From 68388bc97631b78c54af39def3773bd0c920e4ed Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 11 Dec 2015 01:02:15 +0100 Subject: [PATCH] add more filters to ammo boxes --- addons/filters/$PBOPREFIX$ | 1 + addons/filters/CfgEventHandlers.hpp | 12 ++++ addons/filters/XEH_postInit.sqf | 32 ++++++++++ addons/filters/XEH_preInit.sqf | 50 +++++++++++++++ addons/filters/config.cpp | 15 +++++ .../filters/functions/fnc_addCustomFilter.sqf | 6 ++ .../functions/fnc_currentItemListBox.sqf | 17 ++++++ .../functions/fnc_forceItemListUpdate.sqf | 29 +++++++++ .../functions/fnc_inventoryDisplayLoaded.sqf | 61 +++++++++++++++++++ .../filters/functions/fnc_onLBSelChanged.sqf | 14 +++++ addons/filters/functions/script_component.hpp | 1 + addons/filters/script_component.hpp | 12 ++++ addons/filters/stringtable.xml | 29 +++++++++ 13 files changed, 279 insertions(+) create mode 100644 addons/filters/$PBOPREFIX$ create mode 100644 addons/filters/CfgEventHandlers.hpp create mode 100644 addons/filters/XEH_postInit.sqf create mode 100644 addons/filters/XEH_preInit.sqf create mode 100644 addons/filters/config.cpp create mode 100644 addons/filters/functions/fnc_addCustomFilter.sqf create mode 100644 addons/filters/functions/fnc_currentItemListBox.sqf create mode 100644 addons/filters/functions/fnc_forceItemListUpdate.sqf create mode 100644 addons/filters/functions/fnc_inventoryDisplayLoaded.sqf create mode 100644 addons/filters/functions/fnc_onLBSelChanged.sqf create mode 100644 addons/filters/functions/script_component.hpp create mode 100644 addons/filters/script_component.hpp create mode 100644 addons/filters/stringtable.xml diff --git a/addons/filters/$PBOPREFIX$ b/addons/filters/$PBOPREFIX$ new file mode 100644 index 0000000000..06f96465a9 --- /dev/null +++ b/addons/filters/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\filters \ No newline at end of file diff --git a/addons/filters/CfgEventHandlers.hpp b/addons/filters/CfgEventHandlers.hpp new file mode 100644 index 0000000000..0cd959a047 --- /dev/null +++ b/addons/filters/CfgEventHandlers.hpp @@ -0,0 +1,12 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/filters/XEH_postInit.sqf b/addons/filters/XEH_postInit.sqf new file mode 100644 index 0000000000..5769f1fe13 --- /dev/null +++ b/addons/filters/XEH_postInit.sqf @@ -0,0 +1,32 @@ +#include "script_component.hpp" + +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 +}; + +[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); diff --git a/addons/filters/XEH_preInit.sqf b/addons/filters/XEH_preInit.sqf new file mode 100644 index 0000000000..df7b74d8e2 --- /dev/null +++ b/addons/filters/XEH_preInit.sqf @@ -0,0 +1,50 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP(addCustomFilter); +PREP(currentItemListBox); +PREP(forceItemListUpdate); +PREP(inventoryDisplayLoaded); +PREP(onLBSelChanged); + +// cache config +if !(uiNamespace getVariable [QGVAR(configCached), false]) then { + // 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]; + }; + false + } count ( + ("true" configClasses (configFile >> "CfgWeapons")) + + ("true" configClasses (configFile >> "CfgMagazines")) + + ("true" configClasses (configFile >> "CfgGlasses")) + ); + + // 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]; + }; + false + } count ("true" configClasses (configFile >> "CfgVehicles")); + + uiNamespace setVariable [QGVAR(configCached), true]; +}; + +ADDON = true; diff --git a/addons/filters/config.cpp b/addons/filters/config.cpp new file mode 100644 index 0000000000..a7b7bae6df --- /dev/null +++ b/addons/filters/config.cpp @@ -0,0 +1,15 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common"}; + author[] = {""}; + authorUrl = ""; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" diff --git a/addons/filters/functions/fnc_addCustomFilter.sqf b/addons/filters/functions/fnc_addCustomFilter.sqf new file mode 100644 index 0000000000..6c9c9b876e --- /dev/null +++ b/addons/filters/functions/fnc_addCustomFilter.sqf @@ -0,0 +1,6 @@ +// by commy2 +#include "script_component.hpp" + +params [["_filterName", "ERROR: No Name", [""]], ["_fncName", "", [""]]]; + +GVAR(customFilters) pushBack [_filterName, _fncName]; diff --git a/addons/filters/functions/fnc_currentItemListBox.sqf b/addons/filters/functions/fnc_currentItemListBox.sqf new file mode 100644 index 0000000000..e284cd9a5f --- /dev/null +++ b/addons/filters/functions/fnc_currentItemListBox.sqf @@ -0,0 +1,17 @@ +// by commy2 +#include "script_component.hpp" + +params ["_display"]; + +scopeName "main"; + +{ + private _control = _display displayCtrl _x; + + if (ctrlShown _control) then { + _control breakOut "main" + }; + false +} count [632, 640, 633, 638, 619]; + +-1 diff --git a/addons/filters/functions/fnc_forceItemListUpdate.sqf b/addons/filters/functions/fnc_forceItemListUpdate.sqf new file mode 100644 index 0000000000..77d9bd3449 --- /dev/null +++ b/addons/filters/functions/fnc_forceItemListUpdate.sqf @@ -0,0 +1,29 @@ +// by commy2 +#include "script_component.hpp" + +disableSerialization; +params ["_display"]; + +private _index = GVAR(selectedFilterIndex); +private _itemList = _display call FUNC(currentItemListBox); +private _filterFunction = missionNamespace getVariable ((_display displayCtrl 6554) 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], + configNull + ]; + + if (!isNull _config && {!(_config call _filterFunction)}) then { + _itemList lbDelete _i; + + // in case the filter function returns nil. Otherwise could lock up the game. + _i = _i - 1; + }; + + _i = _i + 1; + }; +}; diff --git a/addons/filters/functions/fnc_inventoryDisplayLoaded.sqf b/addons/filters/functions/fnc_inventoryDisplayLoaded.sqf new file mode 100644 index 0000000000..8c4433197b --- /dev/null +++ b/addons/filters/functions/fnc_inventoryDisplayLoaded.sqf @@ -0,0 +1,61 @@ +// by commy2 +#include "script_component.hpp" + +disableSerialization; +params ["_display"]; + +private _filter = _display displayCtrl 6554; + +// 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 +_filter ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(onLBSelChanged)}]; + +// 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). + private _index = lbSize _filter - 1; + private _nameAll = _filter lbText _index; + _filter lbDelete _index; + + // add our custom filters + { + _x params ["_name", "_fncName"]; + + _index = _filter lbAdd _name; + _filter lbSetData [_index, _fncName]; + + false + } count GVAR(customFilters); + + // readd "All" filter to last position and select it + _index = _filter lbAdd _nameAll; + _filter lbSetCurSel _index; +}, [_filter]] call EFUNC(common,execNextFrame); + +// monitor changes that can happen and force our upate +private _dummyControl = _display ctrlCreate ["RscMapControl", -1]; + +_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); + + // 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 { + _display call FUNC(forceItemListUpdate); + _itemList lbSetValue [0, 127]; + }; +}]; diff --git a/addons/filters/functions/fnc_onLBSelChanged.sqf b/addons/filters/functions/fnc_onLBSelChanged.sqf new file mode 100644 index 0000000000..a5e020f78c --- /dev/null +++ b/addons/filters/functions/fnc_onLBSelChanged.sqf @@ -0,0 +1,14 @@ +// by commy2 +#include "script_component.hpp" + +disableSerialization; +params ["_filter", "_index"]; + +GVAR(selectedFilterIndex) = _index; + +[{ + disableSerialization; + params ["_display"]; + + [_display] call FUNC(forceItemListUpdate); +}, [ctrlParent _filter]] call EFUNC(common,execNextFrame); diff --git a/addons/filters/functions/script_component.hpp b/addons/filters/functions/script_component.hpp new file mode 100644 index 0000000000..500275e357 --- /dev/null +++ b/addons/filters/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\filters\script_component.hpp" \ No newline at end of file diff --git a/addons/filters/script_component.hpp b/addons/filters/script_component.hpp new file mode 100644 index 0000000000..27873602d3 --- /dev/null +++ b/addons/filters/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT filters +#include "\z\ace\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_FILTERS + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_ENABLED_FILTERS + #define DEBUG_SETTINGS DEBUG_ENABLED_FILTERS +#endif + +#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file diff --git a/addons/filters/stringtable.xml b/addons/filters/stringtable.xml new file mode 100644 index 0000000000..75b7101da3 --- /dev/null +++ b/addons/filters/stringtable.xml @@ -0,0 +1,29 @@ + + + + + Backpacks + Rucksäcke + + + Headgear + Helme + + + Glasses + Brillen + + + Uniforms + Uniformen + + + Vests + Westen + + + Grenades + Granaten + + +