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 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,
}
}

View File

@ -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<Adventure>();
const uint first = 2162688;
var row = 0;
foreach (var adventure in adventures) {
var idx = row;
row += 1;
var adventures = this.Plugin.Interface.Data.GetExcelSheet<Adventure>()
.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();