Skip to content

Commit 899d18b

Browse files
authored
Merge pull request #1517 from 10Dozen/dzn-inventory-frame-noninherit-actions
Item Context Menu -- Add class-specific actions support
2 parents 597ee23 + 4911c89 commit 899d18b

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

addons/ui/fnc_addItemContextMenuOption.sqf

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ Parameters:
113113
An already existing ID will overwrite the previous settings.
114114
(optional, default: "") <STRING>
115115
116+
_allowInheritance - if true, then option will be available for all items
117+
that inherit from the given _item class.
118+
Does nothing if _item is a type or wildcard
119+
(optional, default: true) <BOOLEAN>
120+
116121
Returns:
117122
ID <STRING> (or <NIL> on error)
118123
@@ -122,11 +127,11 @@ Examples:
122127
params ["_unit", "_container", "_item", "_slot", "_params"];
123128
systemChat str [name _unit, typeOf _container, _item, _slot, _params];
124129
true
125-
}, false, [0,1,2]] call CBA_fnc_addItemContextMenuOption;
130+
}, false, [0,1,2], "DebugAction", false] call CBA_fnc_addItemContextMenuOption;
126131
(end)
127132
128133
Author:
129-
commy2, Zorn
134+
commy2, Zorn, 10Dozen
130135
---------------------------------------------------------------------------- */
131136

132137
// Force unscheduled environment to prevent race conditions.
@@ -139,6 +144,7 @@ if (!hasInterface) exitWith {};
139144
// Initialize system on first execution.
140145
if (isNil QGVAR(ItemContextMenuOptions)) then {
141146
GVAR(ItemContextMenuOptions) = createHashMap;
147+
GVAR(ItemContextMenuUniqueOptions) = createHashMap;
142148

143149
["CAManBase", "InventoryOpened", {
144150
params ["_unit", "_container1", "_container2"];
@@ -163,7 +169,8 @@ params [
163169
["_statement", {}, [{}]],
164170
["_consume", false, [false]],
165171
["_params", []],
166-
["_id", "", [""]]
172+
["_id", "", [""]],
173+
["_allowInheritance", true, [false]]
167174
];
168175

169176
if (_item isEqualTo "") exitWith { ERROR_1("no item specified [%1]",_item); nil };
@@ -228,11 +235,16 @@ _condition params [
228235
["_conditionShow", {true}, [{}]]
229236
];
230237

231-
private _options = GVAR(ItemContextMenuOptions) get _item;
238+
private _contextMenuOptions = GVAR(ItemContextMenuOptions);
239+
if (!_allowInheritance) then {
240+
_contextMenuOptions = GVAR(ItemContextMenuUniqueOptions);
241+
};
242+
243+
private _options = _contextMenuOptions get _item;
232244

233245
if (isNil "_options") then {
234246
_options = createHashMap;
235-
GVAR(ItemContextMenuOptions) set [_item, _options];
247+
_contextMenuOptions set [_item, _options];
236248
};
237249

238250
if (_id isEqualTo "") then {

addons/ui/fnc_openItemContextMenu.sqf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Examples:
2020
(end)
2121
2222
Author:
23-
commy2, Zorn
23+
commy2, Zorn, 10Dozen
2424
---------------------------------------------------------------------------- */
2525

2626
params ["_display", "_container", "_item", "_slot"];
@@ -37,6 +37,10 @@ while {
3737
!isNull _config
3838
} do {};
3939

40+
// Read unique class options (not inherited)
41+
_options merge (GVAR(ItemContextMenuUniqueOptions) getOrDefault [_item, createHashMap]);
42+
43+
// Read type and wildcard options
4044
_item call BIS_fnc_itemType params ["_itemType1", "_itemType2"];
4145
_options merge (GVAR(ItemContextMenuOptions) getOrDefault [format ["##%1", _itemType2], createHashMap]);
4246
_options merge (GVAR(ItemContextMenuOptions) getOrDefault [format ["#%1", _itemType1], createHashMap]);

0 commit comments

Comments
 (0)