feat: add a zone sort mode

Also reorganise the options menu.
This commit is contained in:
Anna 2021-03-21 18:37:46 -04:00
parent a104b9904c
commit 0d33c829af
2 changed files with 70 additions and 21 deletions

View File

@ -14,6 +14,7 @@ namespace Tourist {
public bool OnlyShowCurrentZone { get; set; } public bool OnlyShowCurrentZone { get; set; }
public bool ShowTimeUntilAvailable { get; set; } = true; public bool ShowTimeUntilAvailable { get; set; } = true;
public bool ShowTimeLeft { get; set; } = true; public bool ShowTimeLeft { get; set; } = true;
public SortMode SortMode { get; set; } = SortMode.Number;
internal void Initialise(Plugin plugin) { internal void Initialise(Plugin plugin) {
this.Plugin = plugin; this.Plugin = plugin;
@ -23,4 +24,10 @@ namespace Tourist {
this.Plugin.Interface.SavePluginConfig(this); this.Plugin.Interface.SavePluginConfig(this);
} }
} }
[Serializable]
public enum SortMode {
Number,
Zone,
}
} }

View File

@ -40,6 +40,19 @@ namespace Tourist {
if (ImGui.BeginMenuBar()) { if (ImGui.BeginMenuBar()) {
if (ImGui.BeginMenu("Options")) { 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")) { if (ImGui.BeginMenu("Times")) {
var showTimeUntil = this.Plugin.Config.ShowTimeUntilAvailable; var showTimeUntil = this.Plugin.Config.ShowTimeUntilAvailable;
if (ImGui.MenuItem("Show time until available", null, ref showTimeUntil)) { if (ImGui.MenuItem("Show time until available", null, ref showTimeUntil)) {
@ -56,16 +69,26 @@ namespace Tourist {
ImGui.EndMenu(); ImGui.EndMenu();
} }
var showFinished = this.Plugin.Config.ShowFinished; if (ImGui.BeginMenu("Visibility")) {
if (ImGui.MenuItem("Show finished", null, ref showFinished)) { var showFinished = this.Plugin.Config.ShowFinished;
this.Plugin.Config.ShowFinished = showFinished; if (ImGui.MenuItem("Show finished", null, ref showFinished)) {
this.Plugin.Config.Save(); this.Plugin.Config.ShowFinished = showFinished;
} this.Plugin.Config.Save();
}
var showUnavailable = this.Plugin.Config.ShowUnavailable; var showUnavailable = this.Plugin.Config.ShowUnavailable;
if (ImGui.MenuItem("Show unavailable", null, ref showUnavailable)) { if (ImGui.MenuItem("Show unavailable", null, ref showUnavailable)) {
this.Plugin.Config.ShowUnavailable = showUnavailable; this.Plugin.Config.ShowUnavailable = showUnavailable;
this.Plugin.Config.Save(); 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; 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(); ImGui.EndMenu();
} }
@ -106,13 +123,20 @@ namespace Tourist {
} }
if (ImGui.BeginChild("tourist-adventures", new Vector2(0, 0))) { if (ImGui.BeginChild("tourist-adventures", new Vector2(0, 0))) {
var adventures = this.Plugin.Interface.Data.GetExcelSheet<Adventure>(); const uint first = 2162688;
var row = 0; var adventures = this.Plugin.Interface.Data.GetExcelSheet<Adventure>()
foreach (var adventure in adventures) { .Select(adventure => (idx: adventure.RowId - first, adventure))
var idx = row; .OrderBy(entry => this.Plugin.Config.SortMode switch {
row += 1; 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) { if (this.Plugin.Config.OnlyShowCurrentZone && adventure.Level.Value.Territory.Row != this.Plugin.Interface.ClientState.TerritoryType) {
continue; continue;
} }
@ -129,6 +153,24 @@ namespace Tourist {
continue; 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); var availability = adventure.NextAvailable(this.Plugin.Weather);
DateTimeOffset? countdown = null; DateTimeOffset? countdown = null;
@ -148,7 +190,7 @@ namespace Tourist {
: $" ({(countdown.Value - DateTimeOffset.UtcNow).ToHumanReadable()})"; : $" ({(countdown.Value - DateTimeOffset.UtcNow).ToHumanReadable()})";
var name = this.Plugin.Interface.SeStringManager.Parse(adventure.Name.RawData.ToArray()); 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) { if (has || available) {
ImGui.PopStyleColor(); ImGui.PopStyleColor();