Skip to content

Commit

Permalink
Common - Add CBA extended loadout (acemod#8923)
Browse files Browse the repository at this point in the history
* extended loadouts - earplugs, gunbag, and arsenal identity

* arsenal - maintain default loadout size check

* restore comment

Co-authored-by: jonpas <jonpas33@gmail.com>

* fix forgotten example

Co-authored-by: jonpas <jonpas33@gmail.com>
  • Loading branch information
2 people authored and RusComBear committed Dec 29, 2023
1 parent be53c69 commit 402f50b
Show file tree
Hide file tree
Showing 25 changed files with 226 additions and 52 deletions.
1 change: 1 addition & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ PREP(fillLeftPanel);
PREP(fillLoadoutsList);
PREP(fillRightPanel);
PREP(fillSort);
PREP(getLoadout);
PREP(handleLoadoutsSearchbar);
PREP(handleMouse);
PREP(handleScrollWheel);
Expand Down
20 changes: 19 additions & 1 deletion addons/arsenal/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ GVAR(lastSortRight) = "";
if (!isNil QGVAR(currentLoadoutsTab) && {GVAR(currentLoadoutsTab) == IDC_buttonSharedLoadouts}) then {

private _curSelData =_contentPanelCtrl lnbData [(lnbCurSelRow _contentPanelCtrl), 1];
([_loadoutData] call FUNC(verifyLoadout)) params ["_loadout", "_nullItemsAmount", "_unavailableItemsAmount"];
([_loadoutData] call FUNC(verifyLoadout)) params ["_extendedLoadout", "_nullItemsAmount", "_unavailableItemsAmount"];

private _newRow = _contentPanelCtrl lnbAddRow [_playerName, _loadoutName];

_extendedLoadout params ["_loadout"];
ADD_LOADOUTS_LIST_PICTURES

_contentPanelCtrl lnbSetData [[_newRow, 1], _playerName + _loadoutName];
Expand All @@ -85,3 +86,20 @@ GVAR(lastSortRight) = "";
};
};
}] call CBA_fnc_addEventHandler;

["CBA_loadoutSet", {
params ["_unit", "_loadout", "_extendedInfo"];
private _face = _extendedInfo getOrDefault [QGVAR(face), ""];
if (_face != "") then {
_unit setFace _face;
};
private _voice = _extendedInfo getOrDefault [QGVAR(voice), ""];
if (_voice != "") then {
_unit setSpeaker _voice;
};
private _insignia = _extendedInfo getOrDefault [QGVAR(insignia), ""];
if (_insignia != "") then {
_unit setVariable ["BIS_fnc_setUnitInsignia_class", nil];
[_unit, _insignia] call bis_fnc_setUnitInsignia;
};
}] call CBA_fnc_addEventHandler;
10 changes: 7 additions & 3 deletions addons/arsenal/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ PREP_RECOMPILE_END;
[QGVAR(enableIdentityTabs), "CHECKBOX", localize LSTRING(enableIdentityTabsSettings), localize LSTRING(settingCategory), true, true] call CBA_fnc_addSetting;

// Arsenal loadouts
[QGVAR(allowDefaultLoadouts), "CHECKBOX", [LSTRING(allowDefaultLoadoutsSetting), LSTRING(defaultLoadoutsTooltip)], localize LSTRING(settingCategory), true, true] call CBA_fnc_addSetting;
[QGVAR(allowSharedLoadouts), "CHECKBOX", localize LSTRING(allowSharingSetting), localize LSTRING(settingCategory), true, true] call CBA_fnc_addSetting;
[QGVAR(EnableRPTLog), "CHECKBOX", [LSTRING(printToRPTSetting), LSTRING(printToRPTTooltip)], localize LSTRING(settingCategory), false, false] call CBA_fnc_addSetting;
[QGVAR(allowDefaultLoadouts), "CHECKBOX", [LSTRING(allowDefaultLoadoutsSetting), LSTRING(defaultLoadoutsTooltip)], [localize LSTRING(settingCategory), localize LSTRING(loadoutSubcategory)], true, true] call CBA_fnc_addSetting;
[QGVAR(allowSharedLoadouts), "CHECKBOX", localize LSTRING(allowSharingSetting), [localize LSTRING(settingCategory), localize LSTRING(loadoutSubcategory)], true, true] call CBA_fnc_addSetting;
[QGVAR(EnableRPTLog), "CHECKBOX", [LSTRING(printToRPTSetting), LSTRING(printToRPTTooltip)], [localize LSTRING(settingCategory), localize LSTRING(loadoutSubcategory)], false, false] call CBA_fnc_addSetting;

[QGVAR(loadoutsSaveFace), "CHECKBOX", localize LSTRING(loadoutsSaveFaceSetting), [localize LSTRING(settingCategory), localize LSTRING(loadoutSubcategory)], false] call CBA_fnc_addSetting;
[QGVAR(loadoutsSaveVoice), "CHECKBOX", localize LSTRING(loadoutsSaveVoiceSetting), [localize LSTRING(settingCategory), localize LSTRING(loadoutSubcategory)], false] call CBA_fnc_addSetting;
[QGVAR(loadoutsSaveInsignia), "CHECKBOX", localize LSTRING(loadoutsSaveInsigniaSetting), [localize LSTRING(settingCategory), localize LSTRING(loadoutSubcategory)], true] call CBA_fnc_addSetting;

[QGVAR(statsToggle), {
params ["_display", "_showStats"];
Expand Down
20 changes: 14 additions & 6 deletions addons/arsenal/functions/fnc_addDefaultLoadout.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Arguments:
* 0: Name of loadout <STRING>
* 1: getUnitLoadout array <ARRAY>
* 1: CBA extended loadout or getUnitLoadout array <ARRAY>
*
* Return Value:
* None
Expand All @@ -17,7 +17,15 @@
* Public: Yes
*/

params [["_name", "", [""]], ["_loadout", [], [[]], 10]];
params [["_name", "", [""]], ["_loadout", [], [[]]]];

private _extendedInfo = createHashMap;
if (count _loadout == 2) then {
_extendedInfo = _loadout select 1;
_loadout = _loadout select 0;
};

if (count _loadout != 10) exitWith {};

if (isNil QGVAR(defaultLoadoutsList)) then {
GVAR(defaultLoadoutsList) = [];
Expand All @@ -36,7 +44,7 @@ for "_dataIndex" from 0 to 10 do {
if (_weapon != "") then {

private _baseWeapon = _weapon call BIS_fnc_baseWeapon;
if (_weapon != _baseWeapon) then {
if (_weapon != _baseWeapon) then {
(_loadout select _dataIndex) set [0, _baseWeapon];
};
};
Expand Down Expand Up @@ -71,7 +79,7 @@ for "_dataIndex" from 0 to 10 do {

private _baseWeapon = _weapon call BIS_fnc_baseWeapon;
if (_weapon != _baseWeapon) then {
(_x select 0)set [0, _baseWeapon];
(_x select 0) set [0, _baseWeapon];
};
};
};
Expand Down Expand Up @@ -100,7 +108,7 @@ for "_dataIndex" from 0 to 10 do {

private _loadoutIndex = (+(GVAR(defaultLoadoutsList))) findIf {(_x select 0) == _name};
if (_loadoutIndex == -1) then {
GVAR(defaultLoadoutsList) pushBack [_name, _loadout];
GVAR(defaultLoadoutsList) pushBack [_name, [_loadout, _extendedInfo]];
} else {
GVAR(defaultLoadoutsList) set [_loadoutIndex, [_name, _loadout]];
GVAR(defaultLoadoutsList) set [_loadoutIndex, [_name, [_loadout, _extendedInfo]]];
};
2 changes: 1 addition & 1 deletion addons/arsenal/functions/fnc_buttonExport.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (GVAR(shiftState)) then {
[_display, localize LSTRING(exportDefault)] call FUNC(message);
} else {

private _export = str getUnitLoadout GVAR(center);
private _export = str ([GVAR(center)] call FUNC(getLoadout));
"ace_clipboard" callExtension (_export + ";");
"ace_clipboard" callExtension "--COMPLETE--";

Expand Down
20 changes: 16 additions & 4 deletions addons/arsenal/functions/fnc_buttonImport.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ if (GVAR(shiftState) && {is3DEN}) then {
set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]];

} else {
if (count _data == 10) then {
GVAR(center) setUnitLoadout _data;
private _count = count _data;
if (_count == 10 || { _count == 2 }) then {
[GVAR(center), _data] call CBA_fnc_setLoadout;

GVAR(currentItems) = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", [], [], [], [], [], []];
for "_index" from 0 to 15 do {
Expand Down Expand Up @@ -92,8 +93,19 @@ if (GVAR(shiftState) && {is3DEN}) then {
call FUNC(updateUniqueItemsList);

// Reapply insignia
[GVAR(center), ""] call bis_fnc_setUnitInsignia;
[GVAR(center), GVAR(currentInsignia)] call bis_fnc_setUnitInsignia;
if (QGVAR(insignia) in _loadout#1) then {
GVAR(currentInsignia) = _loadout#1 getOrDefault [QGVAR(insignia), ""];
} else {
[GVAR(center), ""] call bis_fnc_setUnitInsignia;
[GVAR(center), GVAR(currentInsignia)] call bis_fnc_setUnitInsignia;
};

if (QGVAR(face) in _loadout#1) then {
GVAR(currentFace) = _loadout#1 getOrDefault [QGVAR(face), GVAR(currentFace)];
};
if (QGVAR(voice) in _loadout#1) then {
GVAR(currentVoice) = _loadout#1 getOrDefault [QGVAR(voice), GVAR(currentVoice)];
};

[_display, _display displayCtrl GVAR(currentLeftPanel)] call FUNC(fillLeftPanel);

Expand Down
20 changes: 16 additions & 4 deletions addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private _loadout = switch GVAR(currentLoadoutsTab) do {
};
};

GVAR(center) setUnitLoadout [_loadout, true];
[GVAR(center), _loadout, true] call CBA_fnc_setLoadout;

GVAR(currentItems) = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", [], [], [], [], [], []];
for "_index" from 0 to 15 do {
Expand Down Expand Up @@ -91,9 +91,21 @@ for "_index" from 0 to 15 do {
call FUNC(updateUniqueItemsList);

// Reapply insignia
[GVAR(center), ""] call bis_fnc_setUnitInsignia;
[GVAR(center), GVAR(currentInsignia)] call bis_fnc_setUnitInsignia;
if (QGVAR(insignia) in _loadout#1) then {
GVAR(currentInsignia) = _loadout#1 getOrDefault [QGVAR(insignia), ""];
} else {
[GVAR(center), ""] call bis_fnc_setUnitInsignia;
[GVAR(center), GVAR(currentInsignia)] call bis_fnc_setUnitInsignia;
};

if (QGVAR(face) in _loadout#1) then {
GVAR(currentFace) = _loadout#1 getOrDefault [QGVAR(face), GVAR(currentFace)];
};
if (QGVAR(voice) in _loadout#1) then {
GVAR(currentVoice) = _loadout#1 getOrDefault [QGVAR(voice), GVAR(currentVoice)];
};

[(findDisplay IDD_ace_arsenal), [localize LSTRING(loadoutLoaded), _loadoutName] joinString " "] call FUNC(message);

[QGVAR(onLoadoutLoad), [_loadout, _loadoutName]] call CBA_fnc_localEvent;
[QGVAR(onLoadoutLoad), [_loadout#0, _loadoutName]] call CBA_fnc_localEvent;
[QGVAR(onLoadoutLoadExtended), [_loadout, _loadoutName]] call CBA_fnc_localEvent;
5 changes: 3 additions & 2 deletions addons/arsenal/functions/fnc_buttonLoadoutsRename.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ if (count _similarLoadouts > 0) exitWith {

// Update loadout info in profile / 3DEN and list namespaces
private _loadoutToRename = (_data select {_x select 0 == _loadoutName}) select 0;
(_contentPanelCtrl getVariable (_loadoutName + str GVAR(currentLoadoutsTab))) params ["_loadout", "_nullItemsAmount", "_unavailableItemsAmount", "_nullItemsList", "_unavailableItemsList"];
(_contentPanelCtrl getVariable (_loadoutName + str GVAR(currentLoadoutsTab))) params ["_extendedLoadout", "_nullItemsAmount", "_unavailableItemsAmount", "_nullItemsList", "_unavailableItemsList"];

_data set [_data find _loadoutToRename, [_editBoxContent, (_loadoutToRename select 1)]];
_contentPanelCtrl setVariable [_loadoutName + str GVAR(currentLoadoutsTab), nil];
_contentPanelCtrl setVariable [_editBoxContent + str GVAR(currentLoadoutsTab), [_loadout, _nullItemsAmount, _unavailableItemsAmount, _nullItemsList, _unavailableItemsList]];
_contentPanelCtrl setVariable [_editBoxContent + str GVAR(currentLoadoutsTab), [_extendedLoadout, _nullItemsAmount, _unavailableItemsAmount, _nullItemsList, _unavailableItemsList]];

// Add new row
_contentPanelCtrl lnbDeleteRow _curSelRow;
private _newRow = _contentPanelCtrl lnbAddRow ["",_editBoxContent];

_extendedLoadout params ["_loadout"];
ADD_LOADOUTS_LIST_PICTURES

if (_nullItemsAmount > 0) then {
Expand Down
20 changes: 11 additions & 9 deletions addons/arsenal/functions/fnc_buttonLoadoutsSave.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ private _cursSelRow = lnbCurSelRow _contentPanelCtrl;

private _loadoutName = _contentPanelCtrl lnbText [_cursSelRow, 1];
private _curSelLoadout = (_contentPanelCtrl getVariable (_loadoutName + str GVAR(currentLoadoutsTab))) select 0;
private _loadout = getUnitLoadout GVAR(center);
private _extendedLoadout = GVAR(center) call FUNC(getLoadout);
private _loadout = _loadout select 0;

private _loadoutIndex = _data findIf {(_x select 0) == _editBoxContent};
private _sharedLoadoutsVars = GVAR(sharedLoadoutsNamespace) getVariable QGVAR(sharedLoadoutsVars);
Expand Down Expand Up @@ -62,7 +63,7 @@ switch (GVAR(currentLoadoutsTab)) do {
if (_weapon != "") then {

private _baseWeapon = _weapon call BIS_fnc_baseWeapon;
if (_weapon != _baseWeapon) then {
if (_weapon != _baseWeapon) then {
(_loadout select _dataIndex) set [0, _baseWeapon];
};
};
Expand Down Expand Up @@ -135,9 +136,9 @@ switch (GVAR(currentLoadoutsTab)) do {
};

if (_loadoutIndex isEqualto -1) then {
_data pushBack [_editBoxContent, _loadout];
_data pushBack [_editBoxContent, _extendedLoadout];
} else {
_data set [_loadoutIndex, [[_editBoxContent, _loadoutName] select (_loadoutName isEqualTo _editBoxContent), _loadout]];
_data set [_loadoutIndex, [[_editBoxContent, _loadoutName] select (_loadoutName isEqualTo _editBoxContent), _extendedLoadout]];
};

// Delete "old" loadout row
Expand All @@ -149,7 +150,7 @@ switch (GVAR(currentLoadoutsTab)) do {

ADD_LOADOUTS_LIST_PICTURES

_contentPanelCtrl setVariable [_editBoxContent + str GVAR(currentLoadoutsTab), [_loadout] call FUNC(verifyLoadout)];
_contentPanelCtrl setVariable [_editBoxContent + str GVAR(currentLoadoutsTab), [_extendedLoadout] call FUNC(verifyLoadout)];

_contentPanelCtrl lnbSort [1, false];

Expand Down Expand Up @@ -243,9 +244,9 @@ switch (GVAR(currentLoadoutsTab)) do {
};

if (_loadoutIndex == -1) then {
GVAR(defaultLoadoutsList) pushBack [_editBoxContent, _loadout];
GVAR(defaultLoadoutsList) pushBack [_editBoxContent, _extendedLoadout];
} else {
GVAR(defaultLoadoutsList) set [_loadoutIndex, [[_editBoxContent, _loadoutName] select (_loadoutName isEqualTo _editBoxContent), _loadout]];
GVAR(defaultLoadoutsList) set [_loadoutIndex, [[_editBoxContent, _loadoutName] select (_loadoutName isEqualTo _editBoxContent), _extendedLoadout]];
};

for '_i' from 0 to (((lnbsize _contentPanelCtrl) select 0) - 1) do {
Expand All @@ -256,7 +257,7 @@ switch (GVAR(currentLoadoutsTab)) do {

ADD_LOADOUTS_LIST_PICTURES

_contentPanelCtrl setVariable [_editBoxContent + str GVAR(currentLoadoutsTab), [_loadout] call FUNC(verifyLoadout)];
_contentPanelCtrl setVariable [_editBoxContent + str GVAR(currentLoadoutsTab), [_extendedLoadout] call FUNC(verifyLoadout)];

_contentPanelCtrl lnbSort [1, false];

Expand Down Expand Up @@ -295,4 +296,5 @@ switch (GVAR(currentLoadoutsTab)) do {
};
[(findDisplay IDD_ace_arsenal), [localize LSTRING(loadoutSaved), _editBoxContent] joinString " "] call FUNC(message);
private _savedLoadout = (_data select {_x select 0 == _editBoxContent}) select 0;
[QGVAR(onLoadoutSave), [_data find _savedLoadout, _savedLoadout]] call CBA_fnc_localEvent;
[QGVAR(onLoadoutSave), [_data find _savedLoadout, _savedLoadout#0]] call CBA_fnc_localEvent;
[QGVAR(onLoadoutSaveExtended), [_data find _savedLoadout, _savedLoadout]] call CBA_fnc_localEvent;
8 changes: 5 additions & 3 deletions addons/arsenal/functions/fnc_fillLoadoutsList.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (GVAR(currentLoadoutsTab) != IDC_buttonSharedLoadouts) then {
[_loadoutData] call FUNC(verifyLoadout)
} else {
_loadoutCachedInfo
} params ["_loadout", "_nullItemsAmount", "_unavailableItemsAmount", "_nullItemsList", "_unavailableItemsList"];
} params ["_extendedLoadout", "_nullItemsAmount", "_unavailableItemsAmount", "_nullItemsList", "_unavailableItemsList"];

// Log missing / nil items to RPT
if (GVAR(EnableRPTLog) && {isNil "_loadoutCachedInfo"} && {(_nullItemsAmount > 0) || {_unavailableItemsAmount > 0}}) then {
Expand All @@ -64,6 +64,7 @@ if (GVAR(currentLoadoutsTab) != IDC_buttonSharedLoadouts) then {

private _newRow = _contentPanelCtrl lnbAddRow ["",_loadoutName];

_extendedLoadout params ["_loadout"];
ADD_LOADOUTS_LIST_PICTURES

if (_nullItemsAmount > 0) then {
Expand All @@ -76,7 +77,7 @@ if (GVAR(currentLoadoutsTab) != IDC_buttonSharedLoadouts) then {
};
};

_contentPanelCtrl setVariable [_loadoutName + str GVAR(currentLoadoutsTab), [_loadout, _nullItemsAmount, _unavailableItemsAmount, _nullItemsList, _unavailableItemsList]];
_contentPanelCtrl setVariable [_loadoutName + str GVAR(currentLoadoutsTab), [_extendedLoadout, _nullItemsAmount, _unavailableItemsAmount, _nullItemsList, _unavailableItemsList]];

if ((profileName + _loadoutName) in _sharedLoadoutsVars && {GVAR(currentLoadoutsTab) == IDC_buttonMyLoadouts}) then {
_contentPanelCtrl lnbSetPicture [[_newRow, 0], QPATHTOF(data\iconPublic.paa)];
Expand All @@ -99,11 +100,12 @@ if (GVAR(currentLoadoutsTab) != IDC_buttonSharedLoadouts) then {
[QGVAR(loadoutUnshared), [_contentPanelCtrl, profileName, _loadoutName]] call CBA_fnc_remoteEvent;
} else {

([_loadoutData] call FUNC(verifyLoadout)) params ["_loadout", "_nullItemsAmount", "_unavailableItemsAmount"];
([_loadoutData] call FUNC(verifyLoadout)) params ["_extendedLoadout", "_nullItemsAmount", "_unavailableItemsAmount"];

_contentPanelCtrl lnbSetColumnsPos [0, 0.15, 0.40, 0.50, 0.60, 0.70, 0.75, 0.80, 0.85, 0.90];
private _newRow = _contentPanelCtrl lnbAddRow [_playerName, _loadoutName];

_extendedLoadout params ["_loadout"];
ADD_LOADOUTS_LIST_PICTURES

_contentPanelCtrl lnbSetData [[_newRow, 1], _playerName + _loadoutName];
Expand Down
37 changes: 37 additions & 0 deletions addons/arsenal/functions/fnc_getLoadout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "script_component.hpp"
/*
* Author: Brett Mayson
* Get the extended loadout of a unit, including identity options if enabled
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* CBA Extended Loadout <ARRAY>
*
* Example:
* [_unit] call ace_arsenal_fnc_getLoadout
*
* Public: Yes
*/

params [["_unit", objNull, [objNull]]];

if (isNull _unit) exitWith {};

([_unit] call CBA_fnc_getLoadout) params ["_loadout", "_extendedInfo"];

if (GVAR(loadoutsSaveFace)) then {
_extendedInfo set [QGVAR(face), face _unit];
};
if (GVAR(loadoutsSaveVoice)) then {
_extendedInfo set [QGVAR(voice), speaker _unit];
};
if (GVAR(loadoutsSaveInsignia)) then {
private _insignia = _unit getVariable ["BIS_fnc_setUnitInsignia_class", ""];
if (_insignia != "") then {
_extendedInfo set [QGVAR(insignia), _insignia];
};
};

[_loadout, _extendedInfo]
2 changes: 1 addition & 1 deletion addons/arsenal/functions/fnc_onArsenalClose.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (is3DEN) then {
// Apply the loadout from the dummy to all selected units
if (_exitCode == 1) then {
{
_x setUnitLoadout (getUnitLoadout GVAR(center));
[_x, GVAR(center) call FUNC(getLoadout)] call CBA_fnc_setLoadout;
} foreach (get3DENSelected "object");

save3DENInventory (get3DENSelected "object");
Expand Down
2 changes: 1 addition & 1 deletion addons/arsenal/functions/fnc_onArsenalOpen.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ for "_index" from 0 to 14 do {
};

if ((_array select 2) isNotEqualTo "") then {
((GVAR(virtualItems) select _index) select 2) pushBackUnique (_array select 2);
((GVAR(virtualItems) select _index) select 2) pushBackUnique (_array select 2);
};
};

Expand Down
Loading

0 comments on commit 402f50b

Please sign in to comment.