From bdab3425481434c25a4ffb4516de056aae3a437e Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 31 May 2017 11:41:53 -0500 Subject: [PATCH] Handle escape menu with toggle iteractMenu (#5144) * Handle escape menu with toggle iteractMenu * Work on non-cursor menu * Close cursor menu if open when switching * Update fnc_handleEscapeMenu.sqf --- addons/interact_menu/CfgEventHandlers.hpp | 6 +++++ addons/interact_menu/XEH_PREP.hpp | 1 + .../functions/fnc_handleEscapeMenu.sqf | 25 +++++++++++++++++++ .../interact_menu/functions/fnc_keyDown.sqf | 12 ++++++++- 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 addons/interact_menu/functions/fnc_handleEscapeMenu.sqf diff --git a/addons/interact_menu/CfgEventHandlers.hpp b/addons/interact_menu/CfgEventHandlers.hpp index fa53ccf57c..b8bb1264e1 100644 --- a/addons/interact_menu/CfgEventHandlers.hpp +++ b/addons/interact_menu/CfgEventHandlers.hpp @@ -29,4 +29,10 @@ class Extended_DisplayLoad_EventHandlers { class RscDiary { ADDON = QUOTE(call COMPILE_FILE(XEH_displayLoad)); }; + class RscDisplayInterrupt { + ADDON = QUOTE(_this call FUNC(handleEscapeMenu)); + }; + class RscDisplayMPInterrupt { + ADDON = QUOTE(_this call FUNC(handleEscapeMenu)); + }; }; diff --git a/addons/interact_menu/XEH_PREP.hpp b/addons/interact_menu/XEH_PREP.hpp index 0c1a6842fc..55c35d54df 100644 --- a/addons/interact_menu/XEH_PREP.hpp +++ b/addons/interact_menu/XEH_PREP.hpp @@ -9,6 +9,7 @@ PREP(collectActiveActionTree); PREP(createAction); PREP(ctrlSetParsedTextCached); PREP(findActionNode); +PREP(handleEscapeMenu); PREP(isSubPath); PREP(keyDown); PREP(keyUp); diff --git a/addons/interact_menu/functions/fnc_handleEscapeMenu.sqf b/addons/interact_menu/functions/fnc_handleEscapeMenu.sqf new file mode 100644 index 0000000000..41e16e8951 --- /dev/null +++ b/addons/interact_menu/functions/fnc_handleEscapeMenu.sqf @@ -0,0 +1,25 @@ +/* + * Author: PabstMirror + * Handle the escape key being pressed. + * + * Arguments: + * 0: Escape menu display that should be closed + * + * Return Value: + * Nothing + * + * Public: No + */ +#include "script_component.hpp" + +if (GVAR(openedMenuType) < 0) exitWith {}; + +params [["_display", displayNull, [displayNull]]]; +TRACE_2("handleEscapeMenu",_display,isNull _display); + +if (!isNull _display) then { + _display closeDisplay 0; +}; + +GVAR(actionSelected) = false; +[GVAR(openedMenuType), false] call FUNC(keyUp); diff --git a/addons/interact_menu/functions/fnc_keyDown.sqf b/addons/interact_menu/functions/fnc_keyDown.sqf index 58286a65bb..fb1a377f70 100644 --- a/addons/interact_menu/functions/fnc_keyDown.sqf +++ b/addons/interact_menu/functions/fnc_keyDown.sqf @@ -59,7 +59,13 @@ if (GVAR(useCursorMenu)) then { createDialog QGVAR(cursorMenu); }; (finddisplay 91919) displayAddEventHandler ["KeyUp", {[_this,'keyup'] call CBA_events_fnc_keyHandler}]; - (finddisplay 91919) displayAddEventHandler ["KeyDown", {[_this,'keydown'] call CBA_events_fnc_keyHandler}]; + (finddisplay 91919) displayAddEventHandler ["KeyDown", { + // Handle the escape key being pressed with menu open: + if ((_this select [1,4]) isEqualTo [1,false,false,false]) exitWith { // escape key with no modifiers + [displayNull] call FUNC(handleEscapeMenu); + }; + [_this,'keydown'] call CBA_events_fnc_keyHandler; + }]; // The dialog sets: // uiNamespace getVariable QGVAR(dlgCursorMenu); // uiNamespace getVariable QGVAR(cursorMenuOpened); @@ -73,6 +79,10 @@ if (GVAR(useCursorMenu)) then { ((finddisplay 91919) displayctrl 9922) ctrlAddEventHandler ["MouseMoving", DFUNC(handleMouseMovement)]; ((finddisplay 91919) displayctrl 9922) ctrlAddEventHandler ["MouseButtonDown", DFUNC(handleMouseButtonDown)]; setMousePosition [0.5, 0.5]; +} else { + if (uiNamespace getVariable [QGVAR(cursorMenuOpened),false]) then { + (findDisplay 91919) closeDisplay 2; + }; }; GVAR(selfMenuOffset) = (AGLtoASL (positionCameraToWorld [0, 0, 2])) vectorDiff (AGLtoASL (positionCameraToWorld [0, 0, 0]));