Skip to content

Commit

Permalink
Inventory - Improve multiple aspects (#9706)
Browse files Browse the repository at this point in the history
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
  • Loading branch information
johnb432 and LinkIsGrim authored Jan 6, 2024
1 parent bed8844 commit 7f998c3
Show file tree
Hide file tree
Showing 23 changed files with 156 additions and 150 deletions.
8 changes: 7 additions & 1 deletion addons/inventory/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
Expand All @@ -20,5 +19,12 @@ class Extended_PostInit_EventHandlers {
class Extended_DisplayLoad_EventHandlers {
class RscDisplayInventory {
ADDON = QUOTE(_this call FUNC(inventoryDisplayLoad));
GVAR(displayNameWeight) = QUOTE(_this call FUNC(displayNameWeight)); // separate to allow other mods to disable them individually
};
};

class Extended_DisplayUnload_EventHandlers {
class RscDisplayInventory {
ADDON = QUOTE(GVAR(unit) = ACE_player);
};
};
28 changes: 14 additions & 14 deletions addons/inventory/RscDisplayInventory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ class RscCombo;
#define W_MAKEITBIGGA(num) (num * (safeZoneH / 40))
#define H_MAKEITBIGGA(num) (num * (safeZoneH / 30))

#define X_PART(num) QUOTE(linearConversion [ARR_5(0,2,(missionNamespace getVariable [ARR_2(QUOTE(QGVAR(inventoryDisplaySize)),0)]),X_BIS(num),X_MAKEITBIGGA(num))])
#define Y_PART(num) QUOTE(linearConversion [ARR_5(0,2,(missionNamespace getVariable [ARR_2(QUOTE(QGVAR(inventoryDisplaySize)),0)]),Y_BIS(num),Y_MAKEITBIGGA(num))])
#define W_PART(num) QUOTE(linearConversion [ARR_5(0,2,(missionNamespace getVariable [ARR_2(QUOTE(QGVAR(inventoryDisplaySize)),0)]),W_BIS(num),W_MAKEITBIGGA(num))])
#define H_PART(num) QUOTE(linearConversion [ARR_5(0,2,(missionNamespace getVariable [ARR_2(QUOTE(QGVAR(inventoryDisplaySize)),0)]),H_BIS(num),H_MAKEITBIGGA(num))])
#define X_PART(num) QUOTE(linearConversion [ARR_5(0,2,(missionNamespace getVariable [ARR_2(QQGVAR(inventoryDisplaySize),0)]),X_BIS(num),X_MAKEITBIGGA(num))])
#define Y_PART(num) QUOTE(linearConversion [ARR_5(0,2,(missionNamespace getVariable [ARR_2(QQGVAR(inventoryDisplaySize),0)]),Y_BIS(num),Y_MAKEITBIGGA(num))])
#define W_PART(num) QUOTE(linearConversion [ARR_5(0,2,(missionNamespace getVariable [ARR_2(QQGVAR(inventoryDisplaySize),0)]),W_BIS(num),W_MAKEITBIGGA(num))])
#define H_PART(num) QUOTE(linearConversion [ARR_5(0,2,(missionNamespace getVariable [ARR_2(QQGVAR(inventoryDisplaySize),0)]),H_BIS(num),H_MAKEITBIGGA(num))])

class RscDisplayInventory {
class controls {
class CA_ContainerBackground: RscText {
//crate: GroundLoad adjust size
// Crate: GroundLoad adjust size
x = X_PART(1);
y = Y_PART(1);
w = W_PART(12);
h = H_PART(22.5); //default 23
h = H_PART(22.5); // default 23
};
class CA_PlayerBackground: RscText {
//center player's container: decrease height because of progressbar height decrease
// Center player's container: Decrease height because of progressbar height decrease
x = X_PART(14.6);
y = Y_PART(2);
w = W_PART(24.4);
h = H_PART(21.5); //default 22
h = H_PART(21.5); // default 22
};
class TitleBackground: RscText {
x = X_PART(14.6);
Expand Down Expand Up @@ -98,7 +98,7 @@ class RscDisplayInventory {
};
class BackgroundSlotPrimaryFlashlight: BackgroundSlotPrimary {
x = X_PART(30.6);
y = Y_PART(9.2); //not sure why different (double check release)
y = Y_PART(9.2); // not sure why different (double check release)
w = W_PART(1.9);
h = H_PART(2);
};
Expand Down Expand Up @@ -283,11 +283,11 @@ class RscDisplayInventory {
h = H_PART(1);
};
class GroundLoad: RscProgress {
//crate: GroundLoad adjust size
// Crate: GroundLoad adjust size
x = X_PART(1.5);
y = Y_PART(22.5);
w = W_PART(11);
h = H_PART(0.5); //Default 1
h = H_PART(0.5); // Default 1
};
class SlotPrimary: GroundTab {
x = X_PART(26.6);
Expand Down Expand Up @@ -345,7 +345,7 @@ class RscDisplayInventory {
};
class SlotSecondaryUnderBarrel: SlotPrimary {
x = X_PART(29);
y = Y_PART(14.59); //Why is this different? (check release)
y = Y_PART(14.59); // Why is this different? (check release)
w = W_PART(2.3);
h = H_PART(2);
};
Expand Down Expand Up @@ -518,11 +518,11 @@ class RscDisplayInventory {
h = H_PART(0.5);
};
class TotalLoad: GroundLoad {
//center: progressbar height decrease
// Center: progressbar height decrease
x = X_PART(15.1);
y = Y_PART(22.5);
w = W_PART(23.4);
h = H_PART(0.5); //Default 1
h = H_PART(0.5); // default 1
};
class ContainerMarker: GroundTab {
x = X_PART(0);
Expand Down
9 changes: 4 additions & 5 deletions addons/inventory/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

PREP(addCustomFilter);
PREP(currentItemListBox);
PREP(forceItemListUpdate);
PREP(inventoryDisplayLoad);
PREP(onLBSelChanged);

PREP(displayNameWeight);
PREP(filterWeapons);
PREP(filterMagazines);
PREP(filterItems);
Expand All @@ -14,3 +10,6 @@ PREP(filterVests);
PREP(filterBackpacks);
PREP(filterGrenades);
PREP(filterMedical);
PREP(forceItemListUpdate);
PREP(inventoryDisplayLoad);
PREP(onLBSelChanged);
57 changes: 28 additions & 29 deletions addons/inventory/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@

if (!hasInterface) exitWith {};

// cache config
// items in the inventory display can only be distinguished by their lb names and pictures
// this can cause collisions (mainly weapons with attachments),
// but if the item has the same name and picture it at least shouldn't change the filter anyway
// luckily we don't need private items, so dummy and parent classes are out of the picture

GVAR(ItemKeyNamespace) = [] call CBA_fnc_createNamespace;
private _allItems = uiNamespace getVariable [QGVAR(ItemKeyCache), []]; //See XEH_preStart.sqf

// isEqualType is hacking protection as we cannot trust that the cache hasn't been manipulated
{
if (_x isEqualType [] && {_x isEqualTypeArray ["", configNull]}) then {
GVAR(ItemKeyNamespace) setVariable _x;
};
} forEach ([[], _allItems] select (_allItems isEqualType []));
// If medical_treatment is loaded, get its items
if (["ace_medical_treatment"] call EFUNC(common,isModLoaded)) then {
private _medicalList = +(uiNamespace getVariable [QGVAR(medicalItemList), createHashMap]);

_medicalList merge [uiNamespace getVariable [QEGVAR(medical_treatment,treatmentItems), createHashMap], true];

GVAR(medicalItemList) = compileFinal _medicalList;
} else {
GVAR(medicalItemList) = uiNamespace getVariable [QGVAR(medicalItemList), compileFinal createHashMap];
};

GVAR(customFilters) = [];
GVAR(selectedFilterIndex) = -1;

// add custom filters
// Add custom filters
[LLSTRING(Grenades), QFUNC(filterGrenades)] call FUNC(addCustomFilter);
[LLSTRING(Backpacks), QFUNC(filterBackpacks)] call FUNC(addCustomFilter);
[LLSTRING(Uniforms), QFUNC(filterUniforms)] call FUNC(addCustomFilter);
[LLSTRING(Vests), QFUNC(filterVests)] call FUNC(addCustomFilter);
[LLSTRING(Headgear), QFUNC(filterHeadgear)] call FUNC(addCustomFilter);
[LLSTRING(Medical), QFUNC(filterMedical)] call FUNC(addCustomFilter);

// get list of grenades
GVAR(Grenades_ItemList) = uiNamespace getVariable [QGVAR(Grenades_ItemList), []];
if (!(GVAR(Grenades_ItemList) isEqualType [])) then {GVAR(Grenades_ItemList) = []};
// Used for displaying the correct name when opening a subordinate's inventory
GVAR(unit) = ACE_player;

[localize LSTRING(Grenades), QFUNC(filterGrenades)] call FUNC(addCustomFilter);
["CAManBase", "InventoryOpened", {
params ["_unit", "_container"];

[localize LSTRING(Backpacks), QFUNC(filterBackpacks)] call FUNC(addCustomFilter);
[localize LSTRING(Uniforms), QFUNC(filterUniforms)] call FUNC(addCustomFilter);
[localize LSTRING(Vests), QFUNC(filterVests)] call FUNC(addCustomFilter);
[localize LSTRING(Headgear), QFUNC(filterHeadgear)] call FUNC(addCustomFilter);
// GVAR(unit) is ACE_player by default
if (_unit isEqualTo ACE_player) exitWith {};

// get list of medical items
GVAR(Medical_ItemList) = uiNamespace getVariable [QGVAR(Medical_ItemList), []];
if (!(GVAR(Medical_ItemList) isEqualType [])) then {GVAR(Medical_ItemList) = []};

[localize LSTRING(Medical), QFUNC(filterMedical)] call FUNC(addCustomFilter);
// If the player is a group leader and opens a subordinate's inventory or has a subordinate open the player's backpack, update name to correct unit
if (leader ACE_player == ACE_player && {(_unit in units ACE_player) || {(objectParent _container) isEqualTo ACE_player}}) then {
GVAR(unit) = _unit;
};
}] call CBA_fnc_addClassEventHandler;
61 changes: 29 additions & 32 deletions addons/inventory/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,53 @@

#include "XEH_PREP.hpp"

//item cache, see XEH_postInit.sqf
// Cache config
// Items in the inventory display can all use lb data to get their classname (exception: backpacks, handled separately)
private _allItems = ("getNumber (_x >> 'scope') > 0" configClasses (configFile >> "CfgWeapons"));
_allItems append ("getNumber (_x >> 'scope') > 0" configClasses (configFile >> "CfgGlasses"));
_allItems append ("getNumber (_x >> 'scope') == 2" configClasses (configFile >> "CfgMagazines"));
_allItems append ("getNumber (_x >> 'scope') > 0 && {getNumber (_x >> 'isBackpack') == 1}" configClasses (configFile >> "CfgVehicles"));
_allItems append ("getNumber (_x >> 'scope') > 0" configClasses (configFile >> "CfgMagazines"));

uiNamespace setVariable [QGVAR(ItemKeyCache), _allItems apply {
uiNamespace setVariable [QGVAR(itemKeyCache), compileFinal ((_allItems apply {configName _x}) createHashMapFromArray _allItems)];

// Backpacks in the inventory display can only be distinguished by their lb names and pictures, lb data returns ""
_allItems = "getNumber (_x >> 'scope') > 0 && {getNumber (_x >> 'isBackpack') == 1}" configClasses (configFile >> "CfgVehicles");

uiNamespace setVariable [QGVAR(backpackKeyCache), compileFinal createHashMapFromArray (_allItems apply {
private _displayName = getText (_x >> "displayName");
private _picture = getText (_x >> "picture");

// list box seems to delete the leading backslash
if (_picture select [0,1] == "\") then {
// List box seems to delete the leading backslash
if (_picture select [0, 1] == "\") then {
_picture = _picture select [1];
};
if (count _picture > 0 && !(_picture regexMatch ".*?\.paa")) then { // handle missing file extension
if (!fileExists (_picture + ".paa")) exitWith {};
_picture = _picture + ".paa";
};

[format ["%1:%2", _displayName, _picture], _x];
}];

// generate list of grenades
private _grenades_ItemList = [];

{
_grenades_ItemList append getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines");
} forEach getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles");

// make list case insensitive
_grenades_ItemList = _grenades_ItemList apply {toLower _x};
// Handle missing file extension, as inventory returns path with extension
if (count _picture > 0 && !(_picture regexMatch ".*?\.paa")) then {
if (!fileExists (_picture + ".paa")) exitWith {};
_picture = _picture + ".paa";
};

// filter duplicates
_grenades_ItemList = _grenades_ItemList arrayIntersect _grenades_ItemList;
// Listboxes store pictures as lowercase
[format ["%1:%2", _displayName, toLower _picture], _x]
})];

uiNamespace setVariable [QGVAR(Grenades_ItemList), _grenades_ItemList];
// Generate list of grenades
private _cfgThrow = configFile >> "CfgWeapons" >> "Throw";
private _grenadeList = createHashMap;

// generate list of medical items
private _medical_ItemList = ["FirstAidKit", "Medikit"];
{
_medical_ItemList append getArray (_x >> "items");
} forEach ("true" configClasses (configFile >> QEGVAR(medical_treatment,Actions)));
_grenadeList insert [true, (getArray (_cfgThrow >> _x >> "magazines")) apply {_x call EFUNC(common,getConfigName)}, []];
} forEach getArray (_cfgThrow >> "muzzles");

// remove all numbers from list
_medical_ItemList = _medical_ItemList select {_x isEqualType ""};
uiNamespace setVariable [QGVAR(grenadesItemList), compileFinal _grenadeList];

// make list case insensitive
_medical_ItemList = _medical_ItemList apply {toLower _x};
// Generate list of medical items
private _medicalList = QUOTE(getNumber (_x >> 'scope') > 0 && {getNumber (_x >> 'ItemInfo' >> 'type') in [ARR_2(TYPE_FIRST_AID_KIT,TYPE_MEDIKIT)]}) configClasses (configFile >> "CfgWeapons");

// filter duplicates
_medical_ItemList = _medical_ItemList arrayIntersect _medical_ItemList;
_medicalList = _medicalList apply {configName _x};

uiNamespace setVariable [QGVAR(Medical_ItemList), _medical_ItemList];
uiNamespace setVariable [QGVAR(medicalItemList), compileFinal (_medicalList createHashMapFromArray [])];
6 changes: 4 additions & 2 deletions addons/inventory/functions/fnc_addCustomFilter.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
* None
*
* Example:
* ["displayname", "filter"] call ACE_inventory_fnc_addCustomFilter
* ["displayname", "filter"] call ace_inventory_fnc_addCustomFilter
*
* Public: No
*/

params [["_filterName", "ERROR: No Name", [""]], ["_fncName", "", [""]]];
params [["_filterName", "", [""]], ["_fncName", "", [""]]];

if (_filterName == "") exitWith {};

GVAR(customFilters) pushBack [_filterName, _fncName];
5 changes: 2 additions & 3 deletions addons/inventory/functions/fnc_currentItemListBox.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Currently selected item list box <CONTROL>
*
* Example:
* [DISPLAY] call ACE_inventory_fnc_currentItemListBox
* [DISPLAY] call ace_inventory_fnc_currentItemListBox
*
* Public: No
*/
Expand All @@ -27,7 +27,6 @@ scopeName "main";
if (ctrlShown _control) then {
_control breakOut "main";
};
false
} count [IDC_ITEMLIST_GROUND, IDC_ITEMLIST_SOLDIER, IDC_ITEMLIST_UNIFORM, IDC_ITEMLIST_VEST, IDC_ITEMLIST_BACKPACK];
} forEach [IDC_ITEMLIST_GROUND, IDC_ITEMLIST_SOLDIER, IDC_ITEMLIST_UNIFORM, IDC_ITEMLIST_VEST, IDC_ITEMLIST_BACKPACK];

controlNull
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@
* None
*
* Example:
* [DISPLAY] call ACE_movement_fnc_inventoryDisplayLoad
* [DISPLAY] call ace_inventory_fnc_displayNameWeight
*
* Public: No
*/

params ["_display"];

// forces player name control to display irrespective of isStreamFriendlyUIEnabled
// Forces player name control to display irrespective of isStreamFriendlyUIEnabled
(_display displayCtrl 111) ctrlShow true;

private _fnc_update = {
params ["_display"];

private _control = _display displayCtrl 111;
private _format = ["%1 - %2 %3 (%4)", "%2 %3 (%4)"] select isStreamFriendlyUIEnabled;

_control ctrlSetText format [_format,
[ACE_player, false, true] call EFUNC(common,getName),
localize ELSTRING(common,Weight),
[ACE_player] call EFUNC(common,getWeight),
[ACE_player, true] call EFUNC(common,getWeight)
[GVAR(unit), false, true] call EFUNC(common,getName),
LELSTRING(common,Weight),
GVAR(unit) call EFUNC(common,getWeight),
[GVAR(unit), true] call EFUNC(common,getWeight)
];
};

Expand Down
2 changes: 1 addition & 1 deletion addons/inventory/functions/fnc_filterBackpacks.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Item should appear in this list? <BOOL>
*
* Example:
* [CONFIG] call ACE_inventory_fnc_filterBackpacks
* [CONFIG] call ace_inventory_fnc_filterBackpacks
*
* Public: No
*/
Expand Down
4 changes: 2 additions & 2 deletions addons/inventory/functions/fnc_filterGrenades.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* Item should appear in this list? <BOOL>
*
* Example:
* [CONFIG] call ACE_inventory_fnc_filterGrenades
* [CONFIG] call ace_inventory_fnc_filterGrenades
*
* Public: No
*/

params ["_config"];

toLower configName _config in GVAR(Grenades_ItemList)
(configName _config) in (uiNamespace getVariable QGVAR(grenadesItemList))
2 changes: 1 addition & 1 deletion addons/inventory/functions/fnc_filterHeadgear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Item should appear in this list? <BOOL>
*
* Example:
* [CONFIG] call ACE_inventory_fnc_filterHeadgear
* [CONFIG] call ace_inventory_fnc_filterHeadgear
*
* Public: No
*/
Expand Down
7 changes: 5 additions & 2 deletions addons/inventory/functions/fnc_filterItems.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
* Item should appear in this list? <BOOL>
*
* Example:
* [CONFIG] call ACE_inventory_fnc_filterItems
* [CONFIG] call ace_inventory_fnc_filterItems
*
* Public: No
*/

params ["_config"];

!(getNumber (_config >> "ItemInfo" >> "type") in [TYPE_UNIFORM, TYPE_VESTS, TYPE_HEADGEAR]) && {!(_this call FUNC(filterBackpacks))}
!(_this call FUNC(filterMedical)) &&
{!(_this call FUNC(filterBackpacks))} &&
{!(_this call FUNC(filterHeadgear))} &&
{!(getNumber (_config >> "ItemInfo" >> "type") in [TYPE_UNIFORM, TYPE_VEST])}
Loading

0 comments on commit 7f998c3

Please sign in to comment.