From ab77b8d05cd3530dfa4d701bac2e00389427178e Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 22 Jul 2023 19:15:27 +0200 Subject: [PATCH] Added unique item support for left panel items --- addons/arsenal/functions/fnc_buttonImport.sqf | 7 +- .../functions/fnc_buttonLoadoutsLoad.sqf | 7 +- addons/arsenal/functions/fnc_itemInfo.sqf | 12 +- .../arsenal/functions/fnc_onArsenalOpen.sqf | 18 +-- addons/arsenal/functions/fnc_refresh.sqf | 141 +++++++++++++++++- 5 files changed, 156 insertions(+), 29 deletions(-) diff --git a/addons/arsenal/functions/fnc_buttonImport.sqf b/addons/arsenal/functions/fnc_buttonImport.sqf index eea1370f9bf..ac4f947cfa3 100644 --- a/addons/arsenal/functions/fnc_buttonImport.sqf +++ b/addons/arsenal/functions/fnc_buttonImport.sqf @@ -50,11 +50,8 @@ if (GVAR(shiftState) && {is3DEN}) then { if ((count _extendedLoadout) == 2) then { [GVAR(center), _extendedLoadout] call CBA_fnc_setLoadout; - // Update current item list - call FUNC(updateCurrentItemsList); - - // This takes care of items that aren't available in the arsenal (either wrong tab or arsenal doesn't have it whitelisted) - call FUNC(updateUniqueItemsList); + // Update current item list and unique items + call FUNC(refresh); _extendedLoadout params ["_loadout", "_extendedInfo"]; diff --git a/addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf b/addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf index 9b09c0d66c6..99f78943116 100644 --- a/addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf +++ b/addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf @@ -37,11 +37,8 @@ private _extendedLoadout = switch (GVAR(currentLoadoutsTab)) do { // Apply loadout to unit [GVAR(center), _extendedLoadout, true] call CBA_fnc_setLoadout; -// Update current item list -call FUNC(updateCurrentItemsList); - -// This takes care of items that aren't available in the arsenal (either wrong tab or arsenal doesn't have it whitelisted) -call FUNC(updateUniqueItemsList); +// Update current item list and unique items +call FUNC(refresh); _extendedLoadout params ["_loadout", "_extendedInfo"]; diff --git a/addons/arsenal/functions/fnc_itemInfo.sqf b/addons/arsenal/functions/fnc_itemInfo.sqf index 9dad0c02478..793d5a85e22 100644 --- a/addons/arsenal/functions/fnc_itemInfo.sqf +++ b/addons/arsenal/functions/fnc_itemInfo.sqf @@ -49,16 +49,16 @@ if (isClass _itemCfg) then { // If an item is from a DLC, set it so when you press the icon on the bottom right it opens the DLC page if ((getNumber (configfile >> "CfgMods" >> _dlc >> "appId")) > 0) then { - _ctrlDLC ctrlSetEventHandler ["mouseExit", format ["(_this select 0) ctrlSetText '%1';", _logo]]; - _ctrlDLC ctrlSetEventHandler ["mouseEnter", format ["(_this select 0) ctrlSetText '%1';", _logoOver]]; + _ctrlDLC ctrlSetEventHandler ["MouseExit", format ["(_this select 0) ctrlSetText '%1';", _logo]]; + _ctrlDLC ctrlSetEventHandler ["MouseEnter", format ["(_this select 0) ctrlSetText '%1';", _logoOver]]; _ctrlDLC ctrlSetEventHandler [ - "buttonClick", + "ButtonClick", format ["uiNamespace setVariable ['RscDisplayDLCPreview_dlc','%1']; ctrlParent (_this select 0) createDisplay 'RscDisplayDLCPreview';", _dlc] ]; } else { - _ctrlDLC ctrlRemoveAllEventHandlers "mouseExit"; - _ctrlDLC ctrlRemoveAllEventHandlers "mouseEnter"; - _ctrlDLC ctrlRemoveAllEventHandlers "buttonClick"; + _ctrlDLC ctrlRemoveAllEventHandlers "MouseExit"; + _ctrlDLC ctrlRemoveAllEventHandlers "MouseEnter"; + _ctrlDLC ctrlRemoveAllEventHandlers "ButtonClick"; }; } else { _ctrlDLC ctrlSetFade 1; diff --git a/addons/arsenal/functions/fnc_onArsenalOpen.sqf b/addons/arsenal/functions/fnc_onArsenalOpen.sqf index ce6b81a0f3b..af5552a6c1e 100644 --- a/addons/arsenal/functions/fnc_onArsenalOpen.sqf +++ b/addons/arsenal/functions/fnc_onArsenalOpen.sqf @@ -91,7 +91,7 @@ GVAR(statsInfo) = [true, 0, controlNull, nil, nil]; GVAR(showActions) = true; GVAR(currentActionPage) = 0; -// Add the items the player has to virtualItems +// Add the items the player has to virtualItems as unique items { switch (_forEachIndex) do { // Primary weapon, Secondary weapon, Handgun weapon, Binoculars @@ -107,16 +107,16 @@ GVAR(currentActionPage) = 0; // If bino, add it in a different place than regular weapons if (_forEachIndex != IDX_LOADOUT_BINO) then { - ((GVAR(virtualItems) get IDX_VIRT_WEAPONS) get _forEachIndex) set [_weapon, nil]; + ((GVAR(virtualItems) get IDX_VIRT_WEAPONS) get _forEachIndex) set [_weapon, true, true]; } else { - (GVAR(virtualItems) get IDX_VIRT_BINO) set [_weapon, nil]; + (GVAR(virtualItems) get IDX_VIRT_BINO) set [_weapon, true, true]; }; }; // Add weapon attachments { if (_x != "") then { - ((GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS) get _forEachIndex) set [_x call FUNC(baseWeapon), nil]; + ((GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS) get _forEachIndex) set [_x call FUNC(baseWeapon), true, true]; }; } forEach [_optics, _flashlight, _muzzle, _bipod]; @@ -124,7 +124,7 @@ GVAR(currentActionPage) = 0; { // Check if there is a magazine (ammo count is unnecssary to check) if ((_x param [0, ""]) != "") then { - (GVAR(virtualItems) get IDX_VIRT_ITEMS_ALL) set [_x select 0, nil]; + (GVAR(virtualItems) get IDX_VIRT_ITEMS_ALL) set [_x select 0, true, true]; }; } forEach [_primaryMagazine, _secondaryMagazine]; }; @@ -136,19 +136,19 @@ GVAR(currentActionPage) = 0; _x params [["_containerClass", ""]]; if (_containerClass != "") then { - (GVAR(virtualItems) get (_forEachIndex + 1)) set [_containerClass, nil]; + (GVAR(virtualItems) get (_forEachIndex + 1)) set [_containerClass, true, true]; }; }; // Helmet case IDX_LOADOUT_HEADGEAR: { if (_x != "") then { - (GVAR(virtualItems) get IDX_VIRT_HEADGEAR) set [_x, nil]; + (GVAR(virtualItems) get IDX_VIRT_HEADGEAR) set [_x, true, true]; }; }; // Facewear case IDX_LOADOUT_GOGGLES: { if (_x != "") then { - (GVAR(virtualItems) get IDX_VIRT_GOGGLES) set [_x, nil]; + (GVAR(virtualItems) get IDX_VIRT_GOGGLES) set [_x, true, true]; }; }; // Assigned items: Map, Compass, Watch, GPS / UAV Terminal, Radio, NVGs @@ -156,7 +156,7 @@ GVAR(currentActionPage) = 0; { // Order of storing virtualItems is different than what getUnitLoadout returns, so do some math if (_x != "") then { - (GVAR(virtualItems) get (IDX_VIRT_NVG + ([2, 6, 4, 3, 5, 0] select _forEachIndex))) set [_x, nil]; + (GVAR(virtualItems) get (IDX_VIRT_NVG + ([2, 6, 4, 3, 5, 0] select _forEachIndex))) set [_x, true, true]; }; } forEach _x; }; diff --git a/addons/arsenal/functions/fnc_refresh.sqf b/addons/arsenal/functions/fnc_refresh.sqf index 8f3ebab7aeb..866e9441603 100644 --- a/addons/arsenal/functions/fnc_refresh.sqf +++ b/addons/arsenal/functions/fnc_refresh.sqf @@ -1,8 +1,8 @@ #include "script_component.hpp" #include "..\defines.hpp" /* - * Author: Brett Mayson - * Refreshes the arsenal to show external changes + * Author: Brett Mayson, johnb43 + * Refreshes the arsenal to show external changes. * * Return Value: * None @@ -10,10 +10,143 @@ * Public: No */ -private _display = findDisplay IDD_ace_arsenal; - +// Update current item list call FUNC(updateCurrentItemsList); +// This takes care of items that aren't available in the arsenal (either wrong tab or arsenal doesn't have it whitelisted) call FUNC(updateUniqueItemsList); +// Remove unique items in any panel that can display no or one item, but not multiple +private _items = createHashMap; +private _itemsToDelete = []; +private _index = -1; + +// Add the items the player has to currentItems +{ + switch (_forEachIndex) do { + // Primary weapon, Secondary weapon, Handgun weapon, Binoculars + case IDX_CURR_PRIMARY_WEAPON; + case IDX_CURR_SECONDARY_WEAPON; + case IDX_CURR_HANDGUN_WEAPON: { + _items = (GVAR(virtualItems) get IDX_VIRT_WEAPONS) get _forEachIndex; + _itemsToDelete = []; + + // Remove all unique weapons in tab + { + if (!isNil "_y") then { + _itemsToDelete pushBack _x; + }; + } forEach _items; + + { + _items deleteAt _x; + GVAR(virtualItemsFlatAll) deleteAt _x; + } forEach _itemsToDelete; + + // Add weapon as a unique weapon + if (_x != "") then { + _items set [_x, true, true]; + GVAR(virtualItemsFlatAll) set [_x, true, true]; + }; + }; + // Weapon items + case IDX_CURR_PRIMARY_WEAPON_ITEMS; + case IDX_CURR_SECONDARY_WEAPON_ITEMS; + case IDX_CURR_HANDGUN_WEAPON_ITEMS; + case IDX_CURR_BINO_ITEMS: { + _x params ["_muzzle", "_flashlight", "_optics", "_bipod", "_primaryMagazine", "_secondaryMagazine"]; + + _index = _forEachIndex; + + // Weapon attachments + { + _items = (GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS) get _forEachIndex; + + // Execute only once + if (_index == IDX_CURR_PRIMARY_WEAPON_ITEMS) then { + _itemsToDelete = []; + + // Remove all unique weapon attachments of concerned tab + { + if (!isNil "_y") then { + _itemsToDelete pushBack _x; + }; + } forEach _items; + + { + _items deleteAt _x; + GVAR(virtualItemsFlatAll) deleteAt _x; + } forEach _itemsToDelete; + }; + + // Add weapon attachment as a unique weapon attachment + if (_x != "") then { + _items set [_x, true, true]; + GVAR(virtualItemsFlatAll) set [_x, true, true]; + }; + } forEach [_optics, _flashlight, _muzzle, _bipod]; + + // Magazines + _items = GVAR(virtualItems) get IDX_VIRT_ITEMS_ALL; + + // Execute only once + if (_index == IDX_CURR_PRIMARY_WEAPON_ITEMS) then { + _itemsToDelete = []; + + // Remove all unique magazines of concerned tab + { + if (!isNil "_y") then { + _itemsToDelete pushBack _x; + }; + } forEach _items; + + { + _items deleteAt _x; + GVAR(virtualItemsFlatAll) deleteAt _x; + } forEach _itemsToDelete; + }; + + // Add magazines as unique magazines + { + if (_x != "") then { + _items set [_x, true, true]; + GVAR(virtualItemsFlatAll) set [_x, true, true]; + }; + } forEach [_primaryMagazine, _secondaryMagazine]; + }; + // Inventory items + case IDX_CURR_UNIFORM_ITEMS; + case IDX_CURR_VEST_ITEMS; + case IDX_CURR_BACKPACK_ITEMS: {}; + // Other + default { + _items = GVAR(virtualItems) get _forEachIndex; + _itemsToDelete = []; + + // Remove all unique items of concerned tab + { + if (!isNil "_y") then { + _itemsToDelete pushBack _x; + }; + } forEach _items; + + { + _items deleteAt _x; + GVAR(virtualItemsFlatAll) deleteAt _x; + } forEach _itemsToDelete; + + // Add item as a unique item + if (_x != "") then { + _items set [_x, true, true]; + GVAR(virtualItemsFlatAll) set [_x, true, true]; + }; + }; + }; +} forEach GVAR(currentItems); + +// Don't refresh left panel if in loadout tab +if (!isNull findDisplay IDD_loadouts_display) exitWith {}; + +private _display = findDisplay IDD_ace_arsenal; + [_display, _display displayCtrl GVAR(currentLeftPanel)] call FUNC(fillLeftPanel);