-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arsenal - Add arsenal actions addition and removal via functions (#9318)
* Add and remove arsenal actions via functions * Fixed header * Update addons/arsenal/functions/fnc_addAction.sqf Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Update fnc_addSort.sqf * Update addons/arsenal/functions/fnc_removeAction.sqf Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Update addons/arsenal/functions/fnc_removeAction.sqf Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> --------- Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
- Loading branch information
1 parent
d290ca3
commit a168330
Showing
11 changed files
with
254 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.