2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2017-05-10 16:29:04 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
|
|
|
* Allows zeus to click to indicate a 3d position.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: The souce object <OBJECT>
|
2023-08-09 03:51:20 +00:00
|
|
|
* 1: Code to run when position is ready (will be passed the following array) <CODE>
|
|
|
|
* - 0: Successful <BOOL>
|
|
|
|
* - 1: Object <OBJECT>
|
2023-10-04 22:10:21 +00:00
|
|
|
* - 2: Mouse Pos ASL <ARRAY>
|
2023-08-09 03:51:20 +00:00
|
|
|
* - 3: State of Shift <BOOL>
|
|
|
|
* - 4: State of Ctrl <BOOL>
|
|
|
|
* - 5: State of Alt <BOOL>
|
2017-07-10 11:41:35 +00:00
|
|
|
* 2: Text <STRING> (default: "")
|
|
|
|
* 3: Icon image file <STRING> (default: "\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa")
|
|
|
|
* 4: Icon color <ARRAY> (default: [1,0,0,1])
|
2018-02-24 17:44:57 +00:00
|
|
|
* 5: Icon Angle <NUMBER> (default: 0)
|
2023-10-04 22:10:21 +00:00
|
|
|
* 6: Draw Code <CODE> (default: {})
|
|
|
|
* - 0: Object <OBJECT>
|
|
|
|
* - 1: Mouse Pos ASL <ARRAY>
|
2017-05-10 16:29:04 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, {systemChat format ["Done %1", _this]}] call ace_zeus_fnc_getModuleDestination
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2023-10-04 22:10:21 +00:00
|
|
|
params ["_object", "_code", ["_text", ""], ["_icon", "\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa"], ["_color", [1,0,0,1]], ["_angle", 0], ["_drawCode", {}]];
|
2017-05-10 16:29:04 +00:00
|
|
|
|
|
|
|
if (missionNamespace getVariable [QGVAR(moduleDestination_running), false]) exitWith {
|
2017-07-10 11:41:35 +00:00
|
|
|
[false, _object, [0,0,0], false, false, false] call _code;
|
2017-05-10 16:29:04 +00:00
|
|
|
ERROR("getModuleDestination already running");
|
|
|
|
};
|
|
|
|
|
|
|
|
GVAR(moduleDestination_running) = true;
|
|
|
|
|
|
|
|
// Add mouse button eh for the zeus display (triggered from 2d or 3d)
|
2017-07-10 11:41:35 +00:00
|
|
|
GVAR(moduleDestination_displayEHMouse) = [findDisplay 312, "mouseButtonDown", {
|
|
|
|
params ["", "_mouseButton", "", "", "_shift", "_ctrl", "_alt"];
|
|
|
|
|
2017-05-10 16:29:04 +00:00
|
|
|
if (_mouseButton != 0) exitWith {}; // Only watch for LMB
|
2017-07-10 11:41:35 +00:00
|
|
|
|
2017-12-10 18:29:38 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING ["_thisArgs"]
|
2017-05-10 16:29:04 +00:00
|
|
|
_thisArgs params ["_object", "_code"];
|
2017-07-10 11:41:35 +00:00
|
|
|
|
|
|
|
// Get mouse position on 2D map or 3D world
|
2017-05-10 16:29:04 +00:00
|
|
|
private _mousePosASL = if (ctrlShown ((findDisplay 312) displayCtrl 50)) then {
|
|
|
|
private _pos2d = (((findDisplay 312) displayCtrl 50) ctrlMapScreenToWorld getMousePosition);
|
|
|
|
_pos2d set [2, getTerrainHeightASL _pos2d];
|
|
|
|
_pos2d
|
|
|
|
} else {
|
|
|
|
AGLToASL (screenToWorld getMousePosition);
|
|
|
|
};
|
2017-12-10 18:29:38 +00:00
|
|
|
TRACE_2("placed",_object,_mousePosASL);
|
2017-07-10 11:41:35 +00:00
|
|
|
|
|
|
|
[true, _object, _mousePosASL, _shift, _ctrl, _alt] call _code;
|
|
|
|
GVAR(moduleDestination_running) = false;
|
|
|
|
}, [_object, _code]] call CBA_fnc_addBISEventHandler;
|
|
|
|
|
|
|
|
// Add key eh for the zeus display (triggered from 2d or 3d)
|
|
|
|
GVAR(moduleDestination_displayEHKeyboard) = [findDisplay 312, "KeyDown", {
|
|
|
|
params ["", "_keyCode", "_shift", "_ctrl", "_alt"];
|
|
|
|
|
|
|
|
if (_keyCode != 1) exitWith {}; // Only watch for ESC
|
|
|
|
|
2017-12-10 18:29:38 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING ["_thisArgs"]
|
2017-07-10 11:41:35 +00:00
|
|
|
_thisArgs params ["_object", "_code"];
|
|
|
|
|
|
|
|
// Get mouse position on 2D map or 3D world
|
|
|
|
private _mousePosASL = if (ctrlShown ((findDisplay 312) displayCtrl 50)) then {
|
|
|
|
private _pos2d = (((findDisplay 312) displayCtrl 50) ctrlMapScreenToWorld getMousePosition);
|
|
|
|
_pos2d set [2, getTerrainHeightASL _pos2d];
|
|
|
|
_pos2d
|
|
|
|
} else {
|
|
|
|
AGLToASL (screenToWorld getMousePosition);
|
|
|
|
};
|
2017-12-10 18:29:38 +00:00
|
|
|
TRACE_2("aborted",_object,_mousePosASL);
|
2017-07-10 11:41:35 +00:00
|
|
|
|
|
|
|
[false, _object, _mousePosASL, _shift, _ctrl, _alt] call _code;
|
2017-05-10 16:29:04 +00:00
|
|
|
GVAR(moduleDestination_running) = false;
|
2017-07-10 11:41:35 +00:00
|
|
|
true
|
2017-05-10 16:29:04 +00:00
|
|
|
}, [_object, _code]] call CBA_fnc_addBISEventHandler;
|
|
|
|
|
2017-07-10 11:41:35 +00:00
|
|
|
// Add draw EH for the zeus map - draws the 2D icon and line
|
2017-05-10 16:29:04 +00:00
|
|
|
GVAR(moduleDestination_mapDrawEH) = [((findDisplay 312) displayCtrl 50), "draw", {
|
|
|
|
params ["_mapCtrl"];
|
2017-12-10 18:29:38 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING ["_thisArgs"]
|
2018-02-24 17:44:57 +00:00
|
|
|
_thisArgs params ["_object", "_text", "_icon", "_color", "_angle"];
|
2017-05-10 16:29:04 +00:00
|
|
|
|
|
|
|
private _pos2d = (((findDisplay 312) displayCtrl 50) ctrlMapScreenToWorld getMousePosition);
|
2018-02-24 17:44:57 +00:00
|
|
|
_mapCtrl drawIcon [_icon, _color, _pos2d, 24, 24, _angle, _text, 1, 0.03, "TahomaB", "right"];
|
2017-05-10 16:29:04 +00:00
|
|
|
_mapCtrl drawLine [getPos _object, _pos2d, _color];
|
2018-02-24 17:44:57 +00:00
|
|
|
}, [_object, _text, _icon, _color, _angle]] call CBA_fnc_addBISEventHandler;
|
2017-05-10 16:29:04 +00:00
|
|
|
|
2017-07-10 11:41:35 +00:00
|
|
|
// Add draw EH for 3D camera view - draws the 3D icon and line
|
2017-05-10 16:29:04 +00:00
|
|
|
[{
|
2023-10-04 22:10:21 +00:00
|
|
|
(_this select 0) params ["_object", "_code", "_text", "_icon", "_color", "_angle", "_drawCode"];
|
2017-05-10 16:29:04 +00:00
|
|
|
if ((isNull _object) || {isNull findDisplay 312} || {!isNull findDisplay 49}) then {
|
|
|
|
TRACE_3("null-exit",isNull _object,isNull findDisplay 312,isNull findDisplay 49);
|
|
|
|
GVAR(moduleDestination_running) = false;
|
2017-07-10 11:41:35 +00:00
|
|
|
[false, _object, [0,0,0], false, false, false] call _code;
|
2017-05-10 16:29:04 +00:00
|
|
|
};
|
|
|
|
if (GVAR(moduleDestination_running)) then {
|
|
|
|
// Draw the 3d icon and line
|
|
|
|
private _mousePosAGL = screenToWorld getMousePosition;
|
2023-10-04 22:10:21 +00:00
|
|
|
[_object, AGLToASL _mousePosAGL] call _drawCode;
|
2018-02-24 17:44:57 +00:00
|
|
|
drawIcon3D [_icon, _color, _mousePosAGL, 1.5, 1.5, _angle, _text];
|
2017-05-10 16:29:04 +00:00
|
|
|
drawLine3D [_mousePosAGL, ASLtoAGL (getPosASL _object), _color];;
|
|
|
|
} else {
|
2017-07-10 11:41:35 +00:00
|
|
|
TRACE_4("cleaning up",_this select 1,GVAR(moduleDestination_displayEHMouse),GVAR(moduleDestination_displayEHKeyboard),GVAR(moduleDestination_mapDrawEH));
|
2017-05-10 16:29:04 +00:00
|
|
|
(_this select 1) call CBA_fnc_removePerFrameHandler;
|
2024-06-11 15:00:50 +00:00
|
|
|
(findDisplay 312) displayRemoveEventHandler ["MouseButtonDown", GVAR(moduleDestination_displayEHMouse)];
|
2017-07-10 11:41:35 +00:00
|
|
|
(findDisplay 312) displayRemoveEventHandler ["KeyDown", GVAR(moduleDestination_displayEHKeyboard)];
|
2024-06-11 15:00:50 +00:00
|
|
|
((findDisplay 312) displayCtrl 50) ctrlRemoveEventHandler ["Draw", GVAR(moduleDestination_mapDrawEH)];
|
2017-07-10 11:41:35 +00:00
|
|
|
GVAR(moduleDestination_displayEHMouse) = nil;
|
|
|
|
GVAR(moduleDestination_displayEHKeyboard) = nil;
|
2017-05-10 16:29:04 +00:00
|
|
|
GVAR(moduleDestination_mapDrawEH) = nil;
|
|
|
|
};
|
2023-10-04 22:10:21 +00:00
|
|
|
}, 0, [_object, _code, _text, _icon, _color, _angle, _drawCode]] call CBA_fnc_addPerFrameHandler;
|