diff --git a/addons/ui/fnc_addItemContextMenuOption.sqf b/addons/ui/fnc_addItemContextMenuOption.sqf index 38b029aba..ec3ba55ed 100644 --- a/addons/ui/fnc_addItemContextMenuOption.sqf +++ b/addons/ui/fnc_addItemContextMenuOption.sqf @@ -108,6 +108,11 @@ Parameters: _params - Arguments passed as '_this select 4' to condition and statement (optional, default: []) + _allowInheritance - if true, then option will be available for all items + that inherit from the given _item class. + Does nothing if _item is a type or wildcard + (optional, default: true) + Returns: Nothing/Undefined. @@ -117,11 +122,11 @@ Examples: params ["_unit", "_container", "_item", "_slot", "_params"]; systemChat str [name _unit, typeOf _container, _item, _slot, _params]; true - }, false, [0,1,2]] call CBA_fnc_addItemContextMenuOption; + }, false, [0,1,2], false] call CBA_fnc_addItemContextMenuOption; (end) Author: - commy2 + commy2 & 10Dozen ---------------------------------------------------------------------------- */ // Force unscheduled environment to prevent race conditions. @@ -133,7 +138,8 @@ if (!hasInterface) exitWith {}; // Initialize system on first execution. if (isNil QGVAR(ItemContextMenuOptions)) then { - GVAR(ItemContextMenuOptions) = false call CBA_fnc_createNamespace; + GVAR(ItemContextMenuOptions) = createHashMap; + GVAR(ItemContextMenuUniqueOptions) = createHashMap; ["CAManBase", "InventoryOpened", { params ["_unit", "_container1", "_container2"]; @@ -157,7 +163,8 @@ params [ ["_condition", [], [{}, []]], ["_statement", {}, [{}]], ["_consume", false, [false]], - ["_params", []] + ["_params", []], + ["_allowInheritance", true, [false]] ]; if (_item isEqualTo "") exitWith {}; @@ -222,11 +229,16 @@ _condition params [ ["_conditionShow", {true}, [{}]] ]; -private _options = GVAR(ItemContextMenuOptions) getVariable _item; +private _contextMenuOptions = GVAR(ItemContextMenuOptions); +if (!_allowInheritance) then { + _contextMenuOptions = GVAR(ItemContextMenuUniqueOptions); +}; + +private _options = _contextMenuOptions get _item; if (isNil "_options") then { _options = []; - GVAR(ItemContextMenuOptions) setVariable [_item, _options]; + _contextMenuOptions set [_item, _options]; }; _options pushBack [_slots, _displayName, _tooltip, _color, _icon, _conditionEnable, _conditionShow, _statement, _consume, _params]; diff --git a/addons/ui/fnc_openItemContextMenu.sqf b/addons/ui/fnc_openItemContextMenu.sqf index 3fd9328bd..42ff7b59a 100644 --- a/addons/ui/fnc_openItemContextMenu.sqf +++ b/addons/ui/fnc_openItemContextMenu.sqf @@ -18,7 +18,7 @@ Examples: (end) Author: - commy2 + commy2 & 10Dozen ---------------------------------------------------------------------------- */ params ["_display", "_container", "_item", "_slot"]; @@ -30,15 +30,19 @@ private _config = _item call CBA_fnc_getItemConfig; private _options = []; while { - _options append (GVAR(ItemContextMenuOptions) getVariable configName _config); + _options append (GVAR(ItemContextMenuOptions) get configName _config); _config = inheritsFrom _config; !isNull _config } do {}; +// Read unique class options (not inherited) +_options append (GVAR(ItemContextMenuUniqueOptions) getOrDefault [_item, []]); + +// Read type and wildcard options _item call BIS_fnc_itemType params ["_itemType1", "_itemType2"]; -_options append (GVAR(ItemContextMenuOptions) getVariable [format ["##%1", _itemType2], []]); -_options append (GVAR(ItemContextMenuOptions) getVariable [format ["#%1", _itemType1], []]); -_options append (GVAR(ItemContextMenuOptions) getVariable ["#All", []]); +_options append (GVAR(ItemContextMenuOptions) getOrDefault [format ["##%1", _itemType2], []]); +_options append (GVAR(ItemContextMenuOptions) getOrDefault [format ["#%1", _itemType1], []]); +_options append (GVAR(ItemContextMenuOptions) getOrDefault ["#All", []]); // Skip menu if no options. if (_options isEqualTo []) exitWith {};