From 2d14a854a0aa12bf51f96d3d63b6c591f833dfcf Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Sun, 19 Feb 2023 11:45:26 +0100 Subject: [PATCH] update for better looks --- PartyPlanner/PartyPlanner.csproj | 2 +- PartyPlanner/PluginUI.cs | 122 ++++++++++--------------------- 2 files changed, 38 insertions(+), 86 deletions(-) diff --git a/PartyPlanner/PartyPlanner.csproj b/PartyPlanner/PartyPlanner.csproj index 6419113..d4de190 100644 --- a/PartyPlanner/PartyPlanner.csproj +++ b/PartyPlanner/PartyPlanner.csproj @@ -3,7 +3,7 @@ Zhyra - 1.4.4 + 1.5.0 PartyVerse.app, directly on your client! MIT https://github.com/edg-l/PartyPlanner diff --git a/PartyPlanner/PluginUI.cs b/PartyPlanner/PluginUI.cs index dd4b59e..f6d4e76 100644 --- a/PartyPlanner/PluginUI.cs +++ b/PartyPlanner/PluginUI.cs @@ -1,4 +1,5 @@ using Dalamud.Logging; +using Dalamud.Utility; using Humanizer; using ImGuiNET; using System; @@ -21,10 +22,10 @@ class PluginUI : IDisposable private PartyVerseApi partyVerseApi { get; init; } // All the events private readonly List partyVerseEvents = new(50); - private string filterTag; private string windowTitle; private readonly Dictionary> eventsByDc = new(); private readonly Dictionary> tagsByDc = new(); + private DateTime lastUpdate = DateTime.Now; // this extra bool exists for ImGui, since you can't ref a property private bool visible = false; @@ -40,14 +41,12 @@ public bool EventDetailsOpen get { return this.eventDetailsOpen; } set { this.eventDetailsOpen = value; } } - private Models.EventType? eventDetails = null; public PluginUI(Configuration configuration) { this.configuration = configuration; this.partyVerseApi = new PartyVerseApi(); windowTitle = "PartyPlanner"; - filterTag = ""; try { @@ -70,7 +69,6 @@ public void Dispose() public void Draw() { DrawMainWindow(); - DrawEventWindow(); } public async void UpdateEvents() @@ -80,6 +78,7 @@ public async void UpdateEvents() tagsByDc.Clear(); partyVerseEvents.AddRange(await this.partyVerseApi.GetActiveEvents()); partyVerseEvents.AddRange(await this.partyVerseApi.GetEvents()); + lastUpdate = DateTime.Now; foreach (var ev in partyVerseEvents) { var key = ev.LocationData.DataCenter.Id; @@ -90,7 +89,7 @@ public async void UpdateEvents() if (!tagsByDc.ContainsKey(key)) tagsByDc.Add(key, new()); - foreach(var tag in ev.Tags) + foreach (var tag in ev.Tags) { if (!tagsByDc[key].ContainsKey(tag)) tagsByDc[key].Add(tag, false); @@ -108,6 +107,8 @@ public void DrawMainWindow() { if (ImGui.Button("Reload Events")) Task.Run(UpdateEvents); + ImGui.SameLine(); + ImGui.Text(string.Format("Updated {0}", lastUpdate.Humanize())); ImGui.Spacing(); @@ -162,40 +163,26 @@ public void DrawDataCenter(Models.DataCenterType dataCenter) } } - ImGui.Spacing(); - - if (ImGui.BeginTable(string.Format("partyverse_events_{0}", dataCenter.Name), 5, - ImGuiTableFlags.RowBg | ImGuiTableFlags.Borders | ImGuiTableFlags.BordersInner)) + foreach (var ev in events) { - ImGui.TableHeader("Events"); - ImGui.TableSetupColumn("Title (click for more info)", ImGuiTableColumnFlags.WidthFixed); - ImGui.TableSetupColumn("Location", ImGuiTableColumnFlags.WidthFixed); - ImGui.TableSetupColumn("Description", ImGuiTableColumnFlags.WidthStretch); - ImGui.TableSetupColumn("Starts", ImGuiTableColumnFlags.WidthFixed); - ImGui.TableSetupColumn("Ends", ImGuiTableColumnFlags.WidthFixed); - ImGui.TableHeadersRow(); - ImGui.TableNextRow(); - - foreach (var ev in events) + bool filtered = false; + foreach (var (tag, selected) in tags) { - bool filtered = false; - foreach(var (tag, selected) in tags) + if (selected && !ev.Tags.Contains(tag)) { - if(selected && !ev.Tags.Contains(tag)) - { - filtered = true; - break; - } + filtered = true; + break; } + } - if(!filtered) - { - DrawEventRow(ev); - } - + if (!filtered) + { + ImGui.Separator(); + ImGui.PushID(ev.Id); + DrawEventRow(ev); + ImGui.PopID(); } - ImGui.EndTable(); } ImGui.EndTabItem(); } @@ -203,99 +190,64 @@ public void DrawDataCenter(Models.DataCenterType dataCenter) public void DrawEventRow(Models.EventType ev) { - ImGui.TableNextColumn(); - ImGui.Spacing(); var greenColor = new Vector4(0.0742f, 0.530f, 0.150f, 1.0f); - var title = ev.Title; - if (title.Length > 30) - title = title[..30] + "..."; - - if (ImGui.Button(title)) + ImGui.TextColored(new Vector4(0.668f, 0.146f, 0.910f, 1.0f), ev.Title); + if (ImGui.IsItemClicked()) { - this.eventDetails = ev; - EventDetailsOpen = true; + Util.OpenLink("https://www.partake.gg/events/{0}".Format(ev.Id)); } - if (ImGui.IsItemHovered()) { ImGui.BeginTooltip(); - ImGui.TextColored(greenColor, ev.Title); - ImGui.Text("Click to open a detailed view."); + ImGui.Text("Click to open the partake.gg website."); ImGui.EndTooltip(); } - string description = ev.Description; - - if (description.Length > 200) - description = description[..200] + "..."; - - ImGui.TableNextColumn(); - - - var originalLocation = string.Format("[{0}] {1}", ev.LocationData.Server.Name, ev.Location); - var location = originalLocation; - if (location.Length > 100) - location = location[..100] + "..."; - + ImGui.Text("Location:"); + ImGui.SameLine(); + var location = string.Format("[{0}] {1}", ev.LocationData.Server.Name, ev.Location); if (ImGui.Selectable(location)) { - ImGui.SetClipboardText(originalLocation); + ImGui.SetClipboardText(location); } if (ImGui.IsItemHovered()) { ImGui.BeginTooltip(); - ImGui.TextColored(greenColor, originalLocation); + ImGui.TextColored(greenColor, location); ImGui.Text("Click to copy"); ImGui.EndTooltip(); } var startsAt = ev.StartsAt.ToLocalTime(); var endsAt = ev.EndsAt.ToLocalTime(); - - ImGui.TableNextColumn(); - ImGui.TextWrapped(description); - ImGui.TableNextColumn(); - ImGui.Text(ev.StartsAt.Humanize()); + ImGui.Text(string.Format("Starts {0}", ev.StartsAt.Humanize())); if (ImGui.IsItemHovered()) { ImGui.BeginTooltip(); ImGui.SetTooltip(startsAt.ToString()); ImGui.EndTooltip(); } - ImGui.TableNextColumn(); - ImGui.Text(endsAt.Humanize()); + ImGui.SameLine(); + ImGui.Text(string.Format("| Ends {0}", ev.EndsAt.Humanize())); if (ImGui.IsItemHovered()) { ImGui.BeginTooltip(); ImGui.SetTooltip(endsAt.ToString()); ImGui.EndTooltip(); } - ImGui.TableNextRow(); - } + ImGui.TextColored(new Vector4(0.156f, 0.665f, 0.920f, 1.0f), + string.Format("From {0} to {1}", ev.StartsAt.ToLocalTime().ToString(), ev.EndsAt.ToLocalTime().ToString())); - public void DrawEventWindow() - { - if (!EventDetailsOpen || this.eventDetails == null) - { - return; - } + ImGui.TextColored(new Vector4(0.0888f, 0.740f, 0.176f, 1.0f), + string.Format("Tags: {0}", string.Join(", ", ev.Tags))); - ImGui.SetNextWindowSizeConstraints(new Vector2(300, 100), new Vector2(800, 800)); - if (ImGui.Begin(string.Format("{0}", eventDetails.Title), ref this.eventDetailsOpen, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize)) + if (ImGui.CollapsingHeader("More details")) { - ImGui.TextWrapped(eventDetails.Description); - ImGui.Spacing(); - ImGui.TextColored(new Vector4(0.668f, 0.146f, 0.910f, 1.0f), eventDetails.Location); - ImGui.Spacing(); - ImGui.TextColored(new Vector4(0.156f, 0.665f, 0.920f, 1.0f), - string.Format("From {0} to {1}", eventDetails.StartsAt.ToLocalTime().ToString(), eventDetails.EndsAt.ToLocalTime().ToString())); - ImGui.Spacing(); - ImGui.TextColored(new Vector4(0.0888f, 0.740f, 0.176f, 1.0f), - string.Format("Tags: {0}", string.Join(", ", eventDetails.Tags))); + ImGui.TextWrapped(ev.Description); } } }