diff --git a/addons/filters/XEH_postInit.sqf b/addons/filters/XEH_postInit.sqf index 5769f1fe13..d0e3fb042a 100644 --- a/addons/filters/XEH_postInit.sqf +++ b/addons/filters/XEH_postInit.sqf @@ -2,31 +2,49 @@ if (!hasInterface) exitWith {}; -disableSerialization; - GVAR(customFilters) = []; GVAR(selectedFilterIndex) = -1; ["inventoryDisplayLoaded", {_this call FUNC(inventoryDisplayLoaded)}] call EFUNC(common,addEventHandler); // add custom filters -DFUNC(filterBackpacks) = { - params ["_config"]; - getNumber (_config >> "isBackpack") == 1 -}; + +// generate list of grenades +GVAR(Grenades_ItemList) = []; + +{ + GVAR(Grenades_ItemList) append getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"); + false +} count getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles"); + +// make list case insensitive +GVAR(Grenades_ItemList) = [GVAR(Grenades_ItemList), {toLower _this}] call EFUNC(common,map); + +// filter duplicates +GVAR(Grenades_ItemList) = GVAR(Grenades_ItemList) arrayIntersect GVAR(Grenades_ItemList); + +[localize LSTRING(Grenades), QFUNC(filterGrenades)] call FUNC(addCustomFilter); [localize LSTRING(Backpacks), QFUNC(filterBackpacks)] call FUNC(addCustomFilter); - -DFUNC(filterUniforms) = { - params ["_config"]; - getNumber (_config >> "ItemInfo" >> "type") == 801 -}; - [localize LSTRING(Uniforms), QFUNC(filterUniforms)] call FUNC(addCustomFilter); - -DFUNC(filterVests) = { - params ["_config"]; - getNumber (_config >> "ItemInfo" >> "type") == 701 -}; - [localize LSTRING(Vests), QFUNC(filterVests)] call FUNC(addCustomFilter); +[localize LSTRING(Headgear), QFUNC(filterHeadgear)] call FUNC(addCustomFilter); + +// generate list of medical items +GVAR(Medical_ItemList) = []; + +{ + GVAR(Medical_ItemList) append getArray (_x >> "items"); + false +} count ( + ("true" configClasses (configFile >> QEGVAR(Medical,Actions) >> "Basic")) + + ("true" configClasses (configFile >> QEGVAR(Medical,Actions) >> "Advanced")) +); + +// make list case insensitive +GVAR(Medical_ItemList) = [GVAR(Medical_ItemList), {if (_this isEqualType "") then {toLower _this}}] call EFUNC(common,map); + +// filter duplicates +GVAR(Medical_ItemList) = GVAR(Medical_ItemList) arrayIntersect GVAR(Medical_ItemList); + +[localize LSTRING(Medical), QFUNC(filterMedical)] call FUNC(addCustomFilter); diff --git a/addons/filters/XEH_preInit.sqf b/addons/filters/XEH_preInit.sqf index df7b74d8e2..2b0fa93678 100644 --- a/addons/filters/XEH_preInit.sqf +++ b/addons/filters/XEH_preInit.sqf @@ -9,19 +9,27 @@ PREP(inventoryDisplayLoaded); PREP(onLBSelChanged); // 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 !(uiNamespace getVariable [QGVAR(configCached), false]) then { + private _fnc_addToCache = { + private _displayName = getText (_x >> "displayName"); + private _picture = getText (_x >> "picture"); + + // list box seems to delete the leading backslash + if (_picture select [0,1] == "\") then { + _picture = _picture select [1]; + }; + + uiNamespace setVariable [format [QGVAR(ItemKey:%1:%2), _displayName, _picture], _x]; + }; + // weapons, magazines, items { - if (getNumber (_x >> "scope") > 0) then { - private _displayName = getText (_x >> "displayName"); - private _picture = getText (_x >> "picture"); - - if (_picture select [0,1] == "\") then { - _picture = _picture select [1]; - }; - - uiNamespace setVariable [format [QGVAR(ItemKey:%1), _displayName, _picture], _x]; - }; + if (getNumber (_x >> "scope") > 0) then _fnc_addToCache; false } count ( ("true" configClasses (configFile >> "CfgWeapons")) + @@ -31,20 +39,18 @@ if !(uiNamespace getVariable [QGVAR(configCached), false]) then { // backpacks { - if (getNumber (_x >> "scope") > 0 && {getNumber (_x >> "isBackpack") == 1}) then { - private _displayName = getText (_x >> "displayName"); - private _picture = getText (_x >> "picture"); - - if (_picture select [0,1] == "\") then { - _picture = _picture select [1]; - }; - - uiNamespace setVariable [format [QGVAR(ItemKey:%1), _displayName, _picture], _x]; - }; + if (getNumber (_x >> "scope") > 0 && {getNumber (_x >> "isBackpack") == 1}) then _fnc_addToCache; false } count ("true" configClasses (configFile >> "CfgVehicles")); uiNamespace setVariable [QGVAR(configCached), true]; }; +PREP(filterHeadgear); +PREP(filterUniforms); +PREP(filterVests); +PREP(filterBackpacks); +PREP(filterGrenades); +PREP(filterMedical); + ADDON = true; diff --git a/addons/filters/functions/fnc_addCustomFilter.sqf b/addons/filters/functions/fnc_addCustomFilter.sqf index 6c9c9b876e..44e43bdbf0 100644 --- a/addons/filters/functions/fnc_addCustomFilter.sqf +++ b/addons/filters/functions/fnc_addCustomFilter.sqf @@ -1,4 +1,17 @@ -// by commy2 +/* + * Author: commy2 + * Adds a custom filter list to the inventory display. + * Functions are here as strings, because list boxes can only store numbers and strings. + * + * Arguments: + * 0: Localized filter display name + * 1: Filter function name + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" params [["_filterName", "ERROR: No Name", [""]], ["_fncName", "", [""]]]; diff --git a/addons/filters/functions/fnc_currentItemListBox.sqf b/addons/filters/functions/fnc_currentItemListBox.sqf index e284cd9a5f..1f1b528e93 100644 --- a/addons/filters/functions/fnc_currentItemListBox.sqf +++ b/addons/filters/functions/fnc_currentItemListBox.sqf @@ -1,4 +1,17 @@ -// by commy2 +/* + * Author: commy2 + * Returns the current item list box of given inventory display. + * These can be Ground, Soldier, Uniform, Backpack or Vest. + * Can also be Weapon since 1.52, but that apparently uses one of the above. + * + * Arguments: + * 0: Inventory display + * + * Return Value: + * Currently selected item list box + * + * Public: No + */ #include "script_component.hpp" params ["_display"]; @@ -9,9 +22,9 @@ scopeName "main"; private _control = _display displayCtrl _x; if (ctrlShown _control) then { - _control breakOut "main" + _control breakOut "main"; }; false -} count [632, 640, 633, 638, 619]; +} count [IDC_ITEMLIST_GROUND, IDC_ITEMLIST_SOLDIER, IDC_ITEMLIST_UNIFORM, IDC_ITEMLIST_VEST, IDC_ITEMLIST_BACKPACK]; -1 diff --git a/addons/filters/functions/fnc_filterBackpacks.sqf b/addons/filters/functions/fnc_filterBackpacks.sqf new file mode 100644 index 0000000000..9b629de66f --- /dev/null +++ b/addons/filters/functions/fnc_filterBackpacks.sqf @@ -0,0 +1,17 @@ +/* + * Author: commy2 + * Filter condition for the Backpacks filter list + * + * Arguments: + * 0: Item config entry + * + * Return Value: + * Item should appear in this list? + * + * Public: No + */ +#include "script_component.hpp" + +params ["_config"]; + +getNumber (_config >> "isBackpack") == 1 diff --git a/addons/filters/functions/fnc_filterGrenades.sqf b/addons/filters/functions/fnc_filterGrenades.sqf new file mode 100644 index 0000000000..0acfbcaa2c --- /dev/null +++ b/addons/filters/functions/fnc_filterGrenades.sqf @@ -0,0 +1,17 @@ +/* + * Author: commy2 + * Filter condition for the Grenades filter list + * + * Arguments: + * 0: Item config entry + * + * Return Value: + * Item should appear in this list? + * + * Public: No + */ +#include "script_component.hpp" + +params ["_config"]; + +toLower configName _config in GVAR(Grenades_ItemList) diff --git a/addons/filters/functions/fnc_filterHeadgear.sqf b/addons/filters/functions/fnc_filterHeadgear.sqf new file mode 100644 index 0000000000..056406a3d1 --- /dev/null +++ b/addons/filters/functions/fnc_filterHeadgear.sqf @@ -0,0 +1,17 @@ +/* + * Author: commy2 + * Filter condition for the Headgear filter list + * + * Arguments: + * 0: Item config entry + * + * Return Value: + * Item should appear in this list? + * + * Public: No + */ +#include "script_component.hpp" + +params ["_config"]; + +getNumber (_config >> "ItemInfo" >> "type") in [TYPE_HEADGEAR, TYPE_HMD] || {isClass (configFile >> "CfgGlasses" >> configName _config)} diff --git a/addons/filters/functions/fnc_filterMedical.sqf b/addons/filters/functions/fnc_filterMedical.sqf new file mode 100644 index 0000000000..397be50f06 --- /dev/null +++ b/addons/filters/functions/fnc_filterMedical.sqf @@ -0,0 +1,17 @@ +/* + * Author: commy2 + * Filter condition for the Medical filter list + * + * Arguments: + * 0: Item config entry + * + * Return Value: + * Item should appear in this list? + * + * Public: No + */ +#include "script_component.hpp" + +params ["_config"]; + +toLower configName _config in GVAR(Medical_ItemList) diff --git a/addons/filters/functions/fnc_filterUniforms.sqf b/addons/filters/functions/fnc_filterUniforms.sqf new file mode 100644 index 0000000000..4c135dfa88 --- /dev/null +++ b/addons/filters/functions/fnc_filterUniforms.sqf @@ -0,0 +1,17 @@ +/* + * Author: commy2 + * Filter condition for the Uniforms filter list + * + * Arguments: + * 0: Item config entry + * + * Return Value: + * Item should appear in this list? + * + * Public: No + */ +#include "script_component.hpp" + +params ["_config"]; + +getNumber (_config >> "ItemInfo" >> "type") == TYPE_UNIFORM diff --git a/addons/filters/functions/fnc_filterVests.sqf b/addons/filters/functions/fnc_filterVests.sqf new file mode 100644 index 0000000000..646e23d04d --- /dev/null +++ b/addons/filters/functions/fnc_filterVests.sqf @@ -0,0 +1,17 @@ +/* + * Author: commy2 + * Filter condition for the Vests filter list + * + * Arguments: + * 0: Item config entry + * + * Return Value: + * Item should appear in this list? + * + * Public: No + */ +#include "script_component.hpp" + +params ["_config"]; + +getNumber (_config >> "ItemInfo" >> "type") == TYPE_VEST diff --git a/addons/filters/functions/fnc_forceItemListUpdate.sqf b/addons/filters/functions/fnc_forceItemListUpdate.sqf index 77d9bd3449..89142b99ff 100644 --- a/addons/filters/functions/fnc_forceItemListUpdate.sqf +++ b/addons/filters/functions/fnc_forceItemListUpdate.sqf @@ -1,4 +1,15 @@ -// by commy2 +/* + * Author: commy2 + * Updates item list and removes every entry that does not fit in the currently selected filter list. + * + * Arguments: + * 0: Inventory display + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" disableSerialization; @@ -6,14 +17,14 @@ params ["_display"]; private _index = GVAR(selectedFilterIndex); private _itemList = _display call FUNC(currentItemListBox); -private _filterFunction = missionNamespace getVariable ((_display displayCtrl 6554) lbData _index); +private _filterFunction = missionNamespace getVariable ((_display displayCtrl IDC_FILTERLISTS) lbData _index); if (_filterFunction isEqualType {}) then { private _i = 0; while {_i < lbSize _itemList} do { private _config = uiNamespace getVariable [ - format [QGVAR(ItemKey:%1), _itemList lbText _i, _itemList lbPicture _i], + format [QGVAR(ItemKey:%1:%2), _itemList lbText _i, _itemList lbPicture _i], configNull ]; diff --git a/addons/filters/functions/fnc_inventoryDisplayLoaded.sqf b/addons/filters/functions/fnc_inventoryDisplayLoaded.sqf index 8c4433197b..3cb15853d3 100644 --- a/addons/filters/functions/fnc_inventoryDisplayLoaded.sqf +++ b/addons/filters/functions/fnc_inventoryDisplayLoaded.sqf @@ -1,10 +1,21 @@ -// by commy2 +/* + * Author: commy2 + * Executed every time an inventory display is opened. + * + * Arguments: + * 0: Inventory display + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" disableSerialization; params ["_display"]; -private _filter = _display displayCtrl 6554; +private _filter = _display displayCtrl IDC_FILTERLISTS; // engine defined behaviour is the following: // lb value, data and text don't matter, only the index. @@ -39,7 +50,7 @@ _filter ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(onLBSelChanged)}]; _filter lbSetCurSel _index; }, [_filter]] call EFUNC(common,execNextFrame); -// monitor changes that can happen and force our upate +// monitor changes that can happen and force our update private _dummyControl = _display ctrlCreate ["RscMapControl", -1]; _dummyControl ctrlSetPosition [0,0,0,0]; @@ -53,9 +64,9 @@ _dummyControl ctrlAddEventHandler ["Draw", { private _itemList = _display call FUNC(currentItemListBox); - // monitoring is done by setting a lb value. These are unused here and are reset every time the list box updates. 127 is just a random constant number. - if (_itemList lbValue 0 != 127) then { + // monitoring is done by setting a lb value. These are unused here and are reset every time the list box updates. + if (_itemList lbValue 0 != DUMMY_VALUE) then { _display call FUNC(forceItemListUpdate); - _itemList lbSetValue [0, 127]; + _itemList lbSetValue [0, DUMMY_VALUE]; }; }]; diff --git a/addons/filters/functions/fnc_onLBSelChanged.sqf b/addons/filters/functions/fnc_onLBSelChanged.sqf index a5e020f78c..61e4b12b10 100644 --- a/addons/filters/functions/fnc_onLBSelChanged.sqf +++ b/addons/filters/functions/fnc_onLBSelChanged.sqf @@ -1,4 +1,17 @@ -// by commy2 +/* + * Author: commy2 + * Executed when the filter list box is changed. + * Sets new filter list index. + * + * Arguments: + * 0: Filter list box + * 1: Filter list index + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" disableSerialization; diff --git a/addons/filters/script_component.hpp b/addons/filters/script_component.hpp index 27873602d3..e96072de4b 100644 --- a/addons/filters/script_component.hpp +++ b/addons/filters/script_component.hpp @@ -9,4 +9,13 @@ #define DEBUG_SETTINGS DEBUG_ENABLED_FILTERS #endif -#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file +#include "\z\ace\addons\main\script_macros.hpp" + +#define IDC_FILTERLISTS 6554 +#define IDC_ITEMLIST_GROUND 632 +#define IDC_ITEMLIST_SOLDIER 640 +#define IDC_ITEMLIST_UNIFORM 633 +#define IDC_ITEMLIST_VEST 638 +#define IDC_ITEMLIST_BACKPACK 619 + +#define DUMMY_VALUE 127 diff --git a/addons/filters/stringtable.xml b/addons/filters/stringtable.xml index 75b7101da3..a7f9e30ec6 100644 --- a/addons/filters/stringtable.xml +++ b/addons/filters/stringtable.xml @@ -7,7 +7,7 @@ Headgear - Helme + Kopfbedeckungen Glasses @@ -25,5 +25,9 @@ Grenades Granaten + + Medical + Sanimaterial + diff --git a/addons/main/script_macros.hpp b/addons/main/script_macros.hpp index a65d126110..0864fcdfbe 100644 --- a/addons/main/script_macros.hpp +++ b/addons/main/script_macros.hpp @@ -38,25 +38,48 @@ #define MACRO_ADDWEAPON(WEAPON,COUNT) class _xx_##WEAPON { \ - weapon = #WEAPON; \ - count = COUNT; \ + weapon = #WEAPON; \ + count = COUNT; \ } #define MACRO_ADDITEM(ITEM,COUNT) class _xx_##ITEM { \ - name = #ITEM; \ - count = COUNT; \ + name = #ITEM; \ + count = COUNT; \ } #define MACRO_ADDMAGAZINE(MAGAZINE,COUNT) class _xx_##MAGAZINE { \ - magazine = #MAGAZINE; \ - count = COUNT; \ + magazine = #MAGAZINE; \ + count = COUNT; \ } #define MACRO_ADDBACKPACK(BACKPACK,COUNT) class _xx_##BACKPACK { \ - backpack = #BACKPACK; \ - count = COUNT; \ + backpack = #BACKPACK; \ + count = COUNT; \ } +// item types +#define TYPE_DEFAULT 0 +#define TYPE_MUZZLE 101 +#define TYPE_OPTICS 201 +#define TYPE_FLASHLIGHT 301 +#define TYPE_BIPOD 302 +#define TYPE_FIRST_AID_KIT 401 +#define TYPE_FINS 501 // not implemented +#define TYPE_BREATHING_BOMB 601 // not implemented +#define TYPE_NVG 602 +#define TYPE_GOGGLE 603 +#define TYPE_SCUBA 604 // not implemented +#define TYPE_HEADGEAR 605 +#define TYPE_FACTOR 607 +#define TYPE_RADIO 611 +#define TYPE_HMD 616 +#define TYPE_BINOCULAR 617 +#define TYPE_MEDIKIT 619 +#define TYPE_TOOLKIT 620 +#define TYPE_UAV_TERMINAL 621 +#define TYPE_VEST 701 +#define TYPE_UNIFORM 801 +#define TYPE_BACKPACK 901 #ifdef DISABLE_COMPILE_CACHE #define PREP(fncName) DFUNC(fncName) = compile preprocessFileLineNumbers QUOTE(PATHTOF(functions\DOUBLES(fnc,fncName).sqf))