add more filters to ammo boxes

This commit is contained in:
commy2 2015-12-11 01:02:15 +01:00
parent f0642950e3
commit 68388bc976
13 changed files with 279 additions and 0 deletions

View File

@ -0,0 +1 @@
z\ace\addons\filters

View File

@ -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));
};
};

View File

@ -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);

View File

@ -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;

15
addons/filters/config.cpp Normal file
View File

@ -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"

View File

@ -0,0 +1,6 @@
// by commy2
#include "script_component.hpp"
params [["_filterName", "ERROR: No Name", [""]], ["_fncName", "", [""]]];
GVAR(customFilters) pushBack [_filterName, _fncName];

View File

@ -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

View File

@ -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;
};
};

View File

@ -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];
};
}];

View File

@ -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);

View File

@ -0,0 +1 @@
#include "\z\ace\addons\filters\script_component.hpp"

View File

@ -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"

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="Filters">
<Key ID="STR_ACE_Filters_Backpacks">
<English>Backpacks</English>
<German>Rucksäcke</German>
</Key>
<Key ID="STR_ACE_Filters_Headgear">
<English>Headgear</English>
<German>Helme</German>
</Key>
<Key ID="STR_ACE_Filters_Glasses">
<English>Glasses</English>
<German>Brillen</German>
</Key>
<Key ID="STR_ACE_Filters_Uniforms">
<English>Uniforms</English>
<German>Uniformen</German>
</Key>
<Key ID="STR_ACE_Filters_Vests">
<English>Vests</English>
<German>Westen</German>
</Key>
<Key ID="STR_ACE_Filters_Grenades">
<English>Grenades</English>
<German>Granaten</German>
</Key>
</Package>
</Project>