Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item Context Menu -- Add class-specific actions support #1517

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions addons/ui/fnc_addItemContextMenuOption.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ Parameters:
_params - Arguments passed as '_this select 4' to condition and
statement (optional, default: []) <ANY>

_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) <BOOLEAN>

Returns:
Nothing/Undefined.

Expand All @@ -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.
Expand All @@ -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"];
Expand All @@ -157,7 +163,8 @@ params [
["_condition", [], [{}, []]],
["_statement", {}, [{}]],
["_consume", false, [false]],
["_params", []]
["_params", []],
["_allowInheritance", true, [false]]
];

if (_item isEqualTo "") exitWith {};
Expand Down Expand Up @@ -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];
14 changes: 9 additions & 5 deletions addons/ui/fnc_openItemContextMenu.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Examples:
(end)

Author:
commy2
commy2 & 10Dozen
---------------------------------------------------------------------------- */

params ["_display", "_container", "_item", "_slot"];
Expand All @@ -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 {};
Expand Down