Arsenal - Make Zeuses able to save, delete, and edit Default Loadouts (#9278)

* allow zeus to edit default loadouts

* typo
This commit is contained in:
Grim 2023-07-28 07:55:10 +03:00 committed by GitHub
parent 12905a0702
commit 5e6476aa5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 119 additions and 32 deletions

View File

@ -28,6 +28,7 @@ PREP(buttonLoadoutsRename);
PREP(buttonLoadoutsSave);
PREP(buttonLoadoutsShare);
PREP(buttonStatsPage);
PREP(canEditDefaultLoadout);
PREP(clearSearchbar);
PREP(compileActions);
PREP(compileSorts);
@ -62,9 +63,11 @@ PREP(openBox);
PREP(portVALoadouts);
PREP(refresh);
PREP(removeBox);
PREP(removeDefaultLoadout);
PREP(removeSort);
PREP(removeStat);
PREP(removeVirtualItems);
PREP(renameDefaultLoadout);
PREP(replaceUniqueItemsLoadout);
PREP(scanConfig);
PREP(showItem);

View File

@ -14,6 +14,9 @@ GVAR(lastSortDirectionRight) = DESCENDING;
[QGVAR(initBox), LINKFUNC(initBox)] call CBA_fnc_addEventHandler;
[QGVAR(removeBox), LINKFUNC(removeBox)] call CBA_fnc_addEventHandler;
[QGVAR(addDefaultLoadout), LINKFUNC(addDefaultLoadout)] call CBA_fnc_addEventHandler;
[QGVAR(removeDefaultLoadout), LINKFUNC(removeDefaultLoadout)] call CBA_fnc_addEventHandler;
[QGVAR(renameDefaultLoadout), LINKFUNC(renameDefaultLoadout)] call CBA_fnc_addEventHandler;
[QGVAR(broadcastFace), {
params ["_unit", "_face"];

View File

@ -7,6 +7,7 @@
* Arguments:
* 0: Name of loadout <STRING>
* 1: CBA extended loadout or getUnitLoadout array <ARRAY>
* 2: Add globally <BOOL> (default: false)
*
* Return Value:
* None
@ -17,7 +18,11 @@
* Public: Yes
*/
params [["_name", "", [""]], ["_loadout", [], [[]]]];
params [["_name", "", [""]], ["_loadout", [], [[]]], ["_global", false, [false]]];
if (_global) then {
[QGVAR(addDefaultLoadout), [_name, _loadout]] call CBA_fnc_remoteEvent;
};
private _extendedInfo = createHashMap;
@ -45,3 +50,7 @@ if (_index != -1) then {
// Otherwise just add
GVAR(defaultLoadoutsList) pushBack [_name, [_loadout, _extendedInfo]];
};
if (is3DEN) then {
set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]];
};

View File

@ -25,10 +25,8 @@ private _loadoutName = _contentPanelCtrl lnbText [_contentPanelCursSel, 1];
// If loadout is local or default
if (GVAR(currentLoadoutsTab) != IDC_buttonSharedLoadouts) then {
// Find loadout and delete from list
if (is3DEN && {GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts}) then {
GVAR(defaultLoadoutsList) deleteAt (GVAR(defaultLoadoutsList) findIf {(_x select 0) == _loadoutName});
set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]];
if (GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts) then {
[_loadoutName, !is3DEN] call FUNC(removeDefaultLoadout);
} else {
private _data = profileNamespace getVariable [QGVAR(saved_loadouts), []];

View File

@ -29,7 +29,7 @@ private _editBoxContent = ctrlText (_display displayCtrl IDC_textEditBox);
// If it's the exact same name, don't do anything
if (_editBoxContent isEqualTo _loadoutName) exitWith {};
private _data = [profileNamespace getVariable [QGVAR(saved_loadouts), []], GVAR(defaultLoadoutsList)] select (is3DEN && {GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts});
private _data = [profileNamespace getVariable [QGVAR(saved_loadouts), []], GVAR(defaultLoadoutsList)] select (call FUNC(canEditDefaultLoadout) && {GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts});
// If there is a loadout with a similar name and it's not chosen to be renamed, don't rename and exit
if (_editBoxContent != _loadoutName && {_data findIf {(_x select 0) == _editBoxContent} != -1}) exitWith {
@ -42,8 +42,12 @@ private _loadoutIndex = _data findIf {(_x select 0) == _loadoutName};
// Set new name
(_data select _loadoutIndex) set [0, _editBoxContent];
if (is3DEN && {GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts}) then {
if (GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts) then {
if (is3DEN) then {
set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]];
} else {
[QGVAR(renameDefaultLoadout), [_loadoutName, _editBoxContent]] call CBA_fnc_remoteEvent;
};
};
private _currentLoadoutsTab = str GVAR(currentLoadoutsTab);

View File

@ -49,7 +49,7 @@ private _curSelLoadout = (_contentPanelCtrl getVariable (_loadoutName + str GVAR
private _extendedLoadout = GVAR(center) call CBA_fnc_getLoadout;
_extendedLoadout params ["_loadout"];
private _loadouts = [profileNamespace getVariable [QGVAR(saved_loadouts), []], GVAR(defaultLoadoutsList)] select (is3DEN && {GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts});
private _loadouts = [profileNamespace getVariable [QGVAR(saved_loadouts), []], GVAR(defaultLoadoutsList)] select ((call FUNC(canEditDefaultLoadout)) && {GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts});
private _loadoutIndex = _loadouts findIf {(_x select 0) == _editBoxContent};
// Return what loadout was saved
@ -57,16 +57,14 @@ private _savedLoadout = switch (GVAR(currentLoadoutsTab)) do {
// Local loadouts tab
case IDC_buttonMyLoadouts: {
// If saved to default loadout
if (GVAR(shiftState) && {is3DEN} && {_loadoutName != ""} && {_curSelRow != -1} && {_loadoutIndex != -1}) then {
if (GVAR(shiftState) && FUNC(canEditDefaultLoadout) && {_loadoutName != ""} && {_curSelRow != -1} && {_loadoutIndex != -1}) then {
private _defaultLoadoutsSearch = GVAR(defaultLoadoutsList) findIf {(_x select 0) == _loadoutName};
if (_defaultLoadoutsSearch == -1) then {
_loadoutIndex = GVAR(defaultLoadoutsList) pushBack [_loadoutName, _curSelLoadout];
} else {
GVAR(defaultLoadoutsList) set [_defaultLoadoutsSearch, [_loadoutName, _curSelLoadout]];
};
[_loadoutName, _curSelLoadout, !is3DEN] call FUNC(addDefaultLoadout);
set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]];
if (_defaultLoadoutsSearch == -1) then {
_loadoutIndex = (count GVAR(defaultLoadoutsList)) - 1;
};
_curSelLoadout
} else {
@ -111,19 +109,15 @@ private _savedLoadout = switch (GVAR(currentLoadoutsTab)) do {
};
// Default loadouts tab
case IDC_buttonDefaultLoadouts: {
if (is3DEN) then {
// Replace unique items with their bases and replace weapons with their base weapons
_loadout = [_loadout] call FUNC(replaceUniqueItemsLoadout);
if (call FUNC(canEditDefaultLoadout)) then {
// Add or overwrite loadout in loadout storage
[_editBoxContent, _extendedLoadout, !is3DEN] call FUNC(addDefaultLoadout);
// Get loadout index
if (_loadoutIndex == -1) then {
_loadoutIndex = GVAR(defaultLoadoutsList) pushBack [_editBoxContent, _extendedLoadout];
} else {
GVAR(defaultLoadoutsList) set [_loadoutIndex, [_editBoxContent, _extendedLoadout]];
_loadoutIndex = (count GVAR(defaultLoadoutsList)) - 1;
};
set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]];
// Refresh loadout list; Delete previous loadout row
for "_lbIndex" from 0 to (lnbSize _contentPanelCtrl select 0) - 1 do {
if ((_contentPanelCtrl lnbText [_lbIndex, 1]) == _editBoxContent) exitWith {

View File

@ -0,0 +1,16 @@
#include "script_component.hpp"
#include "..\defines.hpp"
/*
* Author: LinkIsGrim
* Whether the player can save a default loadout in the current mission state
*
* Arguments:
* None
*
* Return Value:
* Can Save <BOOL>
*
* Public: No
*/
is3DEN || EFUNC(common,hasZeusAccess)

View File

@ -48,7 +48,7 @@ switch (ctrlIDC _control) do {
case IDC_buttonMyLoadouts: {
_centerBoxTitleCtrl ctrlSetText LLSTRING(tabMyLoadoutsText);
if (is3DEN) then {
if (call FUNC(canEditDefaultLoadout)) then {
_saveButtonCtrl ctrlSetTooltip format ["%1\n%2", LLSTRING(buttonSaveTooltip), LLSTRING(buttonSaveTooltip_shiftClick)];
};
@ -59,18 +59,18 @@ switch (ctrlIDC _control) do {
case IDC_buttonDefaultLoadouts: {
_centerBoxTitleCtrl ctrlSetText LLSTRING(tabDefaultLoadoutsText);
if (is3DEN) then {
if (call FUNC(canEditDefaultLoadout)) then {
_saveButtonCtrl ctrlSetTooltip LLSTRING(buttonSaveTooltip);
};
_saveButtonCtrl ctrlEnable is3DEN;
_saveButtonCtrl ctrlEnable call FUNC(canEditDefaultLoadout);
_saveButtonCtrl ctrlCommit 0;
};
// Shared loadouts
case IDC_buttonSharedLoadouts: {
_centerBoxTitleCtrl ctrlSetText LLSTRING(tabSharedLoadoutsText);
if (is3DEN) then {
if (call FUNC(canEditDefaultLoadout)) then {
_saveButtonCtrl ctrlSetTooltip LLSTRING(buttonSaveTooltip);
};

View File

@ -74,7 +74,7 @@ switch (GVAR(currentLoadoutsTab)) do {
// Enable delete and renaming button if in 3DEN
{
_x ctrlEnable (is3DEN);
_x ctrlEnable (call FUNC(canEditDefaultLoadout));
_x ctrlCommit 0;
} forEach [_renameButtonCtrl, _deleteButtonCtrl];

View File

@ -0,0 +1,28 @@
#include "script_component.hpp"
/*
* Author: LinkIsGrim
* Removes a loadout from the "Default Loadouts" list.
*
* Arguments:
* 0: Name of loadout <STRING>
* 1: Remove globally <BOOL> (default: false)
*
* Return Value:
* None
*
* Example:
* ["Squad Leader", true] call ace_arsenal_fnc_removeDefaultLoadout
*
* Public: Yes
*/
params [["_name", "", [""]], ["_global", false, [false]]];
if (_global) then {
[QGVAR(removeDefaultLoadout), [_name]] call CBA_fnc_remoteEvent;
};
GVAR(defaultLoadoutsList) deleteAt (GVAR(defaultLoadoutsList) findIf {(_x select 0) == _name});
if (is3DEN) then {
set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]];
};

View File

@ -0,0 +1,25 @@
#include "script_component.hpp"
/*
* Author: LinkIsGrim
* Renames a loadout from the "Default Loadouts" list.
*
* Arguments:
* 0: Current name of loadout <STRING>
* 1: New name of loadout <STRING>
*
* Return Value:
* None
*
* Example:
* ["Squad Leader", "Team Leader"] call ace_arsenal_fnc_renameDefaultLoadout
*
* Public: Yes
*/
params [["_currentName", "", [""]], ["_newName", "", [""]]];
if (_currentName isEqualTo _newName) exitWith {};
private _loadoutIndex = GVAR(defaultLoadoutsList) findIf {(_x select 0) == _currentName};
if (_loadoutIndex isEqualTo -1) exitWith {};
(GVAR(defaultLoadoutsList) select _index) set [0, _newName];

View File

@ -174,7 +174,13 @@ To do so:
This loadout list can be exported to the clipboard by using <kbd>Shift</kbd> + <kbd>LMB</kbd>. on the export button, doing the same on the import button will import the list currently in the clipboard.
### 4.2 Adding default loadouts via script
You can also save one of your personal loadouts as a default loadout by <kbd>Shift</kbd> + <kbd>LMB</kbd> on the save button while highlighting or saving a loadout in My Loadouts.
### 4.2 Adding default loadouts ingame
Players with Zeus access can save default loadouts ingame, doing so will make the saved loadout available to all players. The procedure is the same as with 3DEN, but loadouts cannot be exported or imported in Multiplayer. Default loadouts are not deleted when their creator disconnects, unlike Public Loadouts.
### 4.3 Adding default loadouts via script
`ace_arsenal_fnc_addDefaultLoadout`
@ -182,9 +188,10 @@ This loadout list can be exported to the clipboard by using <kbd>Shift</kbd> + <
---| -------- | ---- | ------------------------
0 | Name of loadout | String | Required
1 | getUnitLoadout array or CBA extended loadout array | Array | Required
2 | Add loadout globally | Boolean | Optional (default: `false`)
Example:
`["Squad Leader", getUnitLoadout sql1] call ace_arsenal_fnc_addDefaultLoadout`
`["Squad Leader", getUnitLoadout sql1, true] call ace_arsenal_fnc_addDefaultLoadout`
If a loadout with the same name exists, it will be overwritten.