using System; using Dalamud.Game.ClientState.Keys; using ImGuiNET; namespace NominaOcculta { internal class PluginUi : IDisposable { private Plugin Plugin { get; } internal bool Visible; private bool _debug; 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}"); ImGui.Separator(); if (ImGui.TreeNode("Name queue")) { foreach (var (info, queue) in this.Plugin.NameRepository.ReadOnlyNames) { if (ImGui.CollapsingHeader($"{info}")) { if (ImGui.BeginTable($"{info} table", 2)) { 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(); } } }