From 9f34ed5c939851481d5d7e84c566fab9b93b36c4 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Sun, 7 Aug 2022 22:01:48 +0200 Subject: [PATCH] display currently active events too, trim descriptions --- PartyPlanner/Models/EventType.cs | 6 +++ PartyPlanner/PartyPlanner.csproj | 2 +- PartyPlanner/PartyVerseApi.cs | 40 +++++++++++++++-- PartyPlanner/PluginUI.cs | 73 ++++++++++++++++++-------------- 4 files changed, 86 insertions(+), 35 deletions(-) diff --git a/PartyPlanner/Models/EventType.cs b/PartyPlanner/Models/EventType.cs index 92a546e..aad46d7 100644 --- a/PartyPlanner/Models/EventType.cs +++ b/PartyPlanner/Models/EventType.cs @@ -30,4 +30,10 @@ public class EventsResponseType [JsonProperty("events")] public List Events { get; set; } } + + public class ActiveEventsResponseType + { + [JsonProperty("activeEvents")] + public List ActiveEvents { get; set; } + } } diff --git a/PartyPlanner/PartyPlanner.csproj b/PartyPlanner/PartyPlanner.csproj index 00a890b..daee197 100644 --- a/PartyPlanner/PartyPlanner.csproj +++ b/PartyPlanner/PartyPlanner.csproj @@ -3,7 +3,7 @@ Zhyra - 1.0.1 + 1.1.0 PartyVerse.app, directly on your client! MIT https://github.com/edg-l/PartyPlanner diff --git a/PartyPlanner/PartyVerseApi.cs b/PartyPlanner/PartyVerseApi.cs index defcb3a..bdfb464 100644 --- a/PartyPlanner/PartyVerseApi.cs +++ b/PartyPlanner/PartyVerseApi.cs @@ -64,7 +64,7 @@ public PartyVerseApi() } - public async Task GetEvents() + public async Task> GetEvents() { var heroRequest = new GraphQLRequest { @@ -92,10 +92,44 @@ public PartyVerseApi() { // Remove emojis. string result = Regex.Replace(ev.Description, @"\p{Cs}", ""); - ev.Description = result; + ev.Description = result.Trim(); } - return res.Data; + return res.Data.Events; + } + + public async Task> GetActiveEvents() + { + var heroRequest = new GraphQLRequest + { + Query = @" + { + activeEvents(game: ""final-fantasy-xiv"", sortBy: STARTS_AT) { + title, + locationId, + ageRating, + attendeeCount, + startsAt, + endsAt, + launchUrl, + location, + tags, + description(type: PLAIN_TEXT) + } + }" + }; + + var res = await graphQL.SendQueryAsync(heroRequest); + var data = res.Data; + + foreach (var ev in data.ActiveEvents) + { + // Remove emojis. + string result = Regex.Replace(ev.Description, @"\p{Cs}", ""); + ev.Description = result.Trim(); + } + + return res.Data.ActiveEvents; } public Models.ServerType GetServerType(int id) diff --git a/PartyPlanner/PluginUI.cs b/PartyPlanner/PluginUI.cs index 88fbca2..a65c7bf 100644 --- a/PartyPlanner/PluginUI.cs +++ b/PartyPlanner/PluginUI.cs @@ -1,6 +1,7 @@ using Dalamud.Logging; using ImGuiNET; using System; +using System.Collections.Generic; using System.Numerics; using System.Runtime.InteropServices; using System.Threading.Tasks; @@ -14,7 +15,8 @@ class PluginUI : IDisposable { private Configuration configuration; private PartyVerseApi partyVerseApi { get; init; } - private Models.EventsResponseType? partyVerseEvents; + private List partyVerseEvents = new(); + private List partyVerseActiveEvents = new(); // this extra bool exists for ImGui, since you can't ref a property private bool visible = false; @@ -30,17 +32,18 @@ public bool EventDetailsOpen get { return this.eventDetailsOpen; } set { this.eventDetailsOpen = value; } } - private Models.EventType? eventDetailsType = null; + private Models.EventType? eventDetails = null; public PluginUI(Configuration configuration) { this.configuration = configuration; this.partyVerseApi = new PartyVerseApi(); - this.partyVerseEvents = null; Task.Run(async () => { - this.partyVerseEvents = await this.partyVerseApi.GetEvents(); + partyVerseEvents.Clear(); + partyVerseEvents.AddRange(await this.partyVerseApi.GetActiveEvents()); + partyVerseEvents.AddRange(await this.partyVerseApi.GetEvents()); }); } @@ -68,7 +71,9 @@ public void DrawMainWindow() { Task.Run(async () => { - this.partyVerseEvents = await this.partyVerseApi.GetEvents(); + partyVerseEvents.Clear(); + partyVerseEvents.AddRange(await this.partyVerseApi.GetActiveEvents()); + partyVerseEvents.AddRange(await this.partyVerseApi.GetEvents()); }); } @@ -90,6 +95,7 @@ public void DrawMainWindow() ImGui.EndTabItem(); } } + } ImGui.End(); } @@ -99,7 +105,7 @@ public void DrawDataCenter(Models.DataCenterType dataCenter) if (ImGui.BeginTabItem(dataCenter.Name)) { if (ImGui.BeginTable(string.Format("partyverse_events_{0}", dataCenter.Name), 5, - ImGuiTableFlags.RowBg | ImGuiTableFlags.Borders | ImGuiTableFlags.BordersInner | ImGuiTableFlags.SizingFixedFit)) + ImGuiTableFlags.RowBg | ImGuiTableFlags.Borders | ImGuiTableFlags.BordersInner)) { ImGui.TableHeader("Events"); ImGui.TableSetupColumn("Title", ImGuiTableColumnFlags.WidthFixed); @@ -112,29 +118,14 @@ public void DrawDataCenter(Models.DataCenterType dataCenter) if (this.partyVerseEvents != null) { - foreach (var ev in this.partyVerseEvents.Events) + foreach (var ev in this.partyVerseEvents) { var serverType = partyVerseApi.GetServerType(ev.LocationId); if (serverType.DataCenter != dataCenter.Id) continue; - ImGui.TableNextColumn(); - if(ImGui.Selectable(ev.Title)) - { - this.eventDetailsType = ev; - EventDetailsOpen = true; - } - - ImGui.TableNextColumn(); - ImGui.Text(string.Format("[{0}] {1}", serverType.Name, ev.Location)); - ImGui.TableNextColumn(); - ImGui.TextWrapped(ev.Description); - ImGui.TableNextColumn(); - ImGui.Text(ev.StartsAt.ToString()); - ImGui.TableNextColumn(); - ImGui.Text(ev.EndsAt.ToString()); - ImGui.TableNextRow(); + DrawEventRow(ev, serverType); } } @@ -144,25 +135,45 @@ public void DrawDataCenter(Models.DataCenterType dataCenter) } } + public void DrawEventRow(Models.EventType ev, Models.ServerType serverType) + { + ImGui.TableNextColumn(); + if (ImGui.Selectable(ev.Title)) + { + this.eventDetails = ev; + EventDetailsOpen = true; + } + + ImGui.TableNextColumn(); + ImGui.Text(string.Format("[{0}] {1}", serverType.Name, ev.Location)); + ImGui.TableNextColumn(); + ImGui.TextWrapped(ev.Description); + ImGui.TableNextColumn(); + ImGui.Text(ev.StartsAt.ToString()); + ImGui.TableNextColumn(); + ImGui.Text(ev.EndsAt.ToString()); + ImGui.TableNextRow(); + } + public void DrawEventWindow() { - if (!EventDetailsOpen || this.eventDetailsType == null) + if (!EventDetailsOpen || this.eventDetails == null) { return; } ImGui.SetNextWindowSizeConstraints(new Vector2(300, 100), new Vector2(800, 800)); - if (ImGui.Begin(string.Format("{0}", eventDetailsType.Title), ref this.eventDetailsOpen, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize)) + if (ImGui.Begin(string.Format("{0}", eventDetails.Title), ref this.eventDetailsOpen, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize)) { - ImGui.TextWrapped(eventDetailsType.Description); + ImGui.TextWrapped(eventDetails.Description); ImGui.Spacing(); - ImGui.TextColored(new Vector4(0.668f, 0.146f, 0.910f, 1.0f), eventDetailsType.Location); + 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}", eventDetailsType.StartsAt.ToString(), eventDetailsType.EndsAt.ToString())); + ImGui.TextColored(new Vector4(0.156f, 0.665f, 0.920f, 1.0f), + string.Format("From {0} to {1}", eventDetails.StartsAt.ToString(), eventDetails.EndsAt.ToString())); ImGui.Spacing(); - ImGui.TextColored(new Vector4(0.0888f, 0.740f, 0.176f, 1.0f), - string.Format("Tags: {0}", string.Join(", ", eventDetailsType.Tags))); + ImGui.TextColored(new Vector4(0.0888f, 0.740f, 0.176f, 1.0f), + string.Format("Tags: {0}", string.Join(", ", eventDetails.Tags))); } } }