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

Add Item Context Menu Framework #1303

Merged
merged 20 commits into from
Mar 19, 2020
Merged
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
3 changes: 3 additions & 0 deletions addons/ui/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ class Extended_DisplayLoad_EventHandlers {
class RscMsgBox {
ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayMessageBox)'));
};
class RscDisplayInventory {
ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayInventory)'));
};
};
5 changes: 5 additions & 0 deletions addons/ui/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ class CfgFunctions {
PATHTO_FNC(getUISize);
PATHTO_FNC(notify);
};

class ItemContextMenu {
PATHTO_FNC(addItemContextMenuOption);
PATHTO_FNC(consumeItem);
};
};
};
5 changes: 5 additions & 0 deletions addons/ui/RscTitles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ class RscText;
class RscProgress;
class RscMapControl;

class RscListBox;
class GVAR(ItemContextMenu): RscListBox {
colorBackground[] = {0.05,0.05,0.05,0.95};
};

class RscTitles {
class GVAR(ProgressBar) {
onLoad = uiNamespace setVariable ['GVAR(ProgressBar)', _this select 0];
Expand Down
2 changes: 2 additions & 0 deletions addons/ui/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (hasInterface) then {
QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"];
};
}];

PREP(openItemContextMenu);
};

// legacy function names
Expand Down
3 changes: 3 additions & 0 deletions addons/ui/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ PREP(initDisplayDiary);
PREP(initDisplay3DEN);
PREP(initDisplayCurator);
PREP(initDisplayMessageBox);
PREP(initDisplayInventory);

PREP(preload3DEN);
PREP(preloadCurator);

PREP(openItemContextMenu);
232 changes: 232 additions & 0 deletions addons/ui/fnc_addItemContextMenuOption.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_addItemContextMenuOption
Description:
Adds context menu option to inventory display.
Parameters:
_item - Item classname <STRING>
Can be base class.
Can be item type as reported by BIS_fnc_itemType:
["Equipment","Headgear"]
->
"#Equipment" and/or "##Headgear"
Wildcard:
#All
_slots - Relevant slots <ARRAY, STRING>
Values:
ALL
GROUND
CARGO
CONTAINER
UNIFORM_CONTAINER
VEST_CONTAINER
BACKPACK_CONTAINER
CLOTHES
UNIFORM
VEST
BACKPACK
HEADGEAR
GOGGLES
WEAPON
RIFLE
LAUNCHER
PISTOL
BINOCULAR
SILENCER
RIFLE_SILENCER
LAUNCHER_SILENCER
PISTOL_SILENCER
BIPOD
RIFLE_BIPOD
LAUNCHER_BIPOD
PISTOL_BIPOD
OPTIC
RIFLE_OPTIC
LAUNCHER_OPTIC
PISTOL_OPTIC
POINTER
RIFLE_POINTER
LAUNCHER_POINTER
PISTOL_POINTER
MAGAZINE
RIFLE_MAGAZINE
RIFLE_MAGAZINE_GL
LAUNCHER_MAGAZINE
PISTOL_MAGAZINE
ASSIGNED_ITEM
MAP
GPS
RADIO
COMPASS
WATCH
HMD
_displayName String keys are automatically translated. <STRING, ARRAY>
0: _displayName - Option display name <STRING>
1: _tooltip - Option tooltip <STRING>
_color - Option text color. Default alpha is 1.
(default: [] = default color) <ARRAY>
_icon - Path to icon. (default: "" = no icon) <STRING>
_condition <CODE, ARRAY>
0: _conditionEnable - Menu option is enabled and executed only if this
condition reports 'true' (default: {true}) <CODE>
1: _conditionShow - Menu option is shown only if this condition
reports 'true'. (optional, default: {true}) <CODE>
- Passed arguments:
params ["_unit", "_container", "_item", "_slot", "_params"];
_statement - Option statement (default: {}) <CODE>
Return true to keep context menu opened.
- Passed arguments:
params ["_unit", "_container", "_item", "_slot", "_params"];
_consume - Remove the item before executing the statement
code. (default: false) <BOOLEAN>
- This does NOT work for the following slots:
GROUND
CARGO
_params - Arguments passed as '_this select 4' to condition and
statement (optional, default: []) <ANY>
Returns:
Nothing/Undefined.
Examples:
(begin example)
["#All", "ALL", ">DEBUG ACTION<", nil, nil, {true}, {
params ["_unit", "_container", "_item", "_slot", "_params"];
systemChat str [name _unit, typeOf _container, _item, _slot, _params];
true
}, false, [0,1,2]] call CBA_fnc_addItemContextMenuOption;
(end)
Author:
commy2
---------------------------------------------------------------------------- */

// Force unscheduled environment to prevent race conditions.
if (canSuspend) exitWith {
[CBA_fnc_addItemContextMenuOption, _this] call CBA_fnc_directCall;
};

if (!hasInterface) exitWith {};
jonpas marked this conversation as resolved.
Show resolved Hide resolved

// Initialize system on first execution.
if (isNil QGVAR(ItemContextMenuOptions)) then {
GVAR(ItemContextMenuOptions) = false call CBA_fnc_createNamespace;

["CAManBase", "InventoryOpened", {
params ["_unit", "_container1", "_container2"];
if (_unit != call CBA_fnc_currentUnit) exitWith {};

if (isNull _container2) then {
GVAR(CurrentGroundItemHolder) = _container1;
} else {
GVAR(CurrentContainer) = _container1;
GVAR(CurrentGroundItemHolder) = _container2;
};
}] call CBA_fnc_addClassEventHandler;
};

params [
["_item", "All", [""]],
["_slots", [], [[], ""]],
["_displayName", [], ["", []]],
["_color", [], [[]], [0,3,4]],
["_icon", "", [""]],
["_condition", [], [{}, []]],
["_statement", {}, [{}]],
["_consume", false, [false]],
["_params", []]
];

if (_item isEqualTo "") exitWith {};

if (_slots isEqualType "") then {
_slots = [_slots];
};
_slots = _slots apply {toUpper _x}; // This also copies the array.

if ("CONTAINER" in _slots) then {
_slots append ["UNIFORM_CONTAINER", "VEST_CONTAINER", "BACKPACK_CONTAINER"];
};

if ("CLOTHES" in _slots) then {
_slots append ["UNIFORM", "VEST", "BACKPACK", "HEADGEAR", "GOGGLES"];
};

if ("WEAPON" in _slots) then {
_slots append ["RIFLE", "LAUNCHER", "PISTOL", "BINOCULAR"];
};

if ("SILENCER" in _slots) then {
_slots append ["RIFLE_SILENCER", "LAUNCHER_SILENCER", "PISTOL_SILENCER"];
};

if ("BIPOD" in _slots) then {
_slots append ["RIFLE_BIPOD", "LAUNCHER_BIPOD", "PISTOL_BIPOD"];
};

if ("OPTIC" in _slots) then {
_slots append ["RIFLE_OPTIC", "LAUNCHER_OPTIC", "PISTOL_OPTIC"];
};

if ("POINTER" in _slots) then {
_slots append ["RIFLE_POINTER", "LAUNCHER_POINTER", "PISTOL_POINTER"];
};

if ("MAGAZINE" in _slots) then {
_slots append ["RIFLE_MAGAZINE", "RIFLE_MAGAZINE_GL", "LAUNCHER_MAGAZINE", "PISTOL_MAGAZINE"];
};

if ("ASSIGNED_ITEM" in _slots) then {
_slots append ["MAP", "GPS", "RADIO", "COMPASS", "WATCH", "HMD"];
};

_displayName params [
["_displayName", "<default>", [""]],
["_tooltip", "", [""]]
];

if !(_color isEqualTo []) then {
_color params [["_r", 1, [0]], ["_g", 1, [0]], ["_b", 1, [0]], ["_a", 1, [0]]];
_color = [_r, _g, _b, _a];
};

if (_icon isEqualTo "") then {
_icon = "#(argb,8,8,3)color(0,0,0,0)";
};

_condition params [
["_conditionEnable", {true}, [{}]],
["_conditionShow", {true}, [{}]]
];

private _options = GVAR(ItemContextMenuOptions) getVariable _item;

if (isNil "_options") then {
_options = [];
GVAR(ItemContextMenuOptions) setVariable [_item, _options];
};

_options pushBack [_slots, _displayName, _tooltip, _color, _icon, _conditionEnable, _conditionShow, _statement, _consume, _params];
Loading