Skip to content

Commit

Permalink
display currently active events too, trim descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Aug 7, 2022
1 parent 03010fc commit 9f34ed5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
6 changes: 6 additions & 0 deletions PartyPlanner/Models/EventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public class EventsResponseType
[JsonProperty("events")]
public List<EventType> Events { get; set; }
}

public class ActiveEventsResponseType
{
[JsonProperty("activeEvents")]
public List<EventType> ActiveEvents { get; set; }
}
}
2 changes: 1 addition & 1 deletion PartyPlanner/PartyPlanner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Authors>Zhyra</Authors>
<Company></Company>
<Version>1.0.1</Version>
<Version>1.1.0</Version>
<Description>PartyVerse.app, directly on your client!</Description>
<Copyright>MIT</Copyright>
<PackageProjectUrl>https://github.com/edg-l/PartyPlanner</PackageProjectUrl>
Expand Down
40 changes: 37 additions & 3 deletions PartyPlanner/PartyVerseApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public PartyVerseApi()

}

public async Task<Models.EventsResponseType> GetEvents()
public async Task<List<Models.EventType>> GetEvents()
{
var heroRequest = new GraphQLRequest
{
Expand Down Expand Up @@ -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<List<Models.EventType>> 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<Models.ActiveEventsResponseType>(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)
Expand Down
73 changes: 42 additions & 31 deletions PartyPlanner/PluginUI.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +15,8 @@ class PluginUI : IDisposable
{
private Configuration configuration;
private PartyVerseApi partyVerseApi { get; init; }
private Models.EventsResponseType? partyVerseEvents;
private List<Models.EventType> partyVerseEvents = new();
private List<Models.EventType> partyVerseActiveEvents = new();

// this extra bool exists for ImGui, since you can't ref a property
private bool visible = false;
Expand All @@ -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());
});
}

Expand Down Expand Up @@ -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());
});
}

Expand All @@ -90,6 +95,7 @@ public void DrawMainWindow()
ImGui.EndTabItem();
}
}

}
ImGui.End();
}
Expand All @@ -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);
Expand All @@ -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);
}
}

Expand All @@ -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)));
}
}
}
Expand Down

0 comments on commit 9f34ed5

Please sign in to comment.