Skip to content

Commit

Permalink
Arsenal - Make ACE_asItem and ACE_isUnique apply to CfgWeapons (#10366)
Browse files Browse the repository at this point in the history
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 2, 2024
1 parent 8994b6b commit f2d3253
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 32 deletions.
6 changes: 6 additions & 0 deletions addons/arsenal/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PREP(handleSearchInputChanged);
PREP(handleSearchModeToggle);
PREP(handleStats);
PREP(initBox);
PREP(isMiscItem);
PREP(itemInfo);
PREP(loadoutsChangeTab);
PREP(message);
Expand Down
1 change: 1 addition & 0 deletions addons/arsenal/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
17 changes: 3 additions & 14 deletions addons/arsenal/functions/fnc_addRightPanelButton.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,9 @@ if (!isNil "_currentButtonInPosition") then {
};

// If spot found, add items and return position
private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";
private _configItemInfo = "";
// Sanitize to configCase and drop anything that's not a misc item
_items = _items apply {_x call EFUNC(common,getConfigName)} select {_x call FUNC(isMiscItem)};

_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
54 changes: 54 additions & 0 deletions addons/arsenal/functions/fnc_isMiscItem.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "..\script_component.hpp"
/*
* Author: DartRuffian, LinkIsGrim
* Determines if a class is a miscellaneous item or not.
*
* Arguments:
* 0: Item or magazine <STRING>
* 1: Item config <CONFIG> (default: nil)
* 2: Whether item is a magazine <BOOL> (default: false)
* 3: Skip setting false keys in the cache, mostly used for building it during preStart <BOOL> (default: false)
*
* Return Value:
* True if class is a misc item, otherwise false <BOOL>
*
* Example:
* "ACE_CableTie" call ace_arsenal_fnc_isMiscItem
*
* Public: No
*/

params ["_item", "_config", ["_isMag", false], ["_skipFalseKeys", false]];
TRACE_4("",_item,_config,_isMag,_skipFalseKeys);

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 _skipFalseKeys is false
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

if (isNil "_config") then {
_config = _item call CBA_fnc_getItemConfig;
};

case (_isMag): _fnc_hasProperty; // Magazine misc item, also easy

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 || !_skipFalseKeys) then {
_cache set [_item, _return];
};
};

_return
16 changes: 7 additions & 9 deletions addons/arsenal/functions/fnc_scanConfig.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]};
};
Expand All @@ -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 "";
Expand Down
9 changes: 2 additions & 7 deletions addons/arsenal/functions/fnc_updateUniqueItemsList.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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];
};
Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/framework/arsenal-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f2d3253

Please sign in to comment.