From 7f998c323402f52de5a360982018ecef1d57f334 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 6 Jan 2024 22:26:46 +0100 Subject: [PATCH] Inventory - Improve multiple aspects (#9706) Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> --- addons/inventory/CfgEventHandlers.hpp | 8 ++- addons/inventory/RscDisplayInventory.hpp | 28 ++++----- addons/inventory/XEH_PREP.hpp | 9 ++- addons/inventory/XEH_postInit.sqf | 53 ++++++++-------- addons/inventory/XEH_preStart.sqf | 63 +++++++++---------- .../functions/fnc_addCustomFilter.sqf | 6 +- .../functions/fnc_currentItemListBox.sqf | 5 +- .../functions/fnc_displayNameWeight.sqf} | 13 ++-- .../functions/fnc_filterBackpacks.sqf | 2 +- .../functions/fnc_filterGrenades.sqf | 4 +- .../functions/fnc_filterHeadgear.sqf | 2 +- .../inventory/functions/fnc_filterItems.sqf | 7 ++- .../functions/fnc_filterMagazines.sqf | 4 +- .../inventory/functions/fnc_filterMedical.sqf | 4 +- .../functions/fnc_filterUniforms.sqf | 2 +- .../inventory/functions/fnc_filterVests.sqf | 2 +- .../inventory/functions/fnc_filterWeapons.sqf | 2 +- .../functions/fnc_forceItemListUpdate.sqf | 31 ++++++--- .../functions/fnc_inventoryDisplayLoad.sqf | 39 +++++------- .../functions/fnc_onLBSelChanged.sqf | 11 ++-- addons/medical_treatment/XEH_preStart.sqf | 2 +- addons/movement/CfgEventHandlers.hpp | 6 -- addons/movement/XEH_PREP.hpp | 1 - 23 files changed, 155 insertions(+), 149 deletions(-) rename addons/{movement/functions/fnc_inventoryDisplayLoad.sqf => inventory/functions/fnc_displayNameWeight.sqf} (68%) diff --git a/addons/inventory/CfgEventHandlers.hpp b/addons/inventory/CfgEventHandlers.hpp index 5b92811746..f95adcb029 100644 --- a/addons/inventory/CfgEventHandlers.hpp +++ b/addons/inventory/CfgEventHandlers.hpp @@ -1,4 +1,3 @@ - class Extended_PreStart_EventHandlers { class ADDON { init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); @@ -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); }; }; diff --git a/addons/inventory/RscDisplayInventory.hpp b/addons/inventory/RscDisplayInventory.hpp index 3149000777..91e68f5fb1 100644 --- a/addons/inventory/RscDisplayInventory.hpp +++ b/addons/inventory/RscDisplayInventory.hpp @@ -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); @@ -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); }; @@ -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); @@ -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); }; @@ -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); diff --git a/addons/inventory/XEH_PREP.hpp b/addons/inventory/XEH_PREP.hpp index 7c58268e23..824ebf63d7 100644 --- a/addons/inventory/XEH_PREP.hpp +++ b/addons/inventory/XEH_PREP.hpp @@ -1,10 +1,6 @@ - PREP(addCustomFilter); PREP(currentItemListBox); -PREP(forceItemListUpdate); -PREP(inventoryDisplayLoad); -PREP(onLBSelChanged); - +PREP(displayNameWeight); PREP(filterWeapons); PREP(filterMagazines); PREP(filterItems); @@ -14,3 +10,6 @@ PREP(filterVests); PREP(filterBackpacks); PREP(filterGrenades); PREP(filterMedical); +PREP(forceItemListUpdate); +PREP(inventoryDisplayLoad); +PREP(onLBSelChanged); diff --git a/addons/inventory/XEH_postInit.sqf b/addons/inventory/XEH_postInit.sqf index c5dc6c48f6..a670a7bfd5 100644 --- a/addons/inventory/XEH_postInit.sqf +++ b/addons/inventory/XEH_postInit.sqf @@ -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 +// If medical_treatment is loaded, get its items +if (["ace_medical_treatment"] call EFUNC(common,isModLoaded)) then { + private _medicalList = +(uiNamespace getVariable [QGVAR(medicalItemList), createHashMap]); -GVAR(ItemKeyNamespace) = [] call CBA_fnc_createNamespace; -private _allItems = uiNamespace getVariable [QGVAR(ItemKeyCache), []]; //See XEH_preStart.sqf + _medicalList merge [uiNamespace getVariable [QEGVAR(medical_treatment,treatmentItems), createHashMap], true]; -// 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 [])); + 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; diff --git a/addons/inventory/XEH_preStart.sqf b/addons/inventory/XEH_preStart.sqf index 82dabefaec..faa0e1691e 100644 --- a/addons/inventory/XEH_preStart.sqf +++ b/addons/inventory/XEH_preStart.sqf @@ -2,18 +2,23 @@ #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 @@ -21,37 +26,29 @@ uiNamespace setVariable [QGVAR(ItemKeyCache), _allItems apply { _picture = _picture + ".paa"; }; - [format ["%1:%2", _displayName, _picture], _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"; + }; -// generate list of grenades -private _grenades_ItemList = []; + // Listboxes store pictures as lowercase + [format ["%1:%2", _displayName, toLower _picture], _x] +})]; + +// Generate list of grenades +private _cfgThrow = configFile >> "CfgWeapons" >> "Throw"; +private _grenadeList = createHashMap; { - _grenades_ItemList append getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"); -} forEach getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles"); + _grenadeList insert [true, (getArray (_cfgThrow >> _x >> "magazines")) apply {_x call EFUNC(common,getConfigName)}, []]; +} forEach getArray (_cfgThrow >> "muzzles"); -// make list case insensitive -_grenades_ItemList = _grenades_ItemList apply {toLower _x}; +uiNamespace setVariable [QGVAR(grenadesItemList), compileFinal _grenadeList]; -// filter duplicates -_grenades_ItemList = _grenades_ItemList arrayIntersect _grenades_ItemList; +// 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"); -uiNamespace setVariable [QGVAR(Grenades_ItemList), _grenades_ItemList]; +_medicalList = _medicalList apply {configName _x}; -// generate list of medical items -private _medical_ItemList = ["FirstAidKit", "Medikit"]; -{ - _medical_ItemList append getArray (_x >> "items"); -} forEach ("true" configClasses (configFile >> QEGVAR(medical_treatment,Actions))); - -// remove all numbers from list -_medical_ItemList = _medical_ItemList select {_x isEqualType ""}; - -// make list case insensitive -_medical_ItemList = _medical_ItemList apply {toLower _x}; - -// filter duplicates -_medical_ItemList = _medical_ItemList arrayIntersect _medical_ItemList; - -uiNamespace setVariable [QGVAR(Medical_ItemList), _medical_ItemList]; +uiNamespace setVariable [QGVAR(medicalItemList), compileFinal (_medicalList createHashMapFromArray [])]; diff --git a/addons/inventory/functions/fnc_addCustomFilter.sqf b/addons/inventory/functions/fnc_addCustomFilter.sqf index 6dd6e1f559..50820fa448 100644 --- a/addons/inventory/functions/fnc_addCustomFilter.sqf +++ b/addons/inventory/functions/fnc_addCustomFilter.sqf @@ -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]; diff --git a/addons/inventory/functions/fnc_currentItemListBox.sqf b/addons/inventory/functions/fnc_currentItemListBox.sqf index b3e5ce40b8..1546e8a509 100644 --- a/addons/inventory/functions/fnc_currentItemListBox.sqf +++ b/addons/inventory/functions/fnc_currentItemListBox.sqf @@ -12,7 +12,7 @@ * Currently selected item list box * * Example: - * [DISPLAY] call ACE_inventory_fnc_currentItemListBox + * [DISPLAY] call ace_inventory_fnc_currentItemListBox * * Public: No */ @@ -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 diff --git a/addons/movement/functions/fnc_inventoryDisplayLoad.sqf b/addons/inventory/functions/fnc_displayNameWeight.sqf similarity index 68% rename from addons/movement/functions/fnc_inventoryDisplayLoad.sqf rename to addons/inventory/functions/fnc_displayNameWeight.sqf index 95299a3b34..c480593d85 100644 --- a/addons/movement/functions/fnc_inventoryDisplayLoad.sqf +++ b/addons/inventory/functions/fnc_displayNameWeight.sqf @@ -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) ]; }; diff --git a/addons/inventory/functions/fnc_filterBackpacks.sqf b/addons/inventory/functions/fnc_filterBackpacks.sqf index 6cb94f3d1c..db1edd9756 100644 --- a/addons/inventory/functions/fnc_filterBackpacks.sqf +++ b/addons/inventory/functions/fnc_filterBackpacks.sqf @@ -10,7 +10,7 @@ * Item should appear in this list? * * Example: - * [CONFIG] call ACE_inventory_fnc_filterBackpacks + * [CONFIG] call ace_inventory_fnc_filterBackpacks * * Public: No */ diff --git a/addons/inventory/functions/fnc_filterGrenades.sqf b/addons/inventory/functions/fnc_filterGrenades.sqf index 6d2b813ae4..7e871699b8 100644 --- a/addons/inventory/functions/fnc_filterGrenades.sqf +++ b/addons/inventory/functions/fnc_filterGrenades.sqf @@ -10,11 +10,11 @@ * Item should appear in this list? * * 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)) diff --git a/addons/inventory/functions/fnc_filterHeadgear.sqf b/addons/inventory/functions/fnc_filterHeadgear.sqf index 134a4fc45f..010c33040f 100644 --- a/addons/inventory/functions/fnc_filterHeadgear.sqf +++ b/addons/inventory/functions/fnc_filterHeadgear.sqf @@ -10,7 +10,7 @@ * Item should appear in this list? * * Example: - * [CONFIG] call ACE_inventory_fnc_filterHeadgear + * [CONFIG] call ace_inventory_fnc_filterHeadgear * * Public: No */ diff --git a/addons/inventory/functions/fnc_filterItems.sqf b/addons/inventory/functions/fnc_filterItems.sqf index 0bdb18310f..a3c2567233 100644 --- a/addons/inventory/functions/fnc_filterItems.sqf +++ b/addons/inventory/functions/fnc_filterItems.sqf @@ -10,11 +10,14 @@ * Item should appear in this list? * * 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])} diff --git a/addons/inventory/functions/fnc_filterMagazines.sqf b/addons/inventory/functions/fnc_filterMagazines.sqf index 4b7747c5a8..e6d9237c21 100644 --- a/addons/inventory/functions/fnc_filterMagazines.sqf +++ b/addons/inventory/functions/fnc_filterMagazines.sqf @@ -10,9 +10,9 @@ * Item should appear in this list? * * Example: - * [CONFIG] call ACE_inventory_fnc_filterMagazines + * [CONFIG] call ace_inventory_fnc_filterMagazines * * Public: No */ -!(_this call FUNC(filterBackpacks)) && {!(_this call FUNC(filterGrenades))} +!(_this call FUNC(filterGrenades)) && {!(_this call FUNC(filterBackpacks))} diff --git a/addons/inventory/functions/fnc_filterMedical.sqf b/addons/inventory/functions/fnc_filterMedical.sqf index ec44ba2a76..73cfdbdffb 100644 --- a/addons/inventory/functions/fnc_filterMedical.sqf +++ b/addons/inventory/functions/fnc_filterMedical.sqf @@ -10,11 +10,11 @@ * Item should appear in this list? * * Example: - * [CONFIG] call ACE_inventory_fnc_filterMedical + * [CONFIG] call ace_inventory_fnc_filterMedical * * Public: No */ params ["_config"]; -toLower configName _config in GVAR(Medical_ItemList) +(configName _config) in GVAR(medicalItemList) diff --git a/addons/inventory/functions/fnc_filterUniforms.sqf b/addons/inventory/functions/fnc_filterUniforms.sqf index dc7d4e9287..b627475038 100644 --- a/addons/inventory/functions/fnc_filterUniforms.sqf +++ b/addons/inventory/functions/fnc_filterUniforms.sqf @@ -10,7 +10,7 @@ * Item should appear in this list? * * Example: - * [CONFIG] call ACE_inventory_fnc_filterUniforms + * [CONFIG] call ace_inventory_fnc_filterUniforms * * Public: No */ diff --git a/addons/inventory/functions/fnc_filterVests.sqf b/addons/inventory/functions/fnc_filterVests.sqf index 439d826390..2bb2af9ef4 100644 --- a/addons/inventory/functions/fnc_filterVests.sqf +++ b/addons/inventory/functions/fnc_filterVests.sqf @@ -10,7 +10,7 @@ * Item should appear in this list? * * Example: - * [CONFIG] call ACE_inventory_fnc_filterVests + * [CONFIG] call ace_inventory_fnc_filterVests * * Public: No */ diff --git a/addons/inventory/functions/fnc_filterWeapons.sqf b/addons/inventory/functions/fnc_filterWeapons.sqf index 2addf83665..db4d402099 100644 --- a/addons/inventory/functions/fnc_filterWeapons.sqf +++ b/addons/inventory/functions/fnc_filterWeapons.sqf @@ -10,7 +10,7 @@ * Item should appear in this list? * * Example: - * [CONFIG] call ACE_inventory_fnc_filterWeapons + * [CONFIG] call ace_inventory_fnc_filterWeapons * * Public: No */ diff --git a/addons/inventory/functions/fnc_forceItemListUpdate.sqf b/addons/inventory/functions/fnc_forceItemListUpdate.sqf index a806326677..fb8f09b5c8 100644 --- a/addons/inventory/functions/fnc_forceItemListUpdate.sqf +++ b/addons/inventory/functions/fnc_forceItemListUpdate.sqf @@ -10,23 +10,38 @@ * None * * Example: - * [DISPLAY] call ACE_inventory_fnc_forceitemListUpdate + * [DISPLAY] call ace_inventory_fnc_forceItemListUpdate * * Public: No */ disableSerialization; + params ["_display"]; +// Get the appropriate filter +private _filterFunction = missionNamespace getVariable [(_display displayCtrl IDC_FILTERLISTS) lbData GVAR(selectedFilterIndex), ""]; + +if !(_filterFunction isEqualType {}) exitWith {}; + private _itemList = _display call FUNC(currentItemListBox); -private _filterFunction = missionNamespace getVariable ((_display displayCtrl IDC_FILTERLISTS) lbData GVAR(selectedFilterIndex)); +private _itemKeyCache = uiNamespace getVariable QGVAR(itemKeyCache); +private _backpackKeyCache = uiNamespace getVariable QGVAR(backpackKeyCache); +private _config = configNull; -if (_filterFunction isEqualType {}) then { - for "_i" from (lbSize _itemList) - 1 to 0 step -1 do { - private _config = GVAR(ItemKeyNamespace) getVariable format ["%1:%2", _itemList lbText _i, _itemList lbPicture _i]; +for "_i" from (lbSize _itemList) to 0 step -1 do { + // All items have their classnames in lbData, except backpacks + _className = _itemList lbData _i; - if (!isNil "_config" && {!(_config call _filterFunction)}) then { - _itemList lbDelete _i; - }; + _config = if (_className != "") then { + _itemKeyCache get _className + } else { + // Backpack are gotten with their display name and inventory icon + _backpackKeyCache get format ["%1:%2", _itemList lbText _i, _itemList lbPicture _i] + }; + + // If item is valid and doesn't match the current filter, remove it + if (!isNil "_config" && {!(_config call _filterFunction)}) then { + _itemList lbDelete _i; }; }; diff --git a/addons/inventory/functions/fnc_inventoryDisplayLoad.sqf b/addons/inventory/functions/fnc_inventoryDisplayLoad.sqf index ca9f7a5343..3e70bbd8d9 100644 --- a/addons/inventory/functions/fnc_inventoryDisplayLoad.sqf +++ b/addons/inventory/functions/fnc_inventoryDisplayLoad.sqf @@ -10,40 +10,42 @@ * None * * Example: - * [DISPLAY] call ACE_inventory_fnc_inventoryDisplayLoad + * [DISPLAY] call ace_inventory_fnc_inventoryDisplayLoad * * Public: No */ disableSerialization; + params ["_display"]; private _filter = _display displayCtrl IDC_FILTERLISTS; -// engine defined behaviour is the following: +// Engine defined behaviour is the following: // lb value, data and text don't matter, only the index. -// the first three indecies are hard coded: 0 - weapons , 1 - magazines, 2 - items -// all of them show backpacks, because BI -// all other indecies show everything, so all we have to do is delete stuff we dont like +// The first three indecies are hard coded: 0 - weapons , 1 - magazines, 2 - items +// All of them show backpacks, because BI +// All other indecies show everything, so all we have to do is delete stuff we don't like _filter ctrlAddEventHandler ["LBSelChanged", LINKFUNC(onLBSelChanged)]; -// have to add these a frame later, because this event happens before the engine adds the default filters +// Have to add these a frame later, because this event happens before the engine adds the default filters [{ disableSerialization; + params ["_filter"]; - // remove "All", so we can push it to the back later. - // to keep localization we can keep the lbText (displayed name). + // Remove "All", so we can push it to the back later + // To keep localization we keep the lbText (displayed name) private _index = lbSize _filter - 1; private _nameAll = _filter lbText _index; _filter lbDelete _index; - // add additional filter functions to the default filters. These remove backpacks etc. + // Add additional filter functions to the default filters. These remove backpacks etc. _filter lbSetData [0, QFUNC(filterWeapons)]; _filter lbSetData [1, QFUNC(filterMagazines)]; _filter lbSetData [2, QFUNC(filterItems)]; - // add our custom filters + // Add our custom filters { _x params ["_name", "_fncName"]; @@ -51,24 +53,17 @@ _filter ctrlAddEventHandler ["LBSelChanged", LINKFUNC(onLBSelChanged)]; _filter lbSetData [_index, _fncName]; } forEach GVAR(customFilters); - // readd "All" filter to last position and select it + // Readd "All" filter to last position and select it _index = _filter lbAdd _nameAll; _filter lbSetCurSel _index; -}, [_filter]] call CBA_fnc_execNextFrame; +}, _filter] call CBA_fnc_execNextFrame; -// monitor changes that can happen and force our update +// Monitor changes that can happen and force our update private _dummyControl = _display ctrlCreate ["RscMapControl", -1]; -_dummyControl ctrlSetPosition [0,0,0,0]; +_dummyControl ctrlSetPosition [0, 0, 0, 0]; _dummyControl ctrlCommit 0; _dummyControl ctrlAddEventHandler ["Draw", { - disableSerialization; - params ["_dummyControl"]; - - private _display = ctrlParent _dummyControl; - - private _itemList = _display call FUNC(currentItemListBox); - - _display call FUNC(forceItemListUpdate); + (ctrlParent (_this select 0)) call FUNC(forceItemListUpdate); }]; diff --git a/addons/inventory/functions/fnc_onLBSelChanged.sqf b/addons/inventory/functions/fnc_onLBSelChanged.sqf index 6fbc7020c0..a2316dc4b6 100644 --- a/addons/inventory/functions/fnc_onLBSelChanged.sqf +++ b/addons/inventory/functions/fnc_onLBSelChanged.sqf @@ -12,19 +12,16 @@ * None * * Example: - * [CONTROL, 5] call ACE_inventory_fnc_onLBSelChanged + * [CONTROL, 5] call ace_inventory_fnc_onLBSelChanged * * Public: No */ disableSerialization; + params ["_filter", "_index"]; GVAR(selectedFilterIndex) = _index; -[{ - disableSerialization; - params ["_display"]; - - [_display] call FUNC(forceItemListUpdate); -}, [ctrlParent _filter]] call CBA_fnc_execNextFrame; +// Force update +[LINKFUNC(forceItemListUpdate), ctrlParent _filter] call CBA_fnc_execNextFrame; diff --git a/addons/medical_treatment/XEH_preStart.sqf b/addons/medical_treatment/XEH_preStart.sqf index 27f8f2d9c2..420bffaf71 100644 --- a/addons/medical_treatment/XEH_preStart.sqf +++ b/addons/medical_treatment/XEH_preStart.sqf @@ -2,4 +2,4 @@ #include "XEH_PREP.hpp" -call FUNC(scanMedicalItems) +call FUNC(scanMedicalItems); diff --git a/addons/movement/CfgEventHandlers.hpp b/addons/movement/CfgEventHandlers.hpp index 2608d0260b..f6503c2479 100644 --- a/addons/movement/CfgEventHandlers.hpp +++ b/addons/movement/CfgEventHandlers.hpp @@ -15,9 +15,3 @@ class Extended_PostInit_EventHandlers { init = QUOTE(call COMPILE_SCRIPT(XEH_postInit)); }; }; - -class Extended_DisplayLoad_EventHandlers { - class RscDisplayInventory { - ADDON = QUOTE(_this call FUNC(inventoryDisplayLoad)); - }; -}; diff --git a/addons/movement/XEH_PREP.hpp b/addons/movement/XEH_PREP.hpp index ceafa7f5dc..36fe97880d 100644 --- a/addons/movement/XEH_PREP.hpp +++ b/addons/movement/XEH_PREP.hpp @@ -3,4 +3,3 @@ PREP(canClimb); PREP(climb); PREP(handleClimb); PREP(handleVirtualMass); -PREP(inventoryDisplayLoad);