Skip to content

Commit

Permalink
Added unique item support for left panel items
Browse files Browse the repository at this point in the history
  • Loading branch information
johnb432 committed Jul 22, 2023
1 parent 3557e93 commit ab77b8d
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 29 deletions.
7 changes: 2 additions & 5 deletions addons/arsenal/functions/fnc_buttonImport.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down
7 changes: 2 additions & 5 deletions addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down
12 changes: 6 additions & 6 deletions addons/arsenal/functions/fnc_itemInfo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions addons/arsenal/functions/fnc_onArsenalOpen.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -107,24 +107,24 @@ 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];

// Add magazines
{
// 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];
};
Expand All @@ -136,27 +136,27 @@ 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
case IDX_LOADOUT_ASSIGNEDITEMS: {
{
// 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;
};
Expand Down
141 changes: 137 additions & 4 deletions addons/arsenal/functions/fnc_refresh.sqf
Original file line number Diff line number Diff line change
@@ -1,19 +1,152 @@
#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
*
* 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);

0 comments on commit ab77b8d

Please sign in to comment.