NominaOcculta/NominaOcculta/PluginUi.cs

154 lines
4.6 KiB
C#
Executable File

using System;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Logging;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
namespace NominaOcculta;
internal class PluginUi : IDisposable {
private Plugin Plugin { get; }
internal bool Visible;
private bool _debug;
private int _queueColumns = 2;
internal PluginUi(Plugin plugin) {
this.Plugin = plugin;
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
this.Plugin.Interface.UiBuilder.OpenConfigUi += this.OpenConfig;
}
public void Dispose() {
this.Plugin.Interface.UiBuilder.OpenConfigUi -= this.OpenConfig;
this.Plugin.Interface.UiBuilder.Draw -= this.Draw;
}
private void OpenConfig() {
this.Visible = true;
}
private void Draw() {
if (!this.Visible) {
return;
}
if (!ImGui.Begin(this.Plugin.Name, ref this.Visible)) {
ImGui.End();
return;
}
var anyChanged = ImGui.Checkbox("Enabled", ref this.Plugin.Config.Enabled);
ImGui.Separator();
anyChanged |= ImGui.Checkbox("Obscure self (full name)", ref this.Plugin.Config.SelfFull);
ImGui.TreePush();
anyChanged |= ImGui.Checkbox("First name", ref this.Plugin.Config.SelfFirst);
anyChanged |= ImGui.Checkbox("Last name", ref this.Plugin.Config.SelfLast);
ImGui.TreePop();
anyChanged |= ImGui.Checkbox("Obscure party members", ref this.Plugin.Config.Party);
anyChanged |= ImGui.Checkbox("Obscure others", ref this.Plugin.Config.Others);
anyChanged |= ImGui.Checkbox("Exclude friends", ref this.Plugin.Config.ExcludeFriends);
if (anyChanged) {
this.Plugin.SaveConfig();
}
ImGui.Separator();
if (ImGui.Button("Reset names")) {
if (this.Plugin.KeyState[VirtualKey.CONTROL] && this.Plugin.KeyState[VirtualKey.SHIFT]) {
this._debug ^= true;
} else {
this.Plugin.NameRepository.Reset();
}
}
if (this._debug) {
if (ImGui.CollapsingHeader("Debug")) {
ImGui.PushID("debug");
try {
this.DrawDebug();
} finally {
ImGui.PopID();
}
}
}
ImGui.End();
}
private void DrawDebug() {
ImGui.TextUnformatted($"Initialised: {this.Plugin.NameRepository.Initialised}");
if (ImGui.Button("Load sheet")) {
this.Plugin.Functions.LoadSheet(Util.SheetName);
}
if (this.Plugin.TargetManager.Target is {} target) {
var npc = this.Plugin.AppearanceRepository.GetNpc(target.ObjectId);
ImGui.TextUnformatted(npc.ToString());
ImGui.TextUnformatted(this.Plugin.DataManager.GetExcelSheet<ENpcResident>()!.GetRow(npc.RowId)!.Singular);
}
ImGui.Separator();
if (ImGui.TreeNode("Name queue")) {
if (ImGui.InputInt("Columns", ref this._queueColumns)) {
this._queueColumns = Math.Max(1, this._queueColumns);
}
foreach (var (info, queue) in this.Plugin.NameRepository.ReadOnlyNames) {
if (!ImGui.CollapsingHeader($"{info}")) {
continue;
}
if (!ImGui.BeginTable($"{info} table", this._queueColumns)) {
continue;
}
foreach (var name in queue) {
ImGui.TableNextColumn();
ImGui.TextUnformatted(name);
}
ImGui.EndTable();
}
ImGui.TreePop();
}
if (ImGui.TreeNode("Replacements")) {
if (ImGui.BeginTable("replacements", 2)) {
foreach (var (name, replacement) in this.Plugin.NameRepository.ReadonlyReplacements) {
ImGui.TableNextColumn();
ImGui.TextUnformatted(name);
ImGui.TableNextColumn();
ImGui.TextUnformatted(replacement);
}
ImGui.EndTable();
}
ImGui.TreePop();
}
if (ImGui.TreeNode("Last seen info")) {
if (ImGui.BeginTable("last seen info", 2)) {
foreach (var (name, info) in this.Plugin.NameRepository.ReadOnlyLastSeenInfo) {
ImGui.TableNextColumn();
ImGui.TextUnformatted(name);
ImGui.TableNextColumn();
ImGui.TextUnformatted($"{info}");
}
ImGui.EndTable();
}
}
ImGui.TreePop();
}
}