sorty worty
This commit is contained in:
parent
77dc295535
commit
4b8e857e9a
|
@ -34,6 +34,9 @@ public class Plugin : IDalamudPlugin {
|
|||
[PluginService]
|
||||
internal Framework Framework { get; init; }
|
||||
|
||||
[PluginService]
|
||||
internal GameGui GameGui { get; init; }
|
||||
|
||||
internal Configuration Config { get; }
|
||||
internal Vfx Vfx { get; }
|
||||
internal PluginUi Ui { get; }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
|
@ -9,6 +10,7 @@ namespace OrangeGuidanceTomestone.Ui.MainWindowTabs;
|
|||
internal class MessageList : ITab {
|
||||
public string Name => "Your messages";
|
||||
private Plugin Plugin { get; }
|
||||
private SortMode Sort { get; set; }
|
||||
|
||||
private SemaphoreSlim MessagesMutex { get; } = new(1, 1);
|
||||
private List<MessageWithTerritory> Messages { get; } = new();
|
||||
|
@ -25,30 +27,73 @@ internal class MessageList : ITab {
|
|||
this.Refresh();
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGui.BeginCombo("Sort", $"{this.Sort}")) {
|
||||
foreach (var mode in Enum.GetValues<SortMode>()) {
|
||||
if (ImGui.Selectable($"{mode}", mode == this.Sort)) {
|
||||
this.Sort = mode;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
this.MessagesMutex.Wait();
|
||||
|
||||
ImGui.TextUnformatted($"Messages: {this.Messages.Count:N0} / {10 + this.Plugin.Ui.MainWindow.ExtraMessages:N0}");
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
foreach (var message in this.Messages) {
|
||||
var territory = this.Plugin.DataManager.GetExcelSheet<TerritoryType>()?.GetRow(message.Territory);
|
||||
var territoryName = territory?.PlaceName.Value?.Name?.ToDalamudString().TextValue ?? "???";
|
||||
|
||||
ImGui.TextUnformatted(message.Text);
|
||||
ImGui.TreePush();
|
||||
ImGui.TextUnformatted($"Location: {territoryName}");
|
||||
var appraisals = Math.Max(0, message.PositiveVotes - message.NegativeVotes);
|
||||
ImGui.TextUnformatted($"Appraisals: {appraisals:N0} ({message.PositiveVotes:N0} - {message.NegativeVotes:N0})");
|
||||
if (ImGui.Button($"Delete##{message.Id}")) {
|
||||
this.Delete(message.Id);
|
||||
if (ImGui.BeginChild("##messages-list")) {
|
||||
var messages = this.Messages;
|
||||
if (this.Sort != SortMode.Date) {
|
||||
messages = messages.ToList();
|
||||
messages.Sort((a, b) => {
|
||||
return this.Sort switch {
|
||||
SortMode.Date => 0,
|
||||
SortMode.Appraisals => Math.Max(a.PositiveVotes - a.NegativeVotes, 0)
|
||||
.CompareTo(Math.Max(b.PositiveVotes - b.NegativeVotes, 0)),
|
||||
SortMode.Likes => a.PositiveVotes.CompareTo(b.PositiveVotes),
|
||||
SortMode.Dislikes => a.NegativeVotes.CompareTo(b.NegativeVotes),
|
||||
SortMode.Location => a.Territory.CompareTo(b.Territory),
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
ImGui.TreePop();
|
||||
foreach (var message in messages) {
|
||||
var territory = this.Plugin.DataManager.GetExcelSheet<TerritoryType>()?.GetRow(message.Territory);
|
||||
var territoryName = territory?.PlaceName.Value?.Name?.ToDalamudString().TextValue ?? "???";
|
||||
|
||||
ImGui.Separator();
|
||||
ImGui.TextUnformatted(message.Text);
|
||||
ImGui.TreePush();
|
||||
ImGui.TextUnformatted($"Location: {territoryName}");
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGui.SmallButton("Open map") && territory != null) {
|
||||
this.Plugin.GameGui.OpenMapWithMapLink(new MapLinkPayload(
|
||||
territory.RowId,
|
||||
territory.Map.Row,
|
||||
message.X,
|
||||
message.Y
|
||||
));
|
||||
}
|
||||
|
||||
var appraisals = Math.Max(0, message.PositiveVotes - message.NegativeVotes);
|
||||
ImGui.TextUnformatted($"Appraisals: {appraisals:N0} ({message.PositiveVotes:N0} - {message.NegativeVotes:N0})");
|
||||
if (ImGui.Button($"Delete##{message.Id}")) {
|
||||
this.Delete(message.Id);
|
||||
}
|
||||
|
||||
ImGui.TreePop();
|
||||
|
||||
ImGui.Separator();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndChild();
|
||||
|
||||
this.MessagesMutex.Release();
|
||||
}
|
||||
|
||||
|
@ -84,4 +129,12 @@ internal class MessageList : ITab {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private enum SortMode {
|
||||
Date,
|
||||
Appraisals,
|
||||
Likes,
|
||||
Dislikes,
|
||||
Location,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue