ACE3/addons/maptools/functions/fnc_handleMouseButton.sqf

95 lines
3.2 KiB
Plaintext
Raw Normal View History

/*
2015-03-24 04:18:00 +00:00
* Author: esteldunedain
* Handle mouse buttons.
*
* Argument:
* 0: 1 if mouse down down, 0 if mouse button up (Number)
* 1: Parameters of the mouse button event
*
* Return value:
* Boolean, true if event was handled
*/
2015-01-15 21:50:48 +00:00
#include "script_component.hpp"
2015-08-18 02:51:40 +00:00
params ["_dir", "_params"];
_params params ["_control", "_button", "_screenPosX", "_screenPosY", "_shiftKey", "_ctrlKey", "_altKey"];
2015-08-18 21:57:56 +00:00
TRACE_2("params",_dir,_params);
2015-08-18 02:51:40 +00:00
private["_gui", "_handled", "_marker", "_pos"];
2015-08-18 02:51:40 +00:00
_handled = false;
2015-01-16 23:13:26 +00:00
// If it's not a left button event, exit
2015-08-18 02:51:40 +00:00
if (_button != 0) exitWith {_handled};
// If releasing
2015-08-18 21:57:56 +00:00
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
2015-04-07 19:38:35 +00:00
if !(call FUNC(canDraw)) exitWith {_handled = false;};
2015-04-07 19:38:35 +00:00
// Transform mouse screen position to coordinates
2015-08-18 02:51:40 +00:00
_pos = _control ctrlMapScreenToWorld [_screenPosX, _screenPosY];
2015-04-07 19:38:35 +00:00
_pos set [count _pos, 0];
2015-04-07 19:38:35 +00:00
if (GVAR(drawing_isDrawing)) exitWith {
// Already drawing -> Add tempLineMarker to permanent list
if (GVAR(drawing_syncMarkers)) then {
deleteMarkerLocal (GVAR(drawing_tempLineMarker) select 0);
["drawing_addLineMarker", GVAR(drawing_tempLineMarker)] call EFUNC(common,globalEvent);
// Log who drew on the briefing screen
[ACE_INFOFORMAT_1("Player %1 drew on the briefing screen", profileName)] call EFUNC(common,serverLog);
2015-04-07 19:38:35 +00:00
} else {
GVAR(drawing_tempLineMarker) call FUNC(updateLineMarker);
GVAR(drawing_lineMarkers) pushBack (+GVAR(drawing_tempLineMarker));
};
GVAR(drawing_tempLineMarker) = [];
GVAR(drawing_isDrawing) = false;
_handled = true;
};
2015-04-07 19:38:35 +00:00
if (_altKey) exitWith {
// Start drawing
GVAR(drawing_isDrawing) = true;
// Create tempLineMarker
_gui = format ["%1%2%3%4", random (100), random (100), random (100), random (100)];
GVAR(drawing_tempLineMarker) = [_gui, + _pos, + _pos, GVAR(drawing_drawColor)];
_marker = createMarkerLocal [_gui, [0,0]];
GVAR(drawing_tempLineMarker) call FUNC(updateLineMarker);
_handled = true;
};
2015-04-07 19:38:35 +00:00
GVAR(mapTool_isDragging) = false;
GVAR(mapTool_isRotating) = false;
2015-04-07 19:38:35 +00:00
// If no map tool marker then exit
if (GVAR(mapTool_Shown) == 0) exitWith {_handled = false;};
2015-04-07 19:38:35 +00:00
// Check if clicking the maptool
if (_pos call FUNC(isInsideMapTool)) exitWith {
// Store data for dragging
GVAR(mapTool_startPos) = + GVAR(mapTool_pos);
GVAR(mapTool_startDragPos) = + _pos;
if (_ctrlKey) then {
// Store data for rotating
GVAR(mapTool_startAngle) = + GVAR(mapTool_angle);
GVAR(mapTool_startDragAngle) = (180 + ((GVAR(mapTool_startDragPos) select 0) - (GVAR(mapTool_startPos) select 0)) atan2 ((GVAR(mapTool_startDragPos) select 1) - (GVAR(mapTool_startPos) select 1)) mod 360);
// Start rotating
GVAR(mapTool_isRotating) = true;
} else {
// Start dragging
GVAR(mapTool_isDragging) = true;
};
_handled = true;
};
2015-08-18 02:51:40 +00:00
_handled
};
_handled