From 0d33c829af15e35b12e1fd3bb5b24ba1c296dd95 Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 21 Mar 2021 18:37:46 -0400 Subject: [PATCH] feat: add a zone sort mode Also reorganise the options menu. --- Tourist/Configuration.cs | 7 ++++ Tourist/PluginUi.cs | 84 ++++++++++++++++++++++++++++++---------- 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/Tourist/Configuration.cs b/Tourist/Configuration.cs index 0244eb2..f658a4c 100644 --- a/Tourist/Configuration.cs +++ b/Tourist/Configuration.cs @@ -14,6 +14,7 @@ namespace Tourist { public bool OnlyShowCurrentZone { get; set; } public bool ShowTimeUntilAvailable { get; set; } = true; public bool ShowTimeLeft { get; set; } = true; + public SortMode SortMode { get; set; } = SortMode.Number; internal void Initialise(Plugin plugin) { this.Plugin = plugin; @@ -23,4 +24,10 @@ namespace Tourist { this.Plugin.Interface.SavePluginConfig(this); } } + + [Serializable] + public enum SortMode { + Number, + Zone, + } } diff --git a/Tourist/PluginUi.cs b/Tourist/PluginUi.cs index 94ef918..0588806 100644 --- a/Tourist/PluginUi.cs +++ b/Tourist/PluginUi.cs @@ -40,6 +40,19 @@ namespace Tourist { if (ImGui.BeginMenuBar()) { if (ImGui.BeginMenu("Options")) { + if (ImGui.BeginMenu("Sort by")) { + foreach (var mode in (SortMode[]) Enum.GetValues(typeof(SortMode))) { + if (!ImGui.MenuItem($"{mode}", null, this.Plugin.Config.SortMode == mode)) { + continue; + } + + this.Plugin.Config.SortMode = mode; + this.Plugin.Config.Save(); + } + + ImGui.EndMenu(); + } + if (ImGui.BeginMenu("Times")) { var showTimeUntil = this.Plugin.Config.ShowTimeUntilAvailable; if (ImGui.MenuItem("Show time until available", null, ref showTimeUntil)) { @@ -56,16 +69,26 @@ namespace Tourist { ImGui.EndMenu(); } - var showFinished = this.Plugin.Config.ShowFinished; - if (ImGui.MenuItem("Show finished", null, ref showFinished)) { - this.Plugin.Config.ShowFinished = showFinished; - this.Plugin.Config.Save(); - } + if (ImGui.BeginMenu("Visibility")) { + var showFinished = this.Plugin.Config.ShowFinished; + if (ImGui.MenuItem("Show finished", null, ref showFinished)) { + this.Plugin.Config.ShowFinished = showFinished; + this.Plugin.Config.Save(); + } - var showUnavailable = this.Plugin.Config.ShowUnavailable; - if (ImGui.MenuItem("Show unavailable", null, ref showUnavailable)) { - this.Plugin.Config.ShowUnavailable = showUnavailable; - this.Plugin.Config.Save(); + var showUnavailable = this.Plugin.Config.ShowUnavailable; + if (ImGui.MenuItem("Show unavailable", null, ref showUnavailable)) { + this.Plugin.Config.ShowUnavailable = showUnavailable; + this.Plugin.Config.Save(); + } + + var onlyCurrent = this.Plugin.Config.OnlyShowCurrentZone; + if (ImGui.MenuItem("Show current zone only", null, ref onlyCurrent)) { + this.Plugin.Config.OnlyShowCurrentZone = onlyCurrent; + this.Plugin.Config.Save(); + } + + ImGui.EndMenu(); } var showArrVistas = this.Plugin.Config.ShowArrVistas; @@ -81,12 +104,6 @@ namespace Tourist { } } - var onlyCurrent = this.Plugin.Config.OnlyShowCurrentZone; - if (ImGui.MenuItem("Only show vistas for current zone", null, ref onlyCurrent)) { - this.Plugin.Config.OnlyShowCurrentZone = onlyCurrent; - this.Plugin.Config.Save(); - } - ImGui.EndMenu(); } @@ -106,13 +123,20 @@ namespace Tourist { } if (ImGui.BeginChild("tourist-adventures", new Vector2(0, 0))) { - var adventures = this.Plugin.Interface.Data.GetExcelSheet(); + const uint first = 2162688; - var row = 0; - foreach (var adventure in adventures) { - var idx = row; - row += 1; + var adventures = this.Plugin.Interface.Data.GetExcelSheet() + .Select(adventure => (idx: adventure.RowId - first, adventure)) + .OrderBy(entry => this.Plugin.Config.SortMode switch { + SortMode.Number => entry.idx, + SortMode.Zone => entry.adventure.Level.Value.Map.Row, + _ => throw new ArgumentOutOfRangeException(), + }); + Map? lastMap = null; + bool lastTree = false; + + foreach (var (idx, adventure) in adventures) { if (this.Plugin.Config.OnlyShowCurrentZone && adventure.Level.Value.Territory.Row != this.Plugin.Interface.ClientState.TerritoryType) { continue; } @@ -129,6 +153,24 @@ namespace Tourist { continue; } + if (this.Plugin.Config.SortMode == SortMode.Zone) { + var map = adventure.Level.Value.Map.Value; + if (lastMap != map) { + if (lastMap != null) { + ImGui.TreePop(); + } + + lastTree = ImGui.CollapsingHeader($"{map.PlaceName.Value.Name}"); + ImGui.TreePush(); + } + + lastMap = map; + + if (!lastTree) { + continue; + } + } + var availability = adventure.NextAvailable(this.Plugin.Weather); DateTimeOffset? countdown = null; @@ -148,7 +190,7 @@ namespace Tourist { : $" ({(countdown.Value - DateTimeOffset.UtcNow).ToHumanReadable()})"; var name = this.Plugin.Interface.SeStringManager.Parse(adventure.Name.RawData.ToArray()); - var header = ImGui.CollapsingHeader($"#{row} - {name.TextValue}{next}###adventure-{adventure.RowId}"); + var header = ImGui.CollapsingHeader($"#{idx + 1} - {name.TextValue}{next}###adventure-{adventure.RowId}"); if (has || available) { ImGui.PopStyleColor();