From de27e383b290efef80844c4cee20ef9fe2e1ac87 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Wed, 1 Sep 2021 00:00:38 +0200 Subject: [PATCH] feat: escape to close topmost window in WindowSystem --- Dalamud/Interface/Windowing/Window.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Dalamud/Interface/Windowing/Window.cs b/Dalamud/Interface/Windowing/Window.cs index b87f6e14a..f60e32369 100644 --- a/Dalamud/Interface/Windowing/Window.cs +++ b/Dalamud/Interface/Windowing/Window.cs @@ -1,5 +1,6 @@ using System.Numerics; +using Dalamud.Game.ClientState.Keys; using ImGuiNET; namespace Dalamud.Interface.Windowing @@ -9,6 +10,8 @@ namespace Dalamud.Interface.Windowing /// public abstract class Window { + private static bool wasEscPressedLastFrame = false; + private bool internalLastIsOpen = false; private bool internalIsOpen = false; @@ -169,6 +172,17 @@ namespace Dalamud.Interface.Windowing { // Draw the actual window contents this.Draw(); + + var escapeDown = Service.Get()[VirtualKey.ESCAPE]; + if (escapeDown && ImGui.IsWindowFocused() && !wasEscPressedLastFrame) + { + this.IsOpen = false; + wasEscPressedLastFrame = true; + } + else if (!escapeDown && wasEscPressedLastFrame) + { + wasEscPressedLastFrame = false; + } } ImGui.End();