Skip to content

Editor - Add keybinds for switching AI stance #795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
49 changes: 39 additions & 10 deletions addons/common/functions/fnc_drawHint.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "script_component.hpp"
/*
* Author: Ampersand, mharis001
* Author: Ampersand, mharis001, Timi007
* Draws a hint that contains icon and line elements in 2D (Zeus display map)
* and 3D (in world) for the given duration.
*
Expand Down Expand Up @@ -35,6 +35,8 @@
* 2: ID <STRING|OBJECT> (default: "")
* - an ID is generated when an empty string is given.
* - in the case of an OBJECT, the hash value is used.
* 3: Fade Out Duration (in seconds) <NUMBER> (default: 0)
* - will occur within show duration.
*
* Return Value:
* ID <STRING>
Expand All @@ -50,7 +52,8 @@
params [
["_elements", [], [[]]],
["_duration", 0, [0]],
["_id", "", ["", objNull]]
["_id", "", ["", objNull]],
["_fadeOut", 0, [0]]
];

private _ctrlMap = findDisplay IDD_RSCDISPLAYCURATOR displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP;
Expand Down Expand Up @@ -126,30 +129,44 @@ private _lines = [];
// Add event handlers to draw the hint elements
private _fnc_draw2D = {
params ["_ctrlMap"];
_thisArgs params ["_icons", "_lines"];
_thisArgs params ["_icons", "_lines", "_endTime", "_fadeOutTime"];

// No drawing if in screenshot mode
if (call FUNC(isInScreenshotMode)) exitWith {};

private _time = CBA_missionTime;

{
_x params ["_position", "_icon", "_color", "_scale", "_angle", "_text", "_shadow", "_textSize", "_font", "_align"];

if (_position isEqualTo objNull) then {continue};

_ctrlMap drawIcon [_icon, _color, _position, _scale * MAP_ICON_SIZE, _scale * MAP_ICON_SIZE, _angle, _text, _shadow, _textSize, _font, _align];
// Handle fade out
private _a = linearConversion [_fadeOutTime, _endTime, _time, _color select 3, 0, true];
private _newColor = (_color select [0, 3]) + [_a];

_ctrlMap drawIcon [_icon, _newColor, _position, _scale * MAP_ICON_SIZE, _scale * MAP_ICON_SIZE, _angle, _text, _shadow, _textSize, _font, _align];
} forEach _icons;

{
_x params ["_begPos", "_endPos", "_color"];

if (objNull in [_begPos, _endPos]) then {continue};

_ctrlMap drawLine [_begPos, _endPos, _color];
// Handle fade out
private _a = linearConversion [_fadeOutTime, _endTime, _time, _color select 3, 0, true];
private _newColor = (_color select [0, 3]) + [_a];

_ctrlMap drawLine [_begPos, _endPos, _newColor];
} forEach _lines;
};

private _fnc_draw3D = {
_thisArgs params ["_icons", "_lines", "_endTime", "_id"];
_thisArgs params ["_icons", "_lines", "_endTime", "_fadeOutTime", "_id"];

// Exit if the Zeus display is closed or hint duration is complete
if (isNull curatorCamera || {CBA_missionTime >= _endTime}) exitWith {
private _time = CBA_missionTime;
if (isNull curatorCamera || {_time >= _endTime}) exitWith {
GVAR(drawHintMap) deleteAt _id params ["_id2D", "_id3D"];

private _ctrlMap = findDisplay IDD_RSCDISPLAYCURATOR displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP;
Expand All @@ -169,7 +186,11 @@ private _fnc_draw3D = {
_position = unitAimPositionVisual _position;
};

drawIcon3D [_icon, _color, _position, _scale, _scale, _angle, _text, _shadow, _textSize, _font, _align];
// Handle fade out
private _a = linearConversion [_fadeOutTime, _endTime, _time, _color select 3, 0, true];
private _newColor = (_color select [0, 3]) + [_a];

drawIcon3D [_icon, _newColor, _position, _scale, _scale, _angle, _text, _shadow, _textSize, _font, _align];
} forEach _icons;

{
Expand All @@ -185,11 +206,19 @@ private _fnc_draw3D = {
_endPos = unitAimPositionVisual _endPos;
};

drawLine3D [_begPos, _endPos, _color];
// Handle fade out
private _a = linearConversion [_fadeOutTime, _endTime, _time, _color select 3, 0, true];
private _newColor = (_color select [0, 3]) + [_a];

drawLine3D [_begPos, _endPos, _newColor];
} forEach _lines;
};

private _args = [_icons, _lines, CBA_missionTime + _duration, _id];
private _endTime = CBA_missionTime + _duration;
// Fade out will be performed within show duration; clip _fadeout value between 0 and duration.
private _fadeOutTime = _endTime - ((_fadeOut min _duration) max 0);

private _args = [_icons, _lines, _endTime, _fadeOutTime, _id];
private _id2D = [_ctrlMap, "Draw", _fnc_draw2D, _args] call CBA_fnc_addBISEventHandler;
private _id3D = [missionNamespace, "Draw3D", _fnc_draw3D, _args] call CBA_fnc_addBISEventHandler;
GVAR(drawHintMap) set [_id, [_id2D, _id3D]];
Expand Down
1 change: 1 addition & 0 deletions addons/editor/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ PREP(handleSideButtons);
PREP(handleTreeButtons);
PREP(handleUnload);
PREP(pingCurators);
PREP(switchStance);
1 change: 1 addition & 0 deletions addons/editor/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PREP_RECOMPILE_END;

#include "initSettings.inc.sqf"
#include "initKeybinds.inc.sqf"
#include "initKeybindsAIControl.inc.sqf"

GVAR(clipboard) = [];
GVAR(includeCrew) = true;
Expand Down
46 changes: 46 additions & 0 deletions addons/editor/functions/fnc_switchStance.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "..\script_component.hpp"
/*
* Authors: Timi007
* Sets the stance of the units and shows an icon as hint.
*
* Arguments:
* 0: Unit(s) <OBJECT or ARRAY>
* 1: Stance ("UP", "MIDDLE", "DOWN", "AUTO") <STRING>
*
* Return Value:
* None
*
* Example:
* [cursorObject, "UP"] call zen_editor_fnc_switchStance
*
* Public: No
*/

params [["_units", [], [objNull, []]], ["_stance", "AUTO", [""]]];

if (_units isEqualType objNull) then {
_units = [_units];
};

private _color = [1, 1, 1, 1];
private _iconProperties = switch (_stance) do {
case "UP": {["\a3\3DEN\Data\Attributes\Stance\up_ca.paa", _color, 1.5]};
case "MIDDLE": {["\a3\3DEN\Data\Attributes\Stance\middle_ca.paa", _color, 1.5]};
case "DOWN": {["\a3\3DEN\Data\Attributes\Stance\down_ca.paa", _color, 1.5]};
case "AUTO": {["\a3\3DEN\Data\Attributes\default_ca.paa", _color, 1]};
};

{
if (
!alive _x
|| {isPlayer _x}
|| {!isNull objectParent _x}
|| {unitPos _x == _stance}
) then {continue};

[QEGVAR(common,setUnitPos), [_x, _stance], _x] call CBA_fnc_targetEvent;

[[
["ICON", [_x] + _iconProperties]
], 3, _x, 1] call EFUNC(common,drawHint);
} forEach _units;
131 changes: 0 additions & 131 deletions addons/editor/initKeybinds.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -133,134 +133,3 @@
true // handled
};
}, {}, [DIK_U, [false, false, false]]] call CBA_fnc_addKeybind; // Default: U

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(ejectPassengers), [LSTRING(EjectPassengers), LSTRING(EjectPassengers_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
{
[_x] call EFUNC(common,ejectPassengers);
} forEach SELECTED_OBJECTS;

true // handled, prevents vanilla eject
};
}, {}, [DIK_G, [false, true, false]]] call CBA_fnc_addKeybind; // Default: CTRL + G

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(deployCountermeasures), [LSTRING(DeployCountermeasures), LSTRING(DeployCountermeasures_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
{
[_x] call EFUNC(common,deployCountermeasures);
} forEach SELECTED_OBJECTS;

true // handled
};
}, {}, [DIK_C, [true, false, false]]] call CBA_fnc_addKeybind; // Default: SHIFT + C

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(watchCursor), [LSTRING(WatchCursor), LSTRING(WatchCursor_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
curatorMouseOver params ["_type", "_target"];

if (_type != "OBJECT") then {
_target = ASLToAGL ([] call EFUNC(common,getPosFromScreen));
};

{
if (!isNull group _x && {!isPlayer _x}) then {
// Cancel if target is self
private _isSelf = _x isEqualTo _target;
private _target = [_target, objNull] select _isSelf;
[_x, _target] call EFUNC(common,forceWatch);
if (_isSelf) then {continue};

[[
["ICON", [_target, "\a3\ui_f\data\igui\cfg\simpletasks\types\scout_ca.paa"]],
["LINE", [_x, _target]]
], 3, _x] call EFUNC(common,drawHint);
};
} forEach SELECTED_OBJECTS;

true // handled
};
}, {}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(watchCuratorCamera), [LSTRING(WatchCuratorCamera), LSTRING(WatchCuratorCamera_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
private _position = ASLToAGL getPosASL curatorCamera;

{
if (!isNull group _x && {!isPlayer _x}) then {
[_x, _position] call EFUNC(common,forceWatch);

[[
["ICON", [_position, "\a3\ui_f\data\igui\cfg\simpletasks\types\scout_ca.paa"]],
["LINE", [_x, _position]]
], 3, _x] call EFUNC(common,drawHint);
};
} forEach SELECTED_OBJECTS;

true // handled
};
}, {}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(forceFire), [LSTRING(ForceFire), LSTRING(ForceFire_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
private _units = SELECTED_OBJECTS select {!isPlayer _x && {!isNull group _x}};
[QEGVAR(common,forceFire), [_units, CBA_clientID]] call CBA_fnc_globalEvent;

true // handled
};
}, {
[QEGVAR(common,forceFire), [[], CBA_clientID]] call CBA_fnc_globalEvent;
}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(toggleLaser), [LSTRING(ToggleLaser), LSTRING(ToggleLaser_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
{
if (!isNull group _x && {!isPlayer _x}) then {
[_x] call EFUNC(common,setVehicleLaserState);
};
} forEach SELECTED_OBJECTS;

true // handled
};
}, {}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(moveToCursor), [LSTRING(MoveToCursor), LSTRING(MoveToCursor_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
private _position = ASLToAGL ([] call EFUNC(common,getPosFromScreen));

{
if (!isNull driver _x && {!isPlayer _x}) then {
[QEGVAR(common,doMove), [_x, _position], _x] call CBA_fnc_targetEvent;

[[
["ICON", [_position, "\a3\ui_f\data\igui\cfg\simpletasks\types\walk_ca.paa"]],
["LINE", [_x, _position]]
], 3, _x] call EFUNC(common,drawHint);
};
} forEach SELECTED_OBJECTS;

true // handled
};
}, {}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(toggleAIPATH), [LSTRING(ToggleAIPATH), LSTRING(ToggleAIPATH_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
{
if (!isPlayer _x && {isNull objectParent _x || {_x == driver vehicle _x}}) then {
private _isPathEnabled = _x checkAIFeature "PATH";
private _eventName = [QEGVAR(common,enableAI), QEGVAR(common,disableAI)] select _isPathEnabled;
[_eventName, [_x, "PATH"], _x] call CBA_fnc_globalEvent;

private _icon = [
"\a3\3den\Data\Displays\Display3DEN\PanelRight\modeWaypoints_ca.paa",
"\a3\3den\Data\CfgWaypoints\hold_ca.paa"
] select _isPathEnabled;

[[
["ICON", [_x, _icon]]
], 3, _x] call EFUNC(common,drawHint);
};
} forEach SELECTED_OBJECTS;

true // handled
};
}, {}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound
Loading