add more filters to ammo boxes

This commit is contained in:
commy2 2015-12-11 13:14:58 +01:00
parent 68388bc976
commit 2b63b2efa8
16 changed files with 285 additions and 62 deletions

View File

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

View File

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

View File

@ -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 <STRING>
* 1: Filter function name <STRING>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params [["_filterName", "ERROR: No Name", [""]], ["_fncName", "", [""]]];

View File

@ -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 <DISPLAY>
*
* Return Value:
* Currently selected item list box <CONTROL>
*
* 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

View File

@ -0,0 +1,17 @@
/*
* Author: commy2
* Filter condition for the Backpacks filter list
*
* Arguments:
* 0: Item config entry <CONFIG>
*
* Return Value:
* Item should appear in this list? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
params ["_config"];
getNumber (_config >> "isBackpack") == 1

View File

@ -0,0 +1,17 @@
/*
* Author: commy2
* Filter condition for the Grenades filter list
*
* Arguments:
* 0: Item config entry <CONFIG>
*
* Return Value:
* Item should appear in this list? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
params ["_config"];
toLower configName _config in GVAR(Grenades_ItemList)

View File

@ -0,0 +1,17 @@
/*
* Author: commy2
* Filter condition for the Headgear filter list
*
* Arguments:
* 0: Item config entry <CONFIG>
*
* Return Value:
* Item should appear in this list? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
params ["_config"];
getNumber (_config >> "ItemInfo" >> "type") in [TYPE_HEADGEAR, TYPE_HMD] || {isClass (configFile >> "CfgGlasses" >> configName _config)}

View File

@ -0,0 +1,17 @@
/*
* Author: commy2
* Filter condition for the Medical filter list
*
* Arguments:
* 0: Item config entry <CONFIG>
*
* Return Value:
* Item should appear in this list? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
params ["_config"];
toLower configName _config in GVAR(Medical_ItemList)

View File

@ -0,0 +1,17 @@
/*
* Author: commy2
* Filter condition for the Uniforms filter list
*
* Arguments:
* 0: Item config entry <CONFIG>
*
* Return Value:
* Item should appear in this list? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
params ["_config"];
getNumber (_config >> "ItemInfo" >> "type") == TYPE_UNIFORM

View File

@ -0,0 +1,17 @@
/*
* Author: commy2
* Filter condition for the Vests filter list
*
* Arguments:
* 0: Item config entry <CONFIG>
*
* Return Value:
* Item should appear in this list? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
params ["_config"];
getNumber (_config >> "ItemInfo" >> "type") == TYPE_VEST

View File

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

View File

@ -1,10 +1,21 @@
// by commy2
/*
* Author: commy2
* Executed every time an inventory display is opened.
*
* Arguments:
* 0: Inventory display <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];
};
}];

View File

@ -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 <CONTROL>
* 1: Filter list index <NUMBER>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
disableSerialization;

View File

@ -9,4 +9,13 @@
#define DEBUG_SETTINGS DEBUG_ENABLED_FILTERS
#endif
#include "\z\ace\addons\main\script_macros.hpp"
#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

View File

@ -7,7 +7,7 @@
</Key>
<Key ID="STR_ACE_Filters_Headgear">
<English>Headgear</English>
<German>Helme</German>
<German>Kopfbedeckungen</German>
</Key>
<Key ID="STR_ACE_Filters_Glasses">
<English>Glasses</English>
@ -25,5 +25,9 @@
<English>Grenades</English>
<German>Granaten</German>
</Key>
<Key ID="STR_ACE_Filters_Medical">
<English>Medical</English>
<German>Sanimaterial</German>
</Key>
</Package>
</Project>

View File

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