From dec09c696c2a18e4cebca04c085fd56e237ed0a2 Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 9 Aug 2020 00:05:11 -0400 Subject: [PATCH] fix: distinguish between closed and hidden --- Peeping Tom/HookManager.cs | 4 ++-- Peeping Tom/Plugin.cs | 6 +++--- Peeping Tom/PluginUI.cs | 32 ++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Peeping Tom/HookManager.cs b/Peeping Tom/HookManager.cs index b839b96..c19f2be 100644 --- a/Peeping Tom/HookManager.cs +++ b/Peeping Tom/HookManager.cs @@ -39,13 +39,13 @@ namespace PeepingTom { return; } - this.plugin.Ui.Visible = true; + this.plugin.Ui.WantsOpen = true; } private void OnLogout(IntPtr ptr) { this.logoutHook.Original(ptr); - this.plugin.Ui.Visible = false; + this.plugin.Ui.WantsOpen = false; this.plugin.Watcher.ClearPrevious(); } diff --git a/Peeping Tom/Plugin.cs b/Peeping Tom/Plugin.cs index 6f90acc..4df7462 100644 --- a/Peeping Tom/Plugin.cs +++ b/Peeping Tom/Plugin.cs @@ -39,9 +39,9 @@ namespace PeepingTom { private void OnCommand(string command, string args) { if (args == "config" || args == "c") { - this.Ui.SettingsVisible = true; + this.Ui.SettingsOpen = true; } else { - this.Ui.Visible = true; + this.Ui.WantsOpen = true; } } @@ -68,7 +68,7 @@ namespace PeepingTom { } private void ConfigUI(object sender, EventArgs args) { - this.Ui.SettingsVisible = true; + this.Ui.SettingsOpen = true; } } } diff --git a/Peeping Tom/PluginUI.cs b/Peeping Tom/PluginUI.cs index 6e94a3b..e3057e0 100644 --- a/Peeping Tom/PluginUI.cs +++ b/Peeping Tom/PluginUI.cs @@ -16,16 +16,18 @@ namespace PeepingTom { private Optional previousFocus = new Optional(); - private bool visible = false; - public bool Visible { - get { return this.visible; } - set { this.visible = value; } + private bool _wantsOpen = false; + public bool WantsOpen { + get => this._wantsOpen; + set => this._wantsOpen = value; } - private bool settingsVisible = false; - public bool SettingsVisible { - get { return this.settingsVisible; } - set { this.settingsVisible = value; } + public bool Visible { get; private set; } + + private bool _settingsOpen = false; + public bool SettingsOpen { + get => this._settingsOpen; + set => this._settingsOpen = value; } public PluginUI(PeepingTomPlugin plugin) { @@ -33,12 +35,12 @@ namespace PeepingTom { } public void Dispose() { - this.Visible = false; - this.SettingsVisible = false; + this.WantsOpen = false; + this.SettingsOpen = false; } public void Draw() { - if (this.SettingsVisible) { + if (this.SettingsOpen) { ShowSettings(); } @@ -51,7 +53,7 @@ namespace PeepingTom { || this.plugin.Interface.ClientState.Condition[ConditionFlag.OccupiedInCutSceneEvent]; // FIXME: this could just be a boolean expression - bool shouldBeShown = this.Visible; + bool shouldBeShown = this.WantsOpen; if (inCombat && !this.plugin.Config.ShowInCombat) { shouldBeShown = false; } else if (inInstance && !this.plugin.Config.ShowInInstance) { @@ -60,6 +62,8 @@ namespace PeepingTom { shouldBeShown = false; } + this.Visible = shouldBeShown; + if (shouldBeShown) { ShowMainWindow(); } @@ -86,7 +90,7 @@ namespace PeepingTom { private void ShowSettings() { // 700x250 if setting a size ImGui.SetNextWindowSize(new Vector2(700, 250)); - if (ImGui.Begin($"{this.plugin.Name} settings", ref this.settingsVisible)) { + if (ImGui.Begin($"{this.plugin.Name} settings", ref this._settingsOpen)) { if (ImGui.BeginTabBar("##settings-tabs")) { if (ImGui.BeginTabItem("Markers")) { bool markTargeted = this.plugin.Config.MarkTargeted; @@ -352,7 +356,7 @@ namespace PeepingTom { if (!this.plugin.Config.AllowMovement) { flags |= ImGuiWindowFlags.NoMove; } - if (ImGui.Begin(this.plugin.Name, ref this.visible, flags)) { + if (ImGui.Begin(this.plugin.Name, ref this._wantsOpen, flags)) { ImGui.Text("Targeting you"); bool anyHovered = false; if (ImGui.ListBoxHeader("##targeting", targeting.Count, 5)) {