ACE3/addons/maptools/functions/fnc_handleMouseButton.sqf

103 lines
3.3 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"
private ["_dir", "_params", "_control", "_button", "_screenPos", "_shiftKey", "_ctrlKey", "_handled", "_pos"];
_dir = _this select 0;
_params = _this select 1;
_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;
2015-01-16 23:13:26 +00:00
// If it's not a left button event, exit
if (_button != 0) exitWith {};
// If releasing
2015-01-15 21:50:48 +00:00
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 {
2015-01-15 09:51:18 +00:00
if !(call FUNC(canDraw)) exitWith {_handled = false;};
// Transform mouse screen position to coordinates
_pos = _control ctrlMapScreenToWorld _screenPos;
_pos set [count _pos, 0];
2015-01-15 21:50:48 +00:00
if (GVAR(drawing_isDrawing)) exitWith {
// Already drawing -> Add tempLineMarker to permanent list
2015-01-15 21:50:48 +00:00
if (GVAR(drawing_syncMarkers)) then {
deleteMarkerLocal (GVAR(drawing_tempLineMarker) select 0);
2015-01-16 23:13:26 +00:00
// [GVAR(drawing_tempLineMarker), "FUNC(addLineMarker)", 2] call EFUNC(common,execRemoteFnc);
2015-01-17 04:07:53 +00:00
["drawing_addLineMarker", GVAR(drawing_tempLineMarker)] call EFUNC(common,globalEvent);
// Log who drew on the briefing screen
2015-01-15 21:50:48 +00:00
(text format ["[ACE] Server: Player %1 drew on the briefing screen", name player]) call EFUNC(common,serverLog);
} else {
2015-01-15 21:50:48 +00:00
GVAR(drawing_tempLineMarker) call FUNC(updateLineMarker);
GVAR(drawing_lineMarkers) pushBack (+GVAR(drawing_tempLineMarker));
};
2015-01-15 21:50:48 +00:00
GVAR(drawing_tempLineMarker) = [];
GVAR(drawing_isDrawing) = false;
_handled = true;
};
if (_altKey) exitWith {
// Start drawing
2015-01-15 21:50:48 +00:00
GVAR(drawing_isDrawing) = true;
// Create tempLineMarker
_gui = format ["%1%2%3%4", random (100), random (100), random (100), random (100)];
2015-01-15 21:50:48 +00:00
GVAR(drawing_tempLineMarker) = [_gui, + _pos, + _pos, GVAR(drawing_drawColor)];
_marker = createMarkerLocal [_gui, [0,0]];
2015-01-15 21:50:48 +00:00
GVAR(drawing_tempLineMarker) call FUNC(updateLineMarker);
_handled = true;
};
2015-01-15 21:50:48 +00:00
GVAR(mapTool_isDragging) = false;
GVAR(mapTool_isRotating) = false;
// If no map tool marker then exit
2015-01-15 21:50:48 +00:00
if (isNil QGVAR(mapTool_markerRotatingFixed)) exitWith {_handled = false;};
// Check if clicking the maptool
2015-01-15 21:50:48 +00:00
if (_pos call FUNC(isInsideMapTool)) exitWith {
// Store data for dragging
2015-01-15 21:50:48 +00:00
GVAR(mapTool_startPos) = + GVAR(mapTool_pos);
GVAR(mapTool_startDragPos) = + _pos;
if (_ctrlKey) then {
// Store data for rotating
2015-01-15 21:50:48 +00:00
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
2015-01-15 21:50:48 +00:00
GVAR(mapTool_isRotating) = true;
} else {
// Start dragging
2015-01-15 21:50:48 +00:00
GVAR(mapTool_isDragging) = true;
};
_handled = true;
};
};
_handled