From fde8f7383f4d4e63f4ff47e37b1cde4e0ac98fc0 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 28 Jun 2015 13:08:47 -0500 Subject: [PATCH] Map Opened/Closed Events + use in maptools --- addons/common/XEH_postInit.sqf | 18 ++++++++++ addons/maptools/XEH_postInitClient.sqf | 16 +++++++-- addons/maptools/XEH_preInit.sqf | 1 - .../functions/fnc_mapStateUpdater.sqf | 33 ------------------- .../functions/fnc_updateMapToolMarkers.sqf | 10 ++++++ 5 files changed, 42 insertions(+), 36 deletions(-) delete mode 100644 addons/maptools/functions/fnc_mapStateUpdater.sqf diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 3796a4fdc8..159ef1883a 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -353,5 +353,23 @@ GVAR(deviceKeyCurrentIndex) = -1; {false}, [0xC7, [true, false, false]], false] call cba_fnc_addKeybind; //SHIFT + Home Key +//Map opened/closed Events: +GVAR(mapOpened) = false; +[] spawn { + waitUntil {(!isNull findDisplay 12)}; + ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", { + if (!GVAR(mapOpened)) then { + GVAR(mapOpened) = true; + ["mapOpened", []] call FUNC(localEvent); + [{ + if (!visibleMap) then { + GVAR(mapOpened) = false; + ["mapClosed", []] call FUNC(localEvent); + [_this select 1] call CBA_fnc_removePerFrameHandler; + }; + }, 0, []] call CBA_fnc_addPerFrameHandler; + }; + }]; +}; GVAR(commonPostInited) = true; diff --git a/addons/maptools/XEH_postInitClient.sqf b/addons/maptools/XEH_postInitClient.sqf index 8129a75b15..e227463711 100644 --- a/addons/maptools/XEH_postInitClient.sqf +++ b/addons/maptools/XEH_postInitClient.sqf @@ -67,6 +67,18 @@ GVAR(drawing_controls) = [36732, 36733, 36734, 36735, 36736, 36737]; // Update the size and rotation of map tools [] call FUNC(updateMapToolMarkers); - - [FUNC(mapStateUpdater), 0, []] call CBA_fnc_addPerFrameHandler; }; + +["mapOpened", { + // Show and update map tools if required + [] call FUNC(updateMapToolMarkers); + // Show GPS if required + [GVAR(mapGpsShow)] call FUNC(openMapGps); +}] call EFUNC(common,addEventHandler); + +["mapClosed", { + // Hide GPS + [false] call FUNC(openMapGps); + // Cancel drawing + call FUNC(cancelDrawing); +}] call EFUNC(common,addEventHandler); diff --git a/addons/maptools/XEH_preInit.sqf b/addons/maptools/XEH_preInit.sqf index 2da38996c3..2bcd68385a 100644 --- a/addons/maptools/XEH_preInit.sqf +++ b/addons/maptools/XEH_preInit.sqf @@ -16,7 +16,6 @@ PREP(handleMouseButton); PREP(handleMouseMove); PREP(handleMouseZChanged); PREP(isInsideMapTool); -PREP(mapStateUpdater); PREP(openMapGps); PREP(openMapGpsUpdate); PREP(removeLineMarker); diff --git a/addons/maptools/functions/fnc_mapStateUpdater.sqf b/addons/maptools/functions/fnc_mapStateUpdater.sqf deleted file mode 100644 index 2b4e634567..0000000000 --- a/addons/maptools/functions/fnc_mapStateUpdater.sqf +++ /dev/null @@ -1,33 +0,0 @@ - -#include "script_component.hpp" - -if (visibleMap) then { - // Show/Hide draw buttons - if ("ACE_MapTools" in items ACE_player) then { - { ((finddisplay 12) displayctrl _x) ctrlShow true; } forEach GVAR(drawing_controls); - } else { - { ((finddisplay 12) displayctrl _x) ctrlShow false; } forEach GVAR(drawing_controls); - if (GVAR(drawing_isDrawing)) then { - call FUNC(cancelDrawing); - }; - }; -}; - -//When Map is Closed: -if (GVAR(mapVisableLastFrame) && (!visibleMap)) then { - GVAR(mapVisableLastFrame) = false; - // Hide GPS - [false] call FUNC(openMapGps); - // Cancel drawing - call FUNC(cancelDrawing); -}; - -//When Map is Opened: -if ((!GVAR(mapVisableLastFrame)) && (visibleMap)) then { - //todo: "mapOpened" Event???? - GVAR(mapVisableLastFrame) = true; - // Show and update map tools if required - [] call FUNC(updateMapToolMarkers); - // Show GPS if required - [GVAR(mapGpsShow)] call FUNC(openMapGps); -}; diff --git a/addons/maptools/functions/fnc_updateMapToolMarkers.sqf b/addons/maptools/functions/fnc_updateMapToolMarkers.sqf index fa6db8872a..959be6752e 100644 --- a/addons/maptools/functions/fnc_updateMapToolMarkers.sqf +++ b/addons/maptools/functions/fnc_updateMapToolMarkers.sqf @@ -20,6 +20,16 @@ PARAMS_1(_theMap); private ["_rotatingTexture", "_textureWidth", "_scale", "_xPos", "_yPos"]; +// Show/Hide draw buttons +if ("ACE_MapTools" in items ACE_player) then { + { ((finddisplay 12) displayctrl _x) ctrlShow true; } forEach GVAR(drawing_controls); +} else { + { ((finddisplay 12) displayctrl _x) ctrlShow false; } forEach GVAR(drawing_controls); + if (GVAR(drawing_isDrawing)) then { + call FUNC(cancelDrawing); + }; +}; + if (!("ACE_MapTools" in items ACE_player)|| {GVAR(mapTool_Shown) == 0}) exitWith {}; _rotatingTexture = "";