From 61e3f1ec0da5f145a4fd3bae256bc17a9ce2b682 Mon Sep 17 00:00:00 2001 From: wraitii Date: Sun, 15 Sep 2019 12:16:28 +0000 Subject: [PATCH] Fix hotkey events synching with hotkey state. This is a semi-revert of 78bc56f33e and a correct fix for #3194. The core issue is that the GUI handler must come behore the hotkey handler, otherwise typing in boxes can set off hotkeys, and the hotkey handler is repsonsible for updating the hotkey state. Thus the GUI handler never has an up-to-date hotkey state, since that's done later. 78bc56f33e fixed that by calling HotkeyInputHandler manually, but that was still broken in some (unused) cases and was hacky (indeed, it even looked hacky as noted by elexis). The simplest fix is to split the 'hotkey creator' handler from the 'hotkey state change' handler, and run the 'hotkey state change handler' before any other handler. Thus the gui handler remains in front of the 'hotkey creator' handler, but it has a correct hotkey state at any time. Differential Revision: https://code.wildfiregames.com/D1839 This was SVN commit r22909. --- binaries/data/mods/_test.gui/gui/gui.rng | 36 ++++++ binaries/data/mods/_test.gui/gui/gui_page.rng | 14 +++ binaries/data/mods/_test.gui/gui/hotkey.js | 14 +++ binaries/data/mods/_test.gui/gui/hotkey.xml | 4 + .../data/mods/_test.gui/gui/page_hotkey.xml | 4 + source/gui/CGUI.cpp | 9 +- source/gui/GUIManager.cpp | 3 + source/gui/tests/test_GuiManager.h | 110 ++++++++++++++++++ source/lib/file/common/trace.cpp | 6 +- source/ps/CConsole.cpp | 3 + source/ps/GameSetup/GameSetup.cpp | 6 +- source/ps/GameSetup/GameSetup.h | 4 +- source/ps/Hotkey.cpp | 20 ++-- source/ps/Hotkey.h | 4 +- 14 files changed, 216 insertions(+), 21 deletions(-) create mode 100755 binaries/data/mods/_test.gui/gui/gui.rng create mode 100755 binaries/data/mods/_test.gui/gui/gui_page.rng create mode 100755 binaries/data/mods/_test.gui/gui/hotkey.js create mode 100755 binaries/data/mods/_test.gui/gui/hotkey.xml create mode 100755 binaries/data/mods/_test.gui/gui/page_hotkey.xml create mode 100755 source/gui/tests/test_GuiManager.h diff --git a/binaries/data/mods/_test.gui/gui/gui.rng b/binaries/data/mods/_test.gui/gui/gui.rng new file mode 100755 index 0000000000..9424e0fa21 --- /dev/null +++ b/binaries/data/mods/_test.gui/gui/gui.rng @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/binaries/data/mods/_test.gui/gui/gui_page.rng b/binaries/data/mods/_test.gui/gui/gui_page.rng new file mode 100755 index 0000000000..c50e60f9e4 --- /dev/null +++ b/binaries/data/mods/_test.gui/gui/gui_page.rng @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/binaries/data/mods/_test.gui/gui/hotkey.js b/binaries/data/mods/_test.gui/gui/hotkey.js new file mode 100755 index 0000000000..3ebf6e50e1 --- /dev/null +++ b/binaries/data/mods/_test.gui/gui/hotkey.js @@ -0,0 +1,14 @@ +var state_before; +var state_after; + +function handleInputBeforeGui(ev) { + if ((ev.type == "hotkeydown" || ev.type == "hotkeyup") && ev.hotkey == "test") + state_before = Engine.HotkeyIsPressed("test"); + return false; +} + +function handleInputAfterGui(ev) { + if ((ev.type == "hotkeydown" || ev.type == "hotkeyup") && ev.hotkey == "test") + state_after = Engine.HotkeyIsPressed("test"); + return false; +} diff --git a/binaries/data/mods/_test.gui/gui/hotkey.xml b/binaries/data/mods/_test.gui/gui/hotkey.xml new file mode 100755 index 0000000000..04e929c76c --- /dev/null +++ b/binaries/data/mods/_test.gui/gui/hotkey.xml @@ -0,0 +1,4 @@ + + +