2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2024-02-11 22:23:44 +00:00
|
|
|
#include "..\defines.hpp"
|
2023-08-18 16:33:56 +00:00
|
|
|
/*
|
|
|
|
* Author: johnb43
|
|
|
|
* Adds custom action buttons.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Tabs to add action to <ARRAY>
|
|
|
|
* 1: Action class (unique string for each action) <STRING>
|
|
|
|
* 2: Title <STRING>
|
|
|
|
* 3: Actions <ARRAY of ARRAYS>
|
|
|
|
* 4: Condition <CODE> (default: {true})
|
|
|
|
* 5: Scope editor <NUMBER> (default: 2)
|
2024-02-06 23:34:52 +00:00
|
|
|
* 6: Update when cargo content changes <BOOL> (default: false)
|
2023-08-18 16:33:56 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* 0: Array of IDs <ARRAY of STRINGS>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [[0, 5], "TAG_myActions", "My Actions", [
|
|
|
|
* ["text", "Text", {true}, "Text"],
|
|
|
|
* ["statement", "Statement", {true}, "", {[_this select 0] call tag_fnc_myTextStatement}],
|
|
|
|
* ["button", "Button", {true}, "", {}, {_this call tag_fnc_myAction}]
|
|
|
|
* ]] call ace_arsenal_fnc_addAction
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
|
|
|
params [
|
|
|
|
["_tabs", [], [[]]],
|
|
|
|
["_rootClass", "", [""]],
|
|
|
|
["_title", "", [""]],
|
|
|
|
["_actions", [], [[]]],
|
|
|
|
["_rootCondition", {true}, [{}]],
|
2024-02-06 23:34:52 +00:00
|
|
|
["_scopeEditor", 2, [0]],
|
|
|
|
["_updateOnCargoChange", false, [false]]
|
2023-08-18 16:33:56 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Compile actions from config (in case this is called before preInit)
|
|
|
|
call FUNC(compileActions);
|
|
|
|
|
|
|
|
// Skip if not allowed in editor and in editor
|
|
|
|
if (is3DEN && {_scopeEditor != 2}) exitWith {
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_1("Skipping action because in editor",_rootClass);
|
2023-08-18 16:33:56 +00:00
|
|
|
[]
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class can't contain ~, because it's used for formatting result
|
|
|
|
if ("~" in _rootClass) exitWith {
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_1("Classname can't contain '~'",_rootClass);
|
2023-08-18 16:33:56 +00:00
|
|
|
[]
|
|
|
|
};
|
|
|
|
|
|
|
|
private _return = [];
|
|
|
|
|
|
|
|
private _fnc_addToGroup = {
|
|
|
|
params ["_group", "_tab"];
|
|
|
|
|
|
|
|
private _type = -1;
|
|
|
|
|
|
|
|
{
|
|
|
|
_x params [["_class", "", [""]], ["_label", "", [""]], ["_condition", {true}, [{}]], ["_text", "", [""]], ["_textStatement", {}, [{}]], ["_statement", {}, [{}]]];
|
|
|
|
|
|
|
|
// Class can't contain ~, because it's used for formatting result
|
|
|
|
if (_class == "" || {"~" in _class}) then {
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Don't allow two of the same class
|
|
|
|
if (_group findIf {(_x select 0) == _class} != -1) then {
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_1("An action with this ID already exists",_class);
|
2023-08-18 16:33:56 +00:00
|
|
|
continue;
|
|
|
|
};
|
|
|
|
|
|
|
|
_type = switch (false) do {
|
|
|
|
case (_text == ""): {
|
|
|
|
_statement = format ["{""%1""}", _text];
|
|
|
|
ACTION_TYPE_TEXT
|
|
|
|
};
|
|
|
|
case (_textStatement isEqualTo {}): {
|
|
|
|
_statement = _textStatement;
|
|
|
|
ACTION_TYPE_TEXT
|
|
|
|
};
|
|
|
|
case (_statement isEqualTo {}): {
|
|
|
|
_statement = _statement;
|
|
|
|
ACTION_TYPE_BUTTON
|
|
|
|
};
|
|
|
|
default {
|
|
|
|
-1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_type == -1) then {
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
|
|
|
|
_statement = compile format [QUOTE([GVAR(center)] call %1), _statement];
|
|
|
|
|
|
|
|
_group pushBack [_class, _type, _label, _statement, _condition];
|
|
|
|
_return pushBack ([_rootClass, _class, _tab] joinString "~");
|
|
|
|
} forEach _actions;
|
|
|
|
};
|
|
|
|
|
|
|
|
private _tab = [];
|
|
|
|
private _index = -1;
|
|
|
|
private _group = [];
|
|
|
|
|
|
|
|
{
|
|
|
|
_tab = GVAR(actionList) select _x;
|
|
|
|
_index = _tab findIf {(_x select 0) == _rootClass};
|
|
|
|
|
|
|
|
// Add to existing group
|
|
|
|
if (_index != -1) then {
|
|
|
|
[_tab select _index select 3, _x] call _fnc_addToGroup;
|
|
|
|
} else {
|
|
|
|
// Add to new group
|
|
|
|
_group = [];
|
|
|
|
|
|
|
|
[_group, _x] call _fnc_addToGroup;
|
|
|
|
|
|
|
|
_tab pushBack [_rootClass, _title, _rootCondition, _group];
|
|
|
|
};
|
|
|
|
} forEach _tabs;
|
|
|
|
|
2024-02-06 23:34:52 +00:00
|
|
|
if (_updateOnCargoChange) then {
|
|
|
|
GVAR(updateActionsOnCargoChange) = true;
|
|
|
|
};
|
|
|
|
|
2023-08-18 16:33:56 +00:00
|
|
|
_return
|