diff --git a/Dalamud/Interface/Windowing/Window.cs b/Dalamud/Interface/Windowing/Window.cs index 3bf987690..39c61566b 100644 --- a/Dalamud/Interface/Windowing/Window.cs +++ b/Dalamud/Interface/Windowing/Window.cs @@ -17,7 +17,6 @@ public abstract class Window private bool internalLastIsOpen = false; private bool internalIsOpen = false; private bool nextFrameBringToFront = false; - private DalamudConfiguration Configuration; /// /// Initializes a new instance of the class. @@ -33,7 +32,6 @@ public abstract class Window this.WindowName = name; this.Flags = flags; this.ForceMainWindow = forceMainWindow; - this.Configuration = Service.Get(); } /// @@ -225,10 +223,12 @@ public abstract class Window /// /// Draw the window via ImGui. /// - internal void DrawInternal() + internal void DrawInternal(DalamudConfiguration? configuration) { this.PreOpenCheck(); + var doSoundEffects = configuration?.EnablePluginUISoundEffects ?? false; + if (!this.IsOpen) { if (this.internalIsOpen != this.internalLastIsOpen) @@ -238,7 +238,7 @@ public abstract class Window this.IsFocused = false; - if (this.Configuration.EnablePluginUISoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnCloseSfxId, 0, 0, 0); + if (doSoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnCloseSfxId, 0, 0, 0); } return; @@ -264,7 +264,7 @@ public abstract class Window this.internalLastIsOpen = this.internalIsOpen; this.OnOpen(); - if (this.Configuration.EnablePluginUISoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnOpenSfxId, 0, 0, 0); + if (doSoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnOpenSfxId, 0, 0, 0); } var wasFocused = this.IsFocused; @@ -294,16 +294,19 @@ public abstract class Window this.IsFocused = ImGui.IsWindowFocused(ImGuiFocusedFlags.RootAndChildWindows); - var escapeDown = Service.Get()[VirtualKey.ESCAPE]; - var isAllowed = Service.Get().IsFocusManagementEnabled; - if (escapeDown && this.IsFocused && isAllowed && !wasEscPressedLastFrame && this.RespectCloseHotkey) + var isAllowed = configuration?.IsFocusManagementEnabled ?? false; + if (isAllowed) { - this.IsOpen = false; - wasEscPressedLastFrame = true; - } - else if (!escapeDown && wasEscPressedLastFrame) - { - wasEscPressedLastFrame = false; + var escapeDown = Service.Get()[VirtualKey.ESCAPE]; + if (escapeDown && this.IsFocused && !wasEscPressedLastFrame && this.RespectCloseHotkey) + { + this.IsOpen = false; + wasEscPressedLastFrame = true; + } + else if (!escapeDown && wasEscPressedLastFrame) + { + wasEscPressedLastFrame = false; + } } ImGui.End(); diff --git a/Dalamud/Interface/Windowing/WindowSystem.cs b/Dalamud/Interface/Windowing/WindowSystem.cs index 516f3c21b..8e12d8f68 100644 --- a/Dalamud/Interface/Windowing/WindowSystem.cs +++ b/Dalamud/Interface/Windowing/WindowSystem.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Dalamud.Configuration.Internal; using Dalamud.Interface.Internal.ManagedAsserts; using ImGuiNET; using Serilog; @@ -111,6 +112,8 @@ public class WindowSystem if (hasNamespace) ImGui.PushID(this.Namespace); + var config = Service.GetNullable(); + // Shallow clone the list of windows so that we can edit it without modifying it while the loop is iterating foreach (var window in this.windows.ToArray()) { @@ -119,7 +122,7 @@ public class WindowSystem #endif var snapshot = ImGuiManagedAsserts.GetSnapshot(); - window.DrawInternal(); + window.DrawInternal(config); var source = ($"{this.Namespace}::" ?? string.Empty) + window.WindowName; ImGuiManagedAsserts.ReportProblems(source, snapshot);