diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index a891b401f4..bfb9c07a9a 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -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); diff --git a/addons/arsenal/XEH_postInit.sqf b/addons/arsenal/XEH_postInit.sqf index c047f4800b..1aaa0203b1 100644 --- a/addons/arsenal/XEH_postInit.sqf +++ b/addons/arsenal/XEH_postInit.sqf @@ -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"]; diff --git a/addons/arsenal/functions/fnc_addDefaultLoadout.sqf b/addons/arsenal/functions/fnc_addDefaultLoadout.sqf index b5a8f82d1c..f1593d82f9 100644 --- a/addons/arsenal/functions/fnc_addDefaultLoadout.sqf +++ b/addons/arsenal/functions/fnc_addDefaultLoadout.sqf @@ -7,6 +7,7 @@ * Arguments: * 0: Name of loadout * 1: CBA extended loadout or getUnitLoadout array + * 2: Add globally (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)]]; +}; diff --git a/addons/arsenal/functions/fnc_buttonLoadoutsDelete.sqf b/addons/arsenal/functions/fnc_buttonLoadoutsDelete.sqf index 511b8216be..79c2fd2884 100644 --- a/addons/arsenal/functions/fnc_buttonLoadoutsDelete.sqf +++ b/addons/arsenal/functions/fnc_buttonLoadoutsDelete.sqf @@ -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), []]; diff --git a/addons/arsenal/functions/fnc_buttonLoadoutsRename.sqf b/addons/arsenal/functions/fnc_buttonLoadoutsRename.sqf index 9e7dc96c0e..e1c52f52b7 100644 --- a/addons/arsenal/functions/fnc_buttonLoadoutsRename.sqf +++ b/addons/arsenal/functions/fnc_buttonLoadoutsRename.sqf @@ -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 { - set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]]; +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); diff --git a/addons/arsenal/functions/fnc_buttonLoadoutsSave.sqf b/addons/arsenal/functions/fnc_buttonLoadoutsSave.sqf index 554065c425..785e7486e9 100644 --- a/addons/arsenal/functions/fnc_buttonLoadoutsSave.sqf +++ b/addons/arsenal/functions/fnc_buttonLoadoutsSave.sqf @@ -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 { diff --git a/addons/arsenal/functions/fnc_canEditDefaultLoadout.sqf b/addons/arsenal/functions/fnc_canEditDefaultLoadout.sqf new file mode 100644 index 0000000000..6f9dc8738c --- /dev/null +++ b/addons/arsenal/functions/fnc_canEditDefaultLoadout.sqf @@ -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 + * + * Public: No +*/ + +is3DEN || EFUNC(common,hasZeusAccess) diff --git a/addons/arsenal/functions/fnc_loadoutsChangeTab.sqf b/addons/arsenal/functions/fnc_loadoutsChangeTab.sqf index 8b6e973ad8..13300bb2a4 100644 --- a/addons/arsenal/functions/fnc_loadoutsChangeTab.sqf +++ b/addons/arsenal/functions/fnc_loadoutsChangeTab.sqf @@ -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); }; diff --git a/addons/arsenal/functions/fnc_onSelChangedLoadouts.sqf b/addons/arsenal/functions/fnc_onSelChangedLoadouts.sqf index 0d742347c9..b982652071 100644 --- a/addons/arsenal/functions/fnc_onSelChangedLoadouts.sqf +++ b/addons/arsenal/functions/fnc_onSelChangedLoadouts.sqf @@ -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]; diff --git a/addons/arsenal/functions/fnc_removeDefaultLoadout.sqf b/addons/arsenal/functions/fnc_removeDefaultLoadout.sqf new file mode 100644 index 0000000000..fd0c31bd62 --- /dev/null +++ b/addons/arsenal/functions/fnc_removeDefaultLoadout.sqf @@ -0,0 +1,28 @@ +#include "script_component.hpp" +/* + * Author: LinkIsGrim + * Removes a loadout from the "Default Loadouts" list. + * + * Arguments: + * 0: Name of loadout + * 1: Remove globally (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)]]; +}; diff --git a/addons/arsenal/functions/fnc_renameDefaultLoadout.sqf b/addons/arsenal/functions/fnc_renameDefaultLoadout.sqf new file mode 100644 index 0000000000..9d8e8b2a47 --- /dev/null +++ b/addons/arsenal/functions/fnc_renameDefaultLoadout.sqf @@ -0,0 +1,25 @@ +#include "script_component.hpp" +/* + * Author: LinkIsGrim + * Renames a loadout from the "Default Loadouts" list. + * + * Arguments: + * 0: Current name of loadout + * 1: New name of loadout + * + * 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]; diff --git a/docs/wiki/framework/arsenal-framework.md b/docs/wiki/framework/arsenal-framework.md index b0ee255493..5bf9ebd5e8 100644 --- a/docs/wiki/framework/arsenal-framework.md +++ b/docs/wiki/framework/arsenal-framework.md @@ -174,7 +174,13 @@ To do so: This loadout list can be exported to the clipboard by using Shift + LMB. 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 Shift + LMB 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 Shift + < ---| -------- | ---- | ------------------------ 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.