diff --git a/addons/arsenal/CfgWeapons.hpp b/addons/arsenal/CfgWeapons.hpp index c45bb7d5ece..0539a58bac1 100644 --- a/addons/arsenal/CfgWeapons.hpp +++ b/addons/arsenal/CfgWeapons.hpp @@ -3,6 +3,12 @@ class CfgWeapons { class ToolKit: ItemCore { ACE_isTool = 1; // sort in Tools Tab }; + + class ChemicalDetector_01_base_F: ItemCore { + ACE_asItem = 1; + ACE_isTool = 1; // sort in Tools Tab + }; + class DetectorCore; class MineDetector: DetectorCore { ACE_isTool = 1; // sort in Tools Tab diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index d0819056f25..b69ff0cb749 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -51,6 +51,7 @@ PREP(handleSearchInputChanged); PREP(handleSearchModeToggle); PREP(handleStats); PREP(initBox); +PREP(isMiscItem); PREP(itemInfo); PREP(loadoutsChangeTab); PREP(message); diff --git a/addons/arsenal/XEH_preStart.sqf b/addons/arsenal/XEH_preStart.sqf index 7e561340104..867d308874a 100644 --- a/addons/arsenal/XEH_preStart.sqf +++ b/addons/arsenal/XEH_preStart.sqf @@ -9,5 +9,6 @@ uiNamespace setVariable [QGVAR(baseWeaponNameCache), createHashMap]; uiNamespace setVariable [QGVAR(addListBoxItemCache), createHashMap]; uiNamespace setVariable [QGVAR(rightPanelCache), createHashMap]; uiNamespace setVariable [QGVAR(sortCache), createHashMap]; +uiNamespace setVariable [QGVAR(isMiscItemCache), createHashMap]; call FUNC(scanConfig); diff --git a/addons/arsenal/functions/fnc_addRightPanelButton.sqf b/addons/arsenal/functions/fnc_addRightPanelButton.sqf index a1bdb09d1d1..07ffd12722a 100644 --- a/addons/arsenal/functions/fnc_addRightPanelButton.sqf +++ b/addons/arsenal/functions/fnc_addRightPanelButton.sqf @@ -26,6 +26,7 @@ params [["_items", [], [[]]], ["_tooltip", "", [""]], ["_picture", QPATHTOF(data if (isNil QGVAR(customRightPanelButtons)) then { GVAR(customRightPanelButtons) = [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]; }; +_items = _items apply {_x call EFUNC(common,getConfigName)}; // sanitize to configCase, required for cache, this doesn't run constantly anyway private _position = -1; @@ -56,20 +57,8 @@ if (!isNil "_currentButtonInPosition") then { }; // If spot found, add items and return position -private _cfgWeapons = configFile >> "CfgWeapons"; -private _cfgMagazines = configFile >> "CfgMagazines"; -private _configItemInfo = ""; +_items = _items select {_x call FUNC(isMiscItem)}; // Only misc items can be added -_items = _items select { - _configItemInfo = _cfgWeapons >> _x >> "ItemInfo"; - - _x isKindOf ["CBA_MiscItem", _cfgWeapons] && {getNumber (_configItemInfo >> "type") in [TYPE_MUZZLE, TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_BIPOD]} || - {getNumber (_configItemInfo >> "type") in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]} || - {getText (_cfgWeapons >> _x >> "simulation") == "ItemMineDetector"} || - {getNumber (_cfgMagazines >> _x >> "ACE_isUnique") == 1} || - {getNumber (_cfgMagazines >> _x >> "ACE_asItem") == 1} -}; - -GVAR(customRightPanelButtons) set [_position, [_items apply {_x call EFUNC(common,getConfigName)}, _picture, _tooltip, _moveOnOverwrite]]; +GVAR(customRightPanelButtons) set [_position, [_items, _picture, _tooltip, _moveOnOverwrite]]; _position diff --git a/addons/arsenal/functions/fnc_isMiscItem.sqf b/addons/arsenal/functions/fnc_isMiscItem.sqf new file mode 100644 index 00000000000..8661eb9f4dd --- /dev/null +++ b/addons/arsenal/functions/fnc_isMiscItem.sqf @@ -0,0 +1,52 @@ +#include "..\script_component.hpp" +/* + * Author: DartRuffian, LinkIsGrim + * Determines if a class is a miscellaneous item or not. + * + * Arguments: + * 0: Item or magazine + * 1: Item config (default: nil) + * 2: Whether item is a magazine. If true, config should be passed as well (default: false) + * 3: If this is being called from preStart. Determines if key will be set even if it's false. If true, config should be passed as well (default: false) + * + * Return Value: + * True if class is a misc item, otherwise false + * + * Example: + * "ACE_CableTie" call ace_arsenal_fnc_isMiscItem + * + * Public: No +*/ + +params ["_item", "_config", ["_isMag", false], ["_inPreStart", false]]; +TRACE_4("",_item,_config,_isMag,_inPreStart); + +private _cache = uiNamespace getVariable QGVAR(isMiscItemCache); +private _return = _cache get _item; + +// Don't replace with getOrDefaultCall, we want the key to only be set if return is true or we are in a mission +if (isNil "_return") then { + private _fnc_hasProperty = {getNumber (_config >> "ACE_asItem") == 1 || {getNumber (_config >> "ACE_isUnique") == 1}}; + + _return = switch (true) do { + case (_item isKindOf ["CBA_MiscItem", configFile >> "CfgWeapons"]): {true}; // CBA misc item, easy + case (_isMag): _fnc_hasProperty; // Magazine misc item, also easy + + if (!_inPreStart) then { + _config = _item call CBA_fnc_getItemConfig; + }; + private _itemType = getNumber (_config >> "ItemInfo" >> "type"); + + case (_itemType in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]): {true}; // Special items: Med/Toolkits + case (_itemType in [TYPE_MUZZLE, TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_BIPOD]): _fnc_hasProperty; // "Forced" misc items + case ((getText (configFile >> "CfgWeapons" >> _item >> "simulation")) == "ItemMineDetector"): {true}; // Special items: mine detectors + + default {false} + }; + + if (_return || !_inPreStart) then { + _cache set [_item, _return]; + }; +}; + +_return diff --git a/addons/arsenal/functions/fnc_scanConfig.sqf b/addons/arsenal/functions/fnc_scanConfig.sqf index b5c6627cc7a..f2b4c23accf 100644 --- a/addons/arsenal/functions/fnc_scanConfig.sqf +++ b/addons/arsenal/functions/fnc_scanConfig.sqf @@ -50,7 +50,7 @@ private _isTool = false; _configItemInfo = _x >> "ItemInfo"; _hasItemInfo = isClass (_configItemInfo); _itemInfoType = if (_hasItemInfo) then {getNumber (_configItemInfo >> "type")} else {0}; - _isMiscItem = _className isKindOf ["CBA_MiscItem", _cfgWeapons]; + _isMiscItem = [_className, _x, false, true] call FUNC(isMiscItem); _isTool = getNumber (_x >> "ACE_isTool") isEqualTo 1; switch (true) do { @@ -127,13 +127,7 @@ private _isTool = false; }; }; // Misc. items - case ( - _hasItemInfo && - {_isMiscItem && - {_itemInfoType in [TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_MUZZLE, TYPE_BIPOD]}} || - {_itemInfoType in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]} || - {_simulationType == "ItemMineDetector"} - ): { + case (_hasItemInfo && _isMiscItem): { (_configItems get IDX_VIRT_MISC_ITEMS) set [_className, nil]; if (_isTool) then {_toolList set [_className, nil]}; }; @@ -160,7 +154,11 @@ private _magazineMiscItems = createHashMap; { _magazineMiscItems set [configName _x, nil]; -} forEach ((toString {getNumber (_x >> "ACE_isUnique") == 1 || getNumber (_x >> "ACE_asItem") == 1}) configClasses _cfgMagazines); +} forEach ((toString { + with uiNamespace do { // configClasses runs in missionNamespace even if we're in preStart apparently + [(configName _x), _x, true, true] call FUNC(isMiscItem); + }; +}) configClasses _cfgMagazines); // Remove invalid/non-existent entries _grenadeList deleteAt ""; diff --git a/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf b/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf index 9b7eb6327a8..4cbdc4bcba0 100644 --- a/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf +++ b/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf @@ -211,7 +211,7 @@ private _attachments = GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS; _configItemInfo = _config >> "ItemInfo"; _hasItemInfo = isClass (_configItemInfo); _itemInfoType = if (_hasItemInfo) then {getNumber (_configItemInfo >> "type")} else {0}; - _isMiscItem = _x isKindOf ["CBA_MiscItem", _cfgWeapons]; + _isMiscItem = _x call FUNC(isMiscItem); _baseWeapon = if (!_isMiscItem) then { _x call FUNC(baseWeapon) @@ -263,12 +263,7 @@ private _attachments = GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS; // Misc. items case ( !(_x in (GVAR(virtualItems) get IDX_VIRT_MISC_ITEMS)) && // misc. items don't use 'baseWeapon' - {_x in (_configItems get IDX_VIRT_MISC_ITEMS) || - {_hasItemInfo && - {_isMiscItem && - {_itemInfoType in [TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_MUZZLE, TYPE_BIPOD]}} || - {_itemInfoType in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]} || - {_simulationType == "ItemMineDetector"}}} + {_x in (_configItems get IDX_VIRT_MISC_ITEMS) || {_hasItemInfo && _isMiscItem}} ): { (GVAR(virtualItems) get IDX_VIRT_UNIQUE_MISC_ITEMS) set [_x, nil]; }; diff --git a/docs/wiki/framework/arsenal-framework.md b/docs/wiki/framework/arsenal-framework.md index 330e7fa99b1..2f37e552e1e 100644 --- a/docs/wiki/framework/arsenal-framework.md +++ b/docs/wiki/framework/arsenal-framework.md @@ -137,8 +137,8 @@ Examples: ACE Arsenal uses 2 existing config entries to sort and display items. - `baseWeapon`: Class name that is used to display an item in the arsenal, used for weapon/attachment variants that are not normally shown to the player (AI variants, PIP optics, and so on). This property can be applied to any weapon or weapon attachment in `CfgWeapons`. Items using CBA or RHS' Scripted Optics systems, or CBA Switchable Attachments do not need this property explictly set, and will automatically use their player-accessible class. -- `ACE_isUnique`: Classes in `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Misc. Items. Used for items with attached data that needs to be kept track of, such as Notepads or Spare Barrels. -- `ACE_asItem`: Classes in `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Items. Used for magazines that are not meant to be used in a weapon, such as Painkillers. +- `ACE_isUnique`: Classes in `CfgWeapons` or `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Misc. Items. Used for items with attached data that needs to be kept track of, such as Notepads or Spare Barrels. +- `ACE_asItem`: Classes in `CfgWeapons` or `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Items. Used for magazines that are not meant to be used in a weapon, such as Painkillers. ### 3.2 New config entries