diff --git a/addons/vector/XEH_preInit.sqf b/addons/vector/XEH_preInit.sqf index 16235cae2d..a324ac7279 100644 --- a/addons/vector/XEH_preInit.sqf +++ b/addons/vector/XEH_preInit.sqf @@ -25,6 +25,7 @@ PREP(showAzimuth); PREP(showCenter); PREP(showDistance); +GVAR(holdKeyHandler) = -1; GVAR(isKeyDownAzimuth) = false; GVAR(isKeyDownDistance) = false; GVAR(keyDownTimeAzimuth) = -1; diff --git a/addons/vector/functions/fnc_onKeyDown.sqf b/addons/vector/functions/fnc_onKeyDown.sqf index 8f8f2c457a..12be8a8673 100644 --- a/addons/vector/functions/fnc_onKeyDown.sqf +++ b/addons/vector/functions/fnc_onKeyDown.sqf @@ -7,28 +7,44 @@ Handles pressing the special vector keys. */ #include "script_component.hpp" +private "_fnc_setPFH"; +_fnc_setPFH = { + if (GVAR(holdKeyHandler) > -1) then { + [GVAR(holdKeyHandler)] call CBA_fnc_removePerFrameHandler; + GVAR(holdKeyHandler) = -1; + }; + + GVAR(holdKeyHandler) = [FUNC(onKeyHold), 0, _this] call CBA_fnc_addPerFrameHandler; +}; + switch (_this select 0) do { case ("azimuth"): { - if (diag_tickTime > GVAR(keyDownTimeDistance) + 0.5) then { - GVAR(isKeyDownDistance) = false; // emulate key release - ["distance"] call FUNC(clearDisplay); - }; GVAR(isKeyDownAzimuth) = true; GVAR(keyDownTimeAzimuth) = diag_tickTime; - [FUNC(onKeyHold), 0, "azimuth"] call CBA_fnc_addPerFrameHandler; + ["azimuth"] call FUNC(clearDisplay); + if (diag_tickTime > GVAR(keyDownTimeDistance) + 0.5) then { + ["distance"] call FUNC(clearDisplay); + "azimuth" call _fnc_setPFH; + } else { + "azimuth+distance" call _fnc_setPFH; + }; + }; case ("distance"): { - if (diag_tickTime > GVAR(keyDownTimeAzimuth) + 0.5) then { - GVAR(isKeyDownAzimuth) = false; // emulate key release - ["azimuth"] call FUNC(clearDisplay); - }; GVAR(isKeyDownDistance) = true; GVAR(keyDownTimeDistance) = diag_tickTime; - [FUNC(onKeyHold), 0, "distance"] call CBA_fnc_addPerFrameHandler; + ["distance"] call FUNC(clearDisplay); + if (diag_tickTime > GVAR(keyDownTimeAzimuth) + 0.5) then { + ["azimuth"] call FUNC(clearDisplay); + "distance" call _fnc_setPFH; + } else { + "azimuth+distance" call _fnc_setPFH; + }; + }; }; diff --git a/addons/vector/functions/fnc_onKeyHold.sqf b/addons/vector/functions/fnc_onKeyHold.sqf index 79c7a5dfe6..b20e2fee72 100644 --- a/addons/vector/functions/fnc_onKeyHold.sqf +++ b/addons/vector/functions/fnc_onKeyHold.sqf @@ -10,12 +10,16 @@ PFH executed while holding a vector key down. switch (_this select 0) do { case ("azimuth"): { - if (diag_tickTime > GVAR(keyDownTimeAzimuth) + 0.5) then { - call FUNC(showAzimuth); - }; + [false] call FUNC(showCenter); + + call FUNC(showAzimuth); if (!GVAR(isKeyDownAzimuth)) then { [_this select 1] call CBA_fnc_removePerFrameHandler; + + if (GVAR(holdKeyHandler) > -1) then { + GVAR(holdKeyHandler) = -1; + }; }; }; @@ -30,10 +34,39 @@ switch (_this select 0) do { if (!GVAR(isKeyDownDistance)) then { if (_isReady) then { call FUNC(showDistance); + [false] call FUNC(showCenter); }; [_this select 1] call CBA_fnc_removePerFrameHandler; + + if (GVAR(holdKeyHandler) > -1) then { + GVAR(holdKeyHandler) = -1; + }; + }; + + }; + + case ("azimuth+distance"): { + + call FUNC(showAzimuth); + + private "_isReady"; + _isReady = diag_tickTime > GVAR(keyDownTimeDistance) + 0.5; + + [_isReady] call FUNC(showCenter); + + if (!GVAR(isKeyDownAzimuth) && {!GVAR(isKeyDownDistance)}) then { + call FUNC(showDistance); + [false] call FUNC(showCenter); + + [_this select 1] call CBA_fnc_removePerFrameHandler; + + if (GVAR(holdKeyHandler) > -1) then { + GVAR(holdKeyHandler) = -1; + }; }; }; }; + +systemChat str (_this select 0);//