Skip to content
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

Arsenal - Add arsenal actions addition and removal via functions #9318

Merged
merged 6 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREP(addAction);
PREP(addDefaultLoadout);
PREP(addListBoxItem);
PREP(addRightPanelButton);
Expand Down Expand Up @@ -62,6 +63,7 @@ PREP(open3DEN);
PREP(openBox);
PREP(portVALoadouts);
PREP(refresh);
PREP(removeAction);
PREP(removeBox);
PREP(removeDefaultLoadout);
PREP(removeSort);
Expand Down
122 changes: 122 additions & 0 deletions addons/arsenal/functions/fnc_addAction.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include "script_component.hpp"
/*
* 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)
*
* 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}, [{}]],
["_scopeEditor", 2, [0]]
];

// 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 {
TRACE_1("Skipping action because in editor", _rootClass);
[]
};

// Class can't contain ~, because it's used for formatting result
if ("~" in _rootClass) exitWith {
TRACE_1("Classname can't contain '~'", _rootClass);
[]
};

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 {
TRACE_1("An action with this ID already exists", _class);
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;

_return
9 changes: 4 additions & 5 deletions addons/arsenal/functions/fnc_addSort.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* 0: Tabs to add sort to <ARRAY>
* - 0: Left Tab Indexes <ARRAY of NUMBERS>
* - 1: Right Tab Indexes <ARRAY of NUMBERS>
* 1: Sort Class (a unique string for each algorithm) <STRING>
* 1: Sort class (a unique string for each algorithm) <STRING>
* 2: Title <STRING>
* 3: Algorithm <CODE>
* 4: Condition <CODE> (default: true)
* 4: Condition <CODE> (default: {true})
*
* Return Value:
* 0: Array of IDs <ARRAY of STRINGS>
Expand All @@ -27,7 +27,7 @@
*
* _fireRate sort true;
* _fireRate param [0, 0]
* }] call ace_arsenal_fnc_addSort;
* }] call ace_arsenal_fnc_addSort
*
* Public: Yes
*/
Expand All @@ -37,8 +37,7 @@ params [
["_class", "", [""]],
["_title", "", [""]],
["_statement", {}, [{}]],
["_condition", {true}, [{}]],
["_overwrite", false, [false]]
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
["_condition", {true}, [{}]]
];

_tabs params [
Expand Down
2 changes: 1 addition & 1 deletion addons/arsenal/functions/fnc_buttonActionsPage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Arguments:
* 0: Arsenal display <DISPLAY>
* 1. Actions control <CONTROL>
* 1: Actions control <CONTROL>
* 2: Previous or next <BOOL> (false = previous, true = next)
*
* Return Value:
Expand Down
14 changes: 10 additions & 4 deletions addons/arsenal/functions/fnc_compileActions.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: Brett Mayson
* Create the internal actions arrays when needed for the first time
* Create the internal actions arrays when needed for the first time.
*
* Arguments:
* None
Expand Down Expand Up @@ -39,10 +39,12 @@ private _configGroupEntries = "true" configClasses (configFile >> QGVAR(actions)

{
private _scopeEditor = getNumber (_x >> "scopeEditor");

if (is3DEN && {_scopeEditor != 2}) then {continue};

private _configActions = "true" configClasses _x;

private _rootClass = configName _x;
private _rootDisplayName = getText (_x >> "displayName");
private _rootCondition = getText (_x >> "condition");
private _rootTabs = getArray (_x >> "tabs");
Expand All @@ -56,6 +58,7 @@ private _configGroupEntries = "true" configClasses (configFile >> QGVAR(actions)
private _group = [];

{
private _class = configName _x;
private _label = getText (_x >> "label");
private _condition = getText (_x >> "condition");
private _statement = getText (_x >> "statement");
Expand All @@ -79,9 +82,11 @@ private _configGroupEntries = "true" configClasses (configFile >> QGVAR(actions)
-1
};
};

if (_type == -1) then {
continue;
};

_statement = compile format [QUOTE([GVAR(center)] call {%1}), _statement];

if (_condition != "") then {
Expand All @@ -90,12 +95,13 @@ private _configGroupEntries = "true" configClasses (configFile >> QGVAR(actions)
_condition = {true};
};

_group pushBack [_type, _label, _statement, _condition];
// No duplicates are possible here
_group pushBack [_class, _type, _label, _statement, _condition];
} forEach _configActions;

{
(_actionList select _x) pushBack [_rootDisplayName, _rootCondition, _group];
(_actionList select _x) pushBack [_rootClass, _rootDisplayName, _rootCondition, _group];
} forEach _rootTabs;
} forEach _configGroupEntries;

missionNamespace setVariable [QGVAR(actionList), _actionList];
GVAR(actionList) = _actionList;
1 change: 0 additions & 1 deletion addons/arsenal/functions/fnc_compileSorts.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private _sortListRightPanel = [
[] // Misc 7
];

//------------------------- Config handling
private _class = "";
private _displayName = "";
private _statement = "";
Expand Down
2 changes: 0 additions & 2 deletions addons/arsenal/functions/fnc_compileStats.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ private _statsListRightPanel = [
[] // Misc 7
];

//------------------------- Config handling
private _finalArray = [];
private _class = "";
private _stats = [];
Expand Down Expand Up @@ -127,6 +126,5 @@ private _priority = 0;
[_statsListLeftPanel] call _fnc_sortLists;
[_statsListRightPanel] call _fnc_sortLists;

//------------------------- Config Handling
GVAR(statsListLeftPanel) = _statsListLeftPanel;
GVAR(statsListRightPanel) = _statsListRightPanel;
20 changes: 14 additions & 6 deletions addons/arsenal/functions/fnc_handleActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private _panel = [
] find GVAR(currentLeftPanel);

private _groups = (GVAR(actionList) select _panel) select {
[GVAR(center)] call (_x select 1)
[GVAR(center)] call (_x select 2)
};

private _show = _groups isNotEqualTo [];
Expand All @@ -57,9 +57,11 @@ private _actionsCurrentPageCtrl = _display displayCtrl IDC_actionsCurrentPage;

private _currentPage = GVAR(currentActionPage);
private _pages = count _groups;

if (_currentPage < 0) then {
_currentPage = _pages - 1;
};

if (_currentPage >= _pages) then {
_currentPage = 0;
GVAR(currentActionPage) = _currentPage;
Expand All @@ -72,25 +74,28 @@ if (_currentPage >= _pages) then {
} forEach [IDC_actionsPreviousPage, IDC_actionsNextPage];

private _group = _groups select _currentPage;
private _items = _group select 2 select {
[GVAR(center)] call (_x select 3)
private _items = _group select 3 select {
[GVAR(center)] call (_x select 4)
};

_actionsCurrentPageCtrl ctrlSetText (_group select 0);
_actionsCurrentPageCtrl ctrlSetText (_group select 1);
_actionsCurrentPageCtrl ctrlSetFade 0;
_actionsCurrentPageCtrl ctrlShow true;
_actionsCurrentPageCtrl ctrlCommit 0;

{
_x params ["_type", "_label", "_statement"];
_x params ["", "_type", "_label", "_statement"];

private _idc = 9001 + _forEachIndex * 2;
private _actionTextCtrl = _display displayCtrl _idc;
private _actionButtonCtrl = _display displayCtrl (_idc + 1);

switch (_type) do {
case ACTION_TYPE_BUTTON: {
_actionButtonCtrl ctrlRemoveAllEventHandlers "ButtonClick";
_actionButtonCtrl ctrlAddEventHandler ["ButtonClick", {
if (is3DEN) exitWith {call FUNC(refresh)};

[{
call FUNC(refresh);
}] call CBA_fnc_execNextFrame;
Expand All @@ -104,10 +109,12 @@ _actionsCurrentPageCtrl ctrlCommit 0;
_actionTextCtrl ctrlCommit 0;
};
case ACTION_TYPE_TEXT: {
private _text = (call _statement);
private _text = call _statement;

if (isNil "_text") then {
_text = "";
};

_actionTextCtrl ctrlSetText _text;
_actionTextCtrl ctrlSetFade 0;
_actionTextCtrl ctrlCommit 0;
Expand All @@ -129,6 +136,7 @@ private _actionCount = count _items;
private _idc = 9001 + _x * 2;
private _actionTextCtrl = _display displayCtrl _idc;
private _actionButtonCtrl = _display displayCtrl (_idc + 1);

_actionTextCtrl ctrlSetFade 1;
_actionTextCtrl ctrlCommit 0;
_actionButtonCtrl ctrlSetFade 1;
Expand Down
41 changes: 41 additions & 0 deletions addons/arsenal/functions/fnc_removeAction.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "script_component.hpp"
/*
* Author: johnb43
* Remove a custom action button from ACE Arsenal.
*
* Arguments:
* 0: Array of IDs <ARRAY of STRINGS>
*
* Return Value:
* None
*
* Example:
* [["TAG_myActions~text~0", "TAG_myActions~statement~0", "TAG_myActions~button~0"]] call ace_arsenal_fnc_removeAction
*
* Public: Yes
*/

params ["_IDList"];

// Compile sorts from config (in case this is called before preInit)
call FUNC(compileActions);

// Remove entries (all names are unique, there are no duplicates)
{
(_x splitString "~") params ["_rootClass", "_class", "_tab"];

_tab = parseNumber _tab;

{
if ((_x select 0) == _rootClass) exitWith {
(_x select 3) deleteAt ((_x select 3) findIf {(_x select 0) == _class});

// If no entries left in group, remove group
if ((_x select 3) isEqualTo []) then {
(GVAR(actionList) select _tab) deleteAt _forEachIndex;
};
};
} forEach (GVAR(actionList) select _tab);
} forEach _IDList;

nil // return
Loading