Merge pull request #2197 from acemod/mapOpenCloseEvents

Map open close events / MapTools Cleanup
This commit is contained in:
PabstMirror 2015-08-31 13:23:10 -05:00
commit 38122ffeaf
17 changed files with 78 additions and 94 deletions

View File

@ -1,4 +1,6 @@
// ACE - Common
// #define ENABLE_PERFORMANCE_COUNTERS
#include "script_component.hpp"
//IGNORE_PRIVATE_WARNING("_handleNetEvent", "_handleRequestAllSyncedEvents", "_handleRequestSyncedEvent", "_handleSyncedEvent");
@ -208,6 +210,7 @@ GVAR(OldVisibleMap) = false;
// PFH to raise varios events
[{
BEGIN_COUNTER(stateChecker);
private ["_newCameraView", "_newInventoryDisplayIsOpen", "_newPlayerInventory", "_newPlayerTurret", "_newPlayerVehicle", "_newPlayerVisionMode", "_newPlayerWeapon", "_newZeusDisplayIsOpen", "_newVisibleMap"];
// "playerInventoryChanged" event
_newPlayerInventory = [ACE_player] call FUNC(getAllGear);
@ -281,6 +284,8 @@ GVAR(OldVisibleMap) = false;
["visibleMapChanged", [ACE_player, _newVisibleMap]] call FUNC(localEvent);
};
END_COUNTER(stateChecker);
}, 0, []] call CBA_fnc_addPerFrameHandler;
@ -381,5 +386,4 @@ GVAR(deviceKeyCurrentIndex) = -1;
{false},
[0xC7, [true, false, false]], false] call cba_fnc_addKeybind; //SHIFT + Home Key
GVAR(commonPostInited) = true;

View File

@ -14,7 +14,7 @@ class CfgVehicles {
class ACE_MapToolsHide {
displayName = CSTRING(MapToolsHide);
condition = QUOTE((call FUNC(canUseMapTools) && {GVAR(mapTool_Shown) != 0}));
statement = QUOTE(GVAR(mapTool_Shown) = 0; [] call FUNC(updateMapToolMarkers));
statement = QUOTE(GVAR(mapTool_Shown) = 0;);
exceptions[] = {"isNotDragging", "notOnMap", "isNotInside", "isNotSitting"};
showDisabled = 1;
priority = 5;
@ -22,7 +22,7 @@ class CfgVehicles {
class ACE_MapToolsShowNormal {
displayName = CSTRING(MapToolsShowNormal);
condition = QUOTE((call FUNC(canUseMapTools) && {GVAR(mapTool_Shown) != 1}));
statement = QUOTE(GVAR(mapTool_Shown) = 1; [] call FUNC(updateMapToolMarkers));
statement = QUOTE(GVAR(mapTool_Shown) = 1;);
exceptions[] = {"isNotDragging", "notOnMap", "isNotInside", "isNotSitting"};
showDisabled = 1;
priority = 4;
@ -30,7 +30,7 @@ class CfgVehicles {
class ACE_MapToolsShowSmall {
displayName = CSTRING(MapToolsShowSmall);
condition = QUOTE((call FUNC(canUseMapTools) && {GVAR(mapTool_Shown) != 2}));
statement = QUOTE(GVAR(mapTool_Shown) = 2; [] call FUNC(updateMapToolMarkers));
statement = QUOTE(GVAR(mapTool_Shown) = 2;);
exceptions[] = {"isNotDragging", "notOnMap", "isNotInside", "isNotSitting"};
showDisabled = 1;
priority = 3;
@ -38,7 +38,7 @@ class CfgVehicles {
class ACE_MapToolsAlignNorth {
displayName = CSTRING(MapToolsAlignNorth);
condition = QUOTE((call FUNC(canUseMapTools) && {GVAR(mapTool_Shown) != 0}));
statement = QUOTE(GVAR(mapTool_angle) = 0; [] call FUNC(updateMapToolMarkers));
statement = QUOTE(GVAR(mapTool_angle) = 0;);
exceptions[] = {"isNotDragging", "notOnMap", "isNotInside", "isNotSitting"};
showDisabled = 1;
priority = 2;
@ -46,7 +46,7 @@ class CfgVehicles {
class ACE_MapToolsAlignCompass {
displayName = CSTRING(MapToolsAlignCompass);
condition = QUOTE((call FUNC(canUseMapTools) && {GVAR(mapTool_Shown) != 0} && {('ItemCompass' in assigneditems ACE_player) || {'ItemCompass' in assigneditems ACE_player}}));
statement = QUOTE(GVAR(mapTool_angle) = getDir ACE_player; [] call FUNC(updateMapToolMarkers));
statement = QUOTE(GVAR(mapTool_angle) = getDir ACE_player;);
exceptions[] = {"isNotDragging", "notOnMap", "isNotInside", "isNotSitting"};
showDisabled = 1;
priority = 1;

View File

@ -26,11 +26,11 @@ GVAR(drawing_controls) = [36732, 36733, 36734, 36735, 36736, 36737];
_fnc_installMapEvents = {
private "_d";
_d = _this;
((finddisplay _d) displayctrl 51) ctrlAddEventHandler ["MouseMoving", {_this call FUNC(handleMouseMove);}];
((finddisplay _d) displayctrl 51) ctrlAddEventHandler ["MouseButtonDown", {[1, _this] call FUNC(handleMouseButton);}];
((finddisplay _d) displayctrl 51) ctrlAddEventHandler ["MouseButtonUp", {[0, _this] call FUNC(handleMouseButton)}];
((finddisplay _d) displayctrl 51) ctrlAddEventHandler ["Draw", {_this call FUNC(updateMapToolMarkers);}];
(finddisplay _d) displayAddEventHandler ["KeyDown", {_this call FUNC(handleKeyDown);}];
((findDisplay _d) displayCtrl 51) ctrlAddEventHandler ["MouseMoving", {_this call FUNC(handleMouseMove);}];
((findDisplay _d) displayCtrl 51) ctrlAddEventHandler ["MouseButtonDown", {[1, _this] call FUNC(handleMouseButton);}];
((findDisplay _d) displayCtrl 51) ctrlAddEventHandler ["MouseButtonUp", {[0, _this] call FUNC(handleMouseButton)}];
((findDisplay _d) displayCtrl 51) ctrlAddEventHandler ["Draw", {_this call FUNC(updateMapToolMarkers);}];
(findDisplay _d) displayAddEventHandler ["KeyDown", {_this call FUNC(handleKeyDown);}];
};
// Wait until the briefing map is detected
@ -64,9 +64,17 @@ GVAR(drawing_controls) = [36732, 36733, 36734, 36735, 36736, 36737];
// Install event handlers on the map control and display (control = 51)
GVAR(drawing_syncMarkers) = false;
12 call _fnc_installMapEvents;
// Update the size and rotation of map tools
[] call FUNC(updateMapToolMarkers);
[FUNC(mapStateUpdater), 0, []] call CBA_fnc_addPerFrameHandler;
};
["visibleMapChanged", {
params ["", "_mapOn"];
if (_mapOn) then {
// Show GPS if required
[GVAR(mapGpsShow)] call FUNC(openMapGps);
} else {
// Hide GPS
[false] call FUNC(openMapGps);
// Cancel drawing
call FUNC(cancelDrawing);
};
}] call EFUNC(common,addEventHandler);

View File

@ -16,7 +16,6 @@ PREP(handleMouseButton);
PREP(handleMouseMove);
PREP(handleMouseZChanged);
PREP(isInsideMapTool);
PREP(mapStateUpdater);
PREP(openMapGps);
PREP(openMapGpsUpdate);
PREP(removeLineMarker);

View File

@ -15,7 +15,7 @@
*/
#include "script_component.hpp"
PARAMS_4(_name,_startPos,_endPos,_color);
params ["_name", "_startPos", "_endPos", "_color"];
private ["_marker", "_difPos", "_mag"];

View File

@ -14,7 +14,7 @@
private ["_screenOffset", "_pos"];
_pos = ((finddisplay 12) displayctrl 51) ctrlMapScreenToWorld [0.5, 0.5];
_screenOffset = ((finddisplay 12) displayctrl 51) posWorldToScreen [(_pos select 0) + 100, (_pos select 1)];
_pos = ((findDisplay 12) displayCtrl 51) ctrlMapScreenToWorld [0.5, 0.5];
_screenOffset = ((findDisplay 12) displayCtrl 51) posWorldToScreen [(_pos select 0) + 100, (_pos select 1)];
(_screenOffset select 0) - 0.5

View File

@ -12,7 +12,7 @@
*/
#include "script_component.hpp"
PARAMS_1(_lineMarkers);
params ["_lineMarkers"];
{
private "_marker";

View File

@ -12,6 +12,6 @@
#include "script_component.hpp"
PARAMS_1(_requester);
params ["_requester"];
["drawing_sendbackMarkers", _requester, [GVAR(drawing_lineMarkers)]] call EFUNC(common,targetEvent);

View File

@ -17,6 +17,6 @@
#include "script_component.hpp"
PARAMS_1(_player,_target);
params ["_player", "_target"];
["drawing_requestMarkers", _target, [_player]] call EFUNC(common,targetEvent);

View File

@ -15,11 +15,12 @@
#include "script_component.hpp"
PARAMS_5(_display,_code,_shiftKey,_ctrlKey,_altKey);
params ["", "_code"];
TRACE_1("params",_code);
private ["_handled", "_relPos", "_diffVector", "_magDiffVector", "_lambdaLong", "_lambdaTrasAbs"];
_handled = false;
_handled = false;
#define DIK_ESCAPE 0x01
#define DIK_DELETE 0xD3
@ -30,6 +31,7 @@ if (_code == DIK_ESCAPE) exitWith {
call FUNC(cancelDrawing);
_handled = true;
};
_handled
};
if (_code == DIK_DELETE) exitWith {
@ -65,6 +67,7 @@ if (_code == DIK_DELETE) exitWith {
};
} forEach GVAR(drawing_lineMarkers);
};
_handled
};
_handled

View File

@ -1,6 +1,5 @@
/*
* Author: esteldunedain
*
* Handle mouse buttons.
*
* Argument:
@ -13,46 +12,39 @@
#include "script_component.hpp"
private ["_control", "_button", "_screenPos", "_shiftKey", "_ctrlKey", "_handled", "_pos", "_altKey", "_gui", "_marker"];
params ["_dir", "_params"];
_params params ["_control", "_button", "_screenPosX", "_screenPosY", "_shiftKey", "_ctrlKey", "_altKey"];
TRACE_2("params",_dir,_params);
PARAMS_2(_dir,_params);
_control = _params select 0;
_button = _params select 1;
_screenPos = [_params select 2, _params select 3];
_shiftKey = _params select 4;
_ctrlKey = _params select 5;
_altKey = _params select 6;
_handled = false;
private["_gui", "_handled", "_marker", "_pos"];
_handled = false;
// If it's not a left button event, exit
if (_button != 0) exitWith {};
if (_button != 0) exitWith {_handled};
// If releasing
if (_dir != 1 && (GVAR(mapTool_isDragging) or GVAR(mapTool_isRotating))) exitWith {
GVAR(mapTool_isDragging) = false;
GVAR(mapTool_isRotating) = false;
_handled = true;
_handled
};
// If clicking
if (_dir == 1) exitWith {
if (_dir != 1) then {
if (GVAR(mapTool_isDragging) || GVAR(mapTool_isRotating)) then {
GVAR(mapTool_isDragging) = false;
GVAR(mapTool_isRotating) = false;
_handled = true;
};
} else {
// If clicking
if !(call FUNC(canDraw)) exitWith {_handled = false;};
// Transform mouse screen position to coordinates
_pos = _control ctrlMapScreenToWorld _screenPos;
_pos = _control ctrlMapScreenToWorld [_screenPosX, _screenPosY];
_pos set [count _pos, 0];
if (GVAR(drawing_isDrawing)) exitWith {
// Already drawing -> Add tempLineMarker to permanent list
if (GVAR(drawing_syncMarkers)) then {
deleteMarkerLocal (GVAR(drawing_tempLineMarker) select 0);
// [GVAR(drawing_tempLineMarker), "FUNC(addLineMarker)", 2] call EFUNC(common,execRemoteFnc);
["drawing_addLineMarker", GVAR(drawing_tempLineMarker)] call EFUNC(common,globalEvent);
// Log who drew on the briefing screen
(text format ["[ACE] Server: Player %1 drew on the briefing screen", name player]) call EFUNC(common,serverLog);
(text format ["[ACE] Server: Player %1 drew on the briefing screen", profileName]) call EFUNC(common,serverLog);
} else {
GVAR(drawing_tempLineMarker) call FUNC(updateLineMarker);
GVAR(drawing_lineMarkers) pushBack (+GVAR(drawing_tempLineMarker));
@ -96,6 +88,9 @@ if (_dir == 1) exitWith {
};
_handled = true;
};
_handled
};
diag_log text format ["HJa %1", _handled];
_handled

View File

@ -1,6 +1,5 @@
/*
* Author: esteldunedain
*
* Handle mouse movement over the map tool.
*
* Argument:
@ -13,11 +12,12 @@
#include "script_component.hpp"
params ["_control", "_mousePosX", "_mousePosY"];
TRACE_3("params",_control,_mousePosX,_mousePosY);
private ["_control", "_pos"];
_control = _this select 0;
_pos = [_this select 1, _this select 2];
GVAR(mousePosition) = _control ctrlMapScreenToWorld _pos;
GVAR(mousePosition) = _control ctrlMapScreenToWorld [_mousePosX, _mousePosY];
GVAR(mousePosition) set [2, 0]; //convert 2d pos to 3d
// If cannot draw then exit
@ -32,6 +32,7 @@ if !(call FUNC(canDraw)) exitWith {
// Handle drawing
if (GVAR(drawing_isDrawing)) exitWith {
GVAR(drawing_tempLineMarker) set [2, GVAR(mousePosition)];
TRACE_1("updating line pos",GVAR(mousePosition));
GVAR(drawing_tempLineMarker) call FUNC(updateLineMarker);
false
};
@ -44,8 +45,6 @@ if (GVAR(mapTool_isDragging)) exitWith {
GVAR(mapTool_pos) set [0, (GVAR(mapTool_startPos) select 0) + (GVAR(mousePosition) select 0) - (GVAR(mapTool_startDragPos) select 0)];
GVAR(mapTool_pos) set [1, (GVAR(mapTool_startPos) select 1) + (GVAR(mousePosition) select 1) - (GVAR(mapTool_startDragPos) select 1)];
// Update the size and rotation of the maptool
[] call FUNC(updateMapToolMarkers);
true
};
@ -56,8 +55,6 @@ if (GVAR(mapTool_isRotating)) exitWith {
_angle = (180 + ((GVAR(mousePosition) select 0) - (GVAR(mapTool_startPos) select 0)) atan2 ((GVAR(mousePosition) select 1) - (GVAR(mapTool_startPos) select 1)) mod 360);
GVAR(mapTool_angle) = GVAR(mapTool_startAngle) + _angle - GVAR(mapTool_startDragAngle);
// Update the size and rotation of the maptool
[] call FUNC(updateMapToolMarkers);
true
};

View File

@ -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);
};

View File

@ -12,7 +12,7 @@
*/
#include "script_component.hpp"
PARAMS_1(_shouldOpenGps);
params ["_shouldOpenGps"];
private ["_isOpen"];

View File

@ -11,7 +11,7 @@
#include "script_component.hpp"
PARAMS_1(_name);
params ["_name"];
deleteMarkerLocal _name;
{

View File

@ -13,7 +13,8 @@
*/
#include "script_component.hpp"
PARAMS_4(_name,_startPos,_endPos,_color);
params ["_name", "_startPos", "_endPos", "_color"];
TRACE_4("params",_name,_startPos,_endPos,_color);
private ["_difPos", "_mag"];

View File

@ -16,10 +16,20 @@
#define CENTER_OFFSET_Y_PERC 0.1606
#define CONSTANT_SCALE 0.2
PARAMS_1(_theMap);
params ["_theMap"];
private ["_rotatingTexture", "_textureWidth", "_scale", "_xPos", "_yPos"];
// Show/Hide draw buttons
if ([] call FUNC(canDraw)) 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 = "";