From dd0f3844f4cb9495469489dec564e191d130f2dc Mon Sep 17 00:00:00 2001 From: Josuan Albin Date: Tue, 7 Nov 2017 20:01:45 +0100 Subject: [PATCH] Fix loadout import, update unique items list after import / loadout load --- addons/arsenal/XEH_PREP.hpp | 1 + addons/arsenal/functions/fnc_buttonImport.sqf | 3 + .../functions/fnc_buttonLoadoutsLoad.sqf | 2 + .../arsenal/functions/fnc_onArsenalOpen.sqf | 105 +--------------- .../functions/fnc_updateUniqueItemsList.sqf | 118 ++++++++++++++++++ 5 files changed, 126 insertions(+), 103 deletions(-) create mode 100644 addons/arsenal/functions/fnc_updateUniqueItemsList.sqf diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index 02d59e6513..576115ad68 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -41,4 +41,5 @@ PREP(showItem); PREP(sortPanel); PREP(updateCamPos); PREP(updateRightPanel); +PREP(updateUniqueItemsList); PREP(verifyLoadout); diff --git a/addons/arsenal/functions/fnc_buttonImport.sqf b/addons/arsenal/functions/fnc_buttonImport.sqf index 08958f2439..40a331aab2 100644 --- a/addons/arsenal/functions/fnc_buttonImport.sqf +++ b/addons/arsenal/functions/fnc_buttonImport.sqf @@ -11,6 +11,7 @@ * Public: No */ #include "script_component.hpp" +#include "..\defines.hpp" params ["_display"]; @@ -106,6 +107,8 @@ if (GVAR(shiftState) && {is3DEN}) then { }; } foreach (assignedItems GVAR(center)); + call FUNC(updateUniqueItemsList); + // Reapply insignia [GVAR(center), ""] call bis_fnc_setUnitInsignia; [GVAR(center), GVAR(currentInsignia)] call bis_fnc_setUnitInsignia; diff --git a/addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf b/addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf index 49077f5961..f72f560154 100644 --- a/addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf +++ b/addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf @@ -92,6 +92,8 @@ for "_index" from 0 to 15 do { }; } foreach (assignedItems GVAR(center)); +call FUNC(updateUniqueItemsList); + // Reapply insignia [GVAR(center), ""] call bis_fnc_setUnitInsignia; [GVAR(center), GVAR(currentInsignia)] call bis_fnc_setUnitInsignia; diff --git a/addons/arsenal/functions/fnc_onArsenalOpen.sqf b/addons/arsenal/functions/fnc_onArsenalOpen.sqf index 616eeb4e7d..fb9e6a88bf 100644 --- a/addons/arsenal/functions/fnc_onArsenalOpen.sqf +++ b/addons/arsenal/functions/fnc_onArsenalOpen.sqf @@ -46,13 +46,6 @@ if (isNil QGVAR(virtualItems)) then { GVAR(virtualItems) = [[[], [], []], [[], [], [], []], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]; }; -GVAR(virtualItems) set [18, []]; -GVAR(virtualItems) set [19, []]; -GVAR(virtualItems) set [20, []]; -GVAR(virtualItems) set [21, []]; -GVAR(virtualItems) set [22, [[], [], [], []]]; -GVAR(virtualItems) set [23, []]; -GVAR(virtualItems) set [24, []]; GVAR(currentItems) = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", [], [], [], [], [], []]; GVAR(currentFace) = face GVAR(center); @@ -105,102 +98,8 @@ for "_index" from 0 to 10 do { // Inventory items case 2: { - private _array = LIST_DEFAULTS select _index; - private _itemsCache = uiNamespace getVariable QGVAR(configItems); - - private _configCfgWeapons = configFile >> "CfgWeapons"; - private _configMagazines = configFile >> "CfgMagazines"; - private _configVehicles = configFile >> "CfgVehicles"; - private _configGlasses = configFile >> "CfgGlasses"; - - { - switch true do { - // Weapon mag - case ( - isClass (_configMagazines >> _x) && - {_x in (_itemsCache select 2)} && - {!(_x in (GVAR(virtualItems) select 2))} - ): { - (GVAR(virtualItems) select 19) pushBackUnique _x; - }; - - // Mag throw - case ( - isClass (_configMagazines >> _x) && - {_x in (_itemsCache select 15)} && - {!(_x in (GVAR(virtualItems) select 15))} - ): { - (GVAR(virtualItems) select 20) pushBackUnique _x; - }; - - // Mag put - case ( - isClass (_configMagazines >> _x) && - {_x in (_itemsCache select 16)} && - {!(_x in (GVAR(virtualItems) select 16))} - ): { - (GVAR(virtualItems) select 21) pushBackUnique _x; - }; - - // acc - case ( - isClass (_configCfgWeapons >> _x) && - {!(_x in ((GVAR(virtualItems) select 1) select 0))} && - {_x in ((_itemsCache select 1) select 0)} - ): { - ((GVAR(virtualItems) select 22) select 0) pushBackUnique _x; - }; - - // acc - case ( - isClass (_configCfgWeapons >> _x) && - {!(_x in ((GVAR(virtualItems) select 1) select 1))} && - {_x in ((_itemsCache select 1) select 1)} - ): { - ((GVAR(virtualItems) select 22) select 1) pushBackUnique _x; - }; - - // acc - case ( - isClass (_configCfgWeapons >> _x) && - {!(_x in ((GVAR(virtualItems) select 1) select 2))} && - {_x in ((_itemsCache select 1) select 2)} - ): { - ((GVAR(virtualItems) select 22) select 2) pushBackUnique _x; - }; - // acc - case ( - isClass (_configCfgWeapons >> _x) && - {!(_x in ((GVAR(virtualItems) select 1) select 3))} && - {_x in ((_itemsCache select 1) select 3)} - ): { - ((GVAR(virtualItems) select 22) select 3) pushBackUnique _x; - }; - - // Misc - case ( - isClass (_configCfgWeapons >> _x) && - {!(_x in (GVAR(virtualItems) select 17))} && - {!(_x in ((_itemsCache select 1) select 0))} && - {!(_x in ((_itemsCache select 1) select 1))} && - {!(_x in ((_itemsCache select 1) select 2))} && - {!(_x in ((_itemsCache select 1) select 3))} - ): { - (GVAR(virtualItems) select 18) pushBackUnique _x; - }; - - // Backpacks - case (isClass (_configVehicles >> _x)): { - (GVAR(virtualItems) select 23) pushBackUnique _x; - }; - - // Facewear - case (isClass (_configGlasses >> _x)): { - (GVAR(virtualItems) select 24) pushBackUnique _x; - }; - }; - } foreach _array; - }; + call FUNC(updateUniqueItemsList); + }; // The rest default { diff --git a/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf b/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf new file mode 100644 index 0000000000..7a037d987d --- /dev/null +++ b/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf @@ -0,0 +1,118 @@ +/* + * Author: Alganthe + * Update the list of unique items. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No +*/ +#include "script_component.hpp" +#include "..\defines.hpp" + +GVAR(virtualItems) set [18, []]; +GVAR(virtualItems) set [19, []]; +GVAR(virtualItems) set [20, []]; +GVAR(virtualItems) set [21, []]; +GVAR(virtualItems) set [22, [[], [], [], []]]; +GVAR(virtualItems) set [23, []]; +GVAR(virtualItems) set [24, []]; + +private _array = LIST_DEFAULTS select 2; +private _itemsCache = uiNamespace getVariable QGVAR(configItems); + +private _configCfgWeapons = configFile >> "CfgWeapons"; +private _configMagazines = configFile >> "CfgMagazines"; +private _configVehicles = configFile >> "CfgVehicles"; +private _configGlasses = configFile >> "CfgGlasses"; + +{ + switch true do { + // Weapon mag + case ( + isClass (_configMagazines >> _x) && + {_x in (_itemsCache select 2)} && + {!(_x in (GVAR(virtualItems) select 2))} + ): { + (GVAR(virtualItems) select 19) pushBackUnique _x; + }; + + // Mag throw + case ( + isClass (_configMagazines >> _x) && + {_x in (_itemsCache select 15)} && + {!(_x in (GVAR(virtualItems) select 15))} + ): { + (GVAR(virtualItems) select 20) pushBackUnique _x; + }; + + // Mag put + case ( + isClass (_configMagazines >> _x) && + {_x in (_itemsCache select 16)} && + {!(_x in (GVAR(virtualItems) select 16))} + ): { + (GVAR(virtualItems) select 21) pushBackUnique _x; + }; + + // acc + case ( + isClass (_configCfgWeapons >> _x) && + {!(_x in ((GVAR(virtualItems) select 1) select 0))} && + {_x in ((_itemsCache select 1) select 0)} + ): { + ((GVAR(virtualItems) select 22) select 0) pushBackUnique _x; + }; + + // acc + case ( + isClass (_configCfgWeapons >> _x) && + {!(_x in ((GVAR(virtualItems) select 1) select 1))} && + {_x in ((_itemsCache select 1) select 1)} + ): { + ((GVAR(virtualItems) select 22) select 1) pushBackUnique _x; + }; + + // acc + case ( + isClass (_configCfgWeapons >> _x) && + {!(_x in ((GVAR(virtualItems) select 1) select 2))} && + {_x in ((_itemsCache select 1) select 2)} + ): { + ((GVAR(virtualItems) select 22) select 2) pushBackUnique _x; + }; + // acc + case ( + isClass (_configCfgWeapons >> _x) && + {!(_x in ((GVAR(virtualItems) select 1) select 3))} && + {_x in ((_itemsCache select 1) select 3)} + ): { + ((GVAR(virtualItems) select 22) select 3) pushBackUnique _x; + }; + + // Misc + case ( + isClass (_configCfgWeapons >> _x) && + {!(_x in (GVAR(virtualItems) select 17))} && + {!(_x in ((_itemsCache select 1) select 0))} && + {!(_x in ((_itemsCache select 1) select 1))} && + {!(_x in ((_itemsCache select 1) select 2))} && + {!(_x in ((_itemsCache select 1) select 3))} + ): { + (GVAR(virtualItems) select 18) pushBackUnique _x; + }; + + // Backpacks + case (isClass (_configVehicles >> _x)): { + (GVAR(virtualItems) select 23) pushBackUnique _x; + }; + + // Facewear + case (isClass (_configGlasses >> _x)): { + (GVAR(virtualItems) select 24) pushBackUnique _x; + }; + }; +} foreach _array;