diff --git a/addons/map/CfgEventHandlers.hpp b/addons/map/CfgEventHandlers.hpp index 0a9f567e49..6764ab5e7d 100644 --- a/addons/map/CfgEventHandlers.hpp +++ b/addons/map/CfgEventHandlers.hpp @@ -17,3 +17,9 @@ class Extended_PostInit_EventHandlers { serverInit = QUOTE(call COMPILE_FILE(XEH_postInitServer)); }; }; + +class Extended_DisplayLoad_EventHandlers { + class RscDiary { + GVAR(initMainMap) = QUOTE((_this select 0) call (uiNamespace getVariable 'FUNC(initMainMap)')); + }; +}; diff --git a/addons/map/XEH_PREP.hpp b/addons/map/XEH_PREP.hpp index 6737249165..b6d1fbcf4a 100644 --- a/addons/map/XEH_PREP.hpp +++ b/addons/map/XEH_PREP.hpp @@ -11,3 +11,4 @@ PREP(onDrawMap); PREP(simulateMapLight); PREP(switchFlashlight); PREP(updateMapEffects); +PREP(initMainMap); diff --git a/addons/map/XEH_postInitClient.sqf b/addons/map/XEH_postInitClient.sqf index 6f2f60fc0c..ff93951bbe 100644 --- a/addons/map/XEH_postInitClient.sqf +++ b/addons/map/XEH_postInitClient.sqf @@ -8,52 +8,6 @@ LOG(MSG_INIT); // Calculate the maximum zoom allowed for this map call FUNC(determineZoom); -[{ - if (isNull findDisplay 12) exitWith {}; - - GVAR(lastStillPosition) = ((findDisplay 12) displayCtrl 51) ctrlMapScreenToWorld [0.5, 0.5]; - GVAR(lastStillTime) = CBA_missionTime; - GVAR(isShaking) = false; - - //map sizes are multiples of 1280 - GVAR(worldSize) = worldSize / 1280; - GVAR(mousePos) = [0.5,0.5]; - - //Allow panning the lastStillPosition while mapShake is active - GVAR(rightMouseButtonLastPos) = []; - ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", {_this call FUNC(updateMapEffects)}]; - ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["MouseMoving", { - if (GVAR(isShaking) && {(count GVAR(rightMouseButtonLastPos)) == 2}) then { - private _lastPos = (_this select 0) ctrlMapScreenToWorld GVAR(rightMouseButtonLastPos); - private _newPos = (_this select 0) ctrlMapScreenToWorld (_this select [1,2]); - GVAR(lastStillPosition) set [0, (GVAR(lastStillPosition) select 0) + (_lastPos select 0) - (_newPos select 0)]; - GVAR(lastStillPosition) set [1, (GVAR(lastStillPosition) select 1) + (_lastPos select 1) - (_newPos select 1)]; - GVAR(rightMouseButtonLastPos) = _this select [1,2]; - TRACE_3("Mouse Move",_lastPos,_newPos,GVAR(rightMouseButtonLastPos)); - }; - }]; - ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["MouseButtonDown", { - if ((_this select 1) == 1) then { - GVAR(rightMouseButtonLastPos) = _this select [2,2]; - }; - }]; - ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["MouseButtonUp", { - if ((_this select 1) == 1) then { - GVAR(rightMouseButtonLastPos) = []; - }; - }]; - - //get mouse position on map - ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["MouseMoving", { - GVAR(mousePos) = (_this select 0) ctrlMapScreenToWorld [_this select 1, _this select 2]; - }]; - ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["MouseHolding", { - GVAR(mousePos) = (_this select 0) ctrlMapScreenToWorld [_this select 1, _this select 2]; - }]; - - [_this select 1] call CBA_fnc_removePerFrameHandler; -}, 0] call CBA_fnc_addPerFrameHandler; - ["ace_settingsInitialized", { if (isMultiplayer && {GVAR(DefaultChannel) != -1}) then { //Set the chat channel once the map has finished loading diff --git a/addons/map/functions/fnc_initMainMap.sqf b/addons/map/functions/fnc_initMainMap.sqf new file mode 100644 index 0000000000..bebfcbd999 --- /dev/null +++ b/addons/map/functions/fnc_initMainMap.sqf @@ -0,0 +1,56 @@ +#include "script_component.hpp" +#include "\a3\ui_f\hpp\defineResincl.inc" + +params ["_display"]; +if (ctrlIDD _display != IDD_MAIN_MAP) exitWith {}; + +private _control = _display displayCtrl IDC_MAP; + +GVAR(lastStillPosition) = _control ctrlMapScreenToWorld [0.5, 0.5]; +GVAR(lastStillTime) = CBA_missionTime; +GVAR(isShaking) = false; + +//map sizes are multiples of 1280 +GVAR(worldSize) = worldSize / 1280; +GVAR(mousePos) = [0.5, 0.5]; + +//Allow panning the lastStillPosition while mapShake is active +GVAR(rightMouseButtonLastPos) = []; + +_control ctrlAddEventHandler ["Draw", {_this call FUNC(updateMapEffects)}]; +_control ctrlAddEventHandler ["MouseMoving", { + params ["_control", "_x", "_y"]; + if (GVAR(isShaking) && {count GVAR(rightMouseButtonLastPos) == 2}) then { + private _lastPos = _control ctrlMapScreenToWorld GVAR(rightMouseButtonLastPos); + private _newPos = _control ctrlMapScreenToWorld [_x, _y]; + GVAR(lastStillPosition) set [0, (GVAR(lastStillPosition) select 0) + (_lastPos select 0) - (_newPos select 0)]; + GVAR(lastStillPosition) set [1, (GVAR(lastStillPosition) select 1) + (_lastPos select 1) - (_newPos select 1)]; + GVAR(rightMouseButtonLastPos) = [_x, _y]; + TRACE_3("Mouse Move",_lastPos,_newPos,GVAR(rightMouseButtonLastPos)); + }; +}]; + +_control ctrlAddEventHandler ["MouseButtonDown", { + params ["", "_button", "_x", "_y"]; + if (_button == 1) then { + GVAR(rightMouseButtonLastPos) = [_x, _y]; + }; +}]; + +_control ctrlAddEventHandler ["MouseButtonUp", { + params ["", "_button"]; + if (_button == 1) then { + GVAR(rightMouseButtonLastPos) = []; + }; +}]; + +//get mouse position on map +_control ctrlAddEventHandler ["MouseMoving", { + params ["_control", "_x", "_y"]; + GVAR(mousePos) = _control ctrlMapScreenToWorld [_x, _y]; +}]; + +_control ctrlAddEventHandler ["MouseHolding", { + params ["_control", "_x", "_y"]; + GVAR(mousePos) = _control ctrlMapScreenToWorld [_x, _y]; +}]; diff --git a/addons/map/script_component.hpp b/addons/map/script_component.hpp index 172a0fe838..12d9c0e5fe 100644 --- a/addons/map/script_component.hpp +++ b/addons/map/script_component.hpp @@ -16,7 +16,6 @@ #include "\z\ace\addons\main\script_macros.hpp" - #define MARKERNAME_MAPTOOL_FIXED "ACE_MapToolFixed" #define MARKERNAME_MAPTOOL_ROTATINGNORMAL "ACE_MapToolRotatingNormal" #define MARKERNAME_MAPTOOL_ROTATINGSMALL "ACE_MapToolRotatingSmall"