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 Rename Framework #1329

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions addons/ui/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CfgFunctions {
};

PATHTO_FNC(addPauseMenuOption);
PATHTO_FNC(addRenamedItem);
PATHTO_FNC(progressBar);
PATHTO_FNC(getFov);
PATHTO_FNC(getAspectRatio);
Expand Down
8 changes: 8 additions & 0 deletions addons/ui/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ if (hasInterface) then {
}];

PREP(openItemContextMenu);
PREP(getInventoryClassname);
};

if (isServer) then {
GVAR(renamedItems) = call CBA_fnc_createNamespace;
publicVariable QGVAR(renamedItems);
};

GVAR(inventoryPFH) = [];

// legacy function names
FUNC(Add) = CBA_fnc_flexiMenu_Add;
FUNC(Remove) = CBA_fnc_flexiMenu_Remove;
Expand Down
2 changes: 2 additions & 0 deletions addons/ui/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ PREP(preload3DEN);
PREP(preloadCurator);

PREP(openItemContextMenu);

PREP(getInventoryClassname);
35 changes: 35 additions & 0 deletions addons/ui/fnc_addRenamedItem.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_addRenamedItem

Description:
Rename an item

Parameters:
_content - Notifications content (lines). <ARRAY>
_line1 - First content line. <ARRAY>
_line2 - Second content line. <ARRAY>
...
_lineN - N-th content line (may be passed directly if only 1 line is required). <ARRAY>
_text - Text to display or path to .paa or .jpg image (may be passed directly if only text is required). <STRING, NUMBER>
_size - Text or image size multiplier. (optional, default: 1) <NUMBER>
_color - RGB or RGBA color (range 0-1). (optional, default: [1, 1, 1, 1]) <ARRAY>
_skippable - Skip or overwrite this notification if another entered the queue. (optional, default: false) <BOOL>

Examples:
(begin example)
"Banana" call CBA_fnc_notify;
["Banana", 1.5, [1, 1, 0, 1]] call CBA_fnc_notify;
[["Banana", 1.5, [1, 1, 0, 1]], ["Not Apple"], true] call CBA_fnc_notify;
(end)

Returns:
Nothing

Authors:
SynixeBrett
---------------------------------------------------------------------------- */

params ["_class", "_name"];

GVAR(renamedItems) setVariable [_class, _name, true];
58 changes: 58 additions & 0 deletions addons/ui/fnc_getInventoryClassname.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Internal Function: cba_ui_fnc_getInventoryClassname

Description:
Opens the item context menu on the inventory screen.

Parameters:
_control - RscDisplayInventory control <CONTROL>
_index - Item index <NUMBER>

Returns:
_classname, _container, _containerType

Examples:
(begin example)
[_groundContainer, 5] call cba_ui_fnc_getInventoryClassname;
(end)

Author:
commy2, SynixeBrett
---------------------------------------------------------------------------- */

params ["_control", "_index"];

private _unit = call CBA_fnc_currentUnit;

private _container = objNull;
private _containerType = _control getVariable QGVAR(containerType);
switch _containerType do {
case "GROUND": {
_container = GVAR(CurrentGroundItemHolder);
};
case "CARGO": {
_container = GVAR(CurrentContainer);
};
case "UNIFORM_CONTAINER": {
_container = uniformContainer _unit;
};
case "VEST_CONTAINER": {
_container = vestContainer _unit;
};
case "BACKPACK_CONTAINER": {
_container = backpackContainer _unit;
};
};

// Reports classname, but only for magazines.
private _classname = _control lbData _index;
if (_classname isEqualTo "") then {
// For weapons, items and glasses, use the lb index and compare with cargo item list.
private _cargoItems = weaponCargo _container + itemCargo _container + magazineCargo _container;
_cargoItems = _cargoItems arrayIntersect _cargoItems;

_classname = _cargoItems param [_index, ""];
};

[_classname, _container, _containerType]
52 changes: 22 additions & 30 deletions addons/ui/fnc_initDisplayInventory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -229,43 +229,35 @@ _vestItems setVariable [QGVAR(containerType), "VEST_CONTAINER"];
_backpackItems setVariable [QGVAR(containerType), "BACKPACK_CONTAINER"];

{
_x ctrlAddEventHandler ["lbDblClick", {
params ["_control", "_index"];
private _unit = call CBA_fnc_currentUnit;

private _container = objNull;
private _containerType = _control getVariable QGVAR(containerType);
switch _containerType do {
case "GROUND": {
_container = GVAR(CurrentGroundItemHolder);
};
case "CARGO": {
_container = GVAR(CurrentContainer);
};
case "UNIFORM_CONTAINER": {
_container = uniformContainer _unit;
};
case "VEST_CONTAINER": {
_container = vestContainer _unit;
};
case "BACKPACK_CONTAINER": {
_container = backpackContainer _unit;
GVAR(inventoryPFH) pushBack ([{
(_this select 0) params ["_control"];
if !(ctrlShown _control) exitWith {};
// Item Rename Framework
for [{_i = 0}, {_i < (lbSize _control)}, {_i = _i + 1}] do
{
private _classname = ([_control, _i] call FUNC(getInventoryClassname)) select 0;
private _name = GVAR(renamedItems) getVariable [_classname, ""];
if !(_name isEqualTo "") then {
_control lbSetText [_i, _name];
};
};
}, 0, [_x]] call CBA_fnc_addPerFrameHandler);

// Reports classname, but only for magazines.
private _classname = _control lbData _index;
if (_classname isEqualTo "") then {
// For weapons, items and glasses, use the lb index and compare with cargo item list.
private _cargoItems = weaponCargo _container + itemCargo _container + magazineCargo _container;
_cargoItems = _cargoItems arrayIntersect _cargoItems;

_classname = _cargoItems param [_index, ""];
};
// Item Context Menu Framework

_x ctrlAddEventHandler ["lbDblClick", {
params ["_control", "_index"];
([_control, _index] call FUNC(getInventoryClassname)) params ["_classname", "_container", "_containerType"];
[ctrlParent _control, _container, _classname, _containerType] call FUNC(openItemContextMenu);
}];
} forEach [
_groundItems, _containerItems,
_uniformItems, _vestItems, _backpackItems
];

_display displayAddEventHandler ["unload", {
{
_x call CBA_fnc_removePerFrameHandler;
} forEach GVAR(inventoryPFH);
GVAR(inventoryPFH) = [];
}];
1 change: 1 addition & 0 deletions hemtt.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# HEMTT: https://github.com/synixebrett/HEMTT/commit/d828af84613f6725732a4c42c8b4611ae2a0cf81
name = "CBA_A3"
prefix = "cba"
mainprefix = "x"
author = "CBATeam"
files = [
"mod.cpp",
Expand Down