From 2ceb225d8d33d745927a8198e9227faa2a2e9abe Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 27 Apr 2020 01:04:35 -0600 Subject: [PATCH 1/8] first draft proof of concept --- addons/ui/CfgFunctions.hpp | 1 + addons/ui/XEH_preInit.sqf | 5 +++ addons/ui/fnc_addRenamedItem.sqf | 35 ++++++++++++++++++++ addons/ui/fnc_initDisplayInventory.sqf | 46 ++++++++++++++++++++++++++ hemtt.toml | 1 + 5 files changed, 88 insertions(+) create mode 100644 addons/ui/fnc_addRenamedItem.sqf diff --git a/addons/ui/CfgFunctions.hpp b/addons/ui/CfgFunctions.hpp index db65a40cd..b7341de64 100644 --- a/addons/ui/CfgFunctions.hpp +++ b/addons/ui/CfgFunctions.hpp @@ -45,6 +45,7 @@ class CfgFunctions { }; PATHTO_FNC(addPauseMenuOption); + PATHTO_FNC(addRenamedItem); PATHTO_FNC(progressBar); PATHTO_FNC(getFov); PATHTO_FNC(getAspectRatio); diff --git a/addons/ui/XEH_preInit.sqf b/addons/ui/XEH_preInit.sqf index cee1d51c1..e48c924ab 100644 --- a/addons/ui/XEH_preInit.sqf +++ b/addons/ui/XEH_preInit.sqf @@ -17,6 +17,11 @@ if (hasInterface) then { PREP(openItemContextMenu); }; +if (isServer) then { + GVAR(renamedItems) = call CBA_fnc_createNamespace; + publicVariable QGVAR(renamedItems); +}; + // legacy function names FUNC(Add) = CBA_fnc_flexiMenu_Add; FUNC(Remove) = CBA_fnc_flexiMenu_Remove; diff --git a/addons/ui/fnc_addRenamedItem.sqf b/addons/ui/fnc_addRenamedItem.sqf new file mode 100644 index 000000000..34835245a --- /dev/null +++ b/addons/ui/fnc_addRenamedItem.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addRenamedItem + +Description: + Rename an item + +Parameters: + _content - Notifications content (lines). + _line1 - First content line. + _line2 - Second content line. + ... + _lineN - N-th content line (may be passed directly if only 1 line is required). + _text - Text to display or path to .paa or .jpg image (may be passed directly if only text is required). + _size - Text or image size multiplier. (optional, default: 1) + _color - RGB or RGBA color (range 0-1). (optional, default: [1, 1, 1, 1]) + _skippable - Skip or overwrite this notification if another entered the queue. (optional, default: false) + +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]; diff --git a/addons/ui/fnc_initDisplayInventory.sqf b/addons/ui/fnc_initDisplayInventory.sqf index 239297f0c..95913df3d 100644 --- a/addons/ui/fnc_initDisplayInventory.sqf +++ b/addons/ui/fnc_initDisplayInventory.sqf @@ -229,6 +229,52 @@ _vestItems setVariable [QGVAR(containerType), "VEST_CONTAINER"]; _backpackItems setVariable [QGVAR(containerType), "BACKPACK_CONTAINER"]; { + // Rename Framework + [{ctrlShown (_this select 0)}, { + params ["_control"]; + private _unit = call CBA_fnc_currentUnit; + for [{_i = 0}, {_i < (lbSize _control)}, {_i = _i + 1}] do + { + 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 _i; + 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 [_i, ""]; + }; + + systemChat format ["class name %1", _classname]; + + private _name = GVAR(renamedItems) getVariable [_classname, ""]; + if !(_name isEqualTo "") then { + systemChat format ["renaming %1", _name]; + _control lbSetText [_i, _name]; + }; + }; + }, [_x]] call CBA_fnc_waitUntilAndExecute; + _x ctrlAddEventHandler ["lbDblClick", { params ["_control", "_index"]; private _unit = call CBA_fnc_currentUnit; diff --git a/hemtt.toml b/hemtt.toml index ef9a55760..3002f2206 100644 --- a/hemtt.toml +++ b/hemtt.toml @@ -1,6 +1,7 @@ # HEMTT: https://github.com/synixebrett/HEMTT/commit/d828af84613f6725732a4c42c8b4611ae2a0cf81 name = "CBA_A3" prefix = "cba" +mainprefix = "x" author = "CBATeam" files = [ "mod.cpp", From fda4bbb08fda8d3dbf37ade79ab7c97d4e139cf7 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 27 Apr 2020 02:50:18 -0600 Subject: [PATCH 2/8] support items moving --- addons/ui/XEH_preInit.sqf | 3 + addons/ui/XEH_preStart.sqf | 2 + addons/ui/fnc_getInventoryClassname.sqf | 58 +++++++++++++++++ addons/ui/fnc_initDisplayInventory.sqf | 86 +++++-------------------- 4 files changed, 79 insertions(+), 70 deletions(-) create mode 100644 addons/ui/fnc_getInventoryClassname.sqf diff --git a/addons/ui/XEH_preInit.sqf b/addons/ui/XEH_preInit.sqf index e48c924ab..884412ec8 100644 --- a/addons/ui/XEH_preInit.sqf +++ b/addons/ui/XEH_preInit.sqf @@ -15,6 +15,7 @@ if (hasInterface) then { }]; PREP(openItemContextMenu); + PREP(getInventoryClassname); }; if (isServer) then { @@ -22,6 +23,8 @@ if (isServer) then { publicVariable QGVAR(renamedItems); }; +GVAR(inventoryPFH) = []; + // legacy function names FUNC(Add) = CBA_fnc_flexiMenu_Add; FUNC(Remove) = CBA_fnc_flexiMenu_Remove; diff --git a/addons/ui/XEH_preStart.sqf b/addons/ui/XEH_preStart.sqf index bfa7f312c..d4f6f7b5b 100644 --- a/addons/ui/XEH_preStart.sqf +++ b/addons/ui/XEH_preStart.sqf @@ -17,3 +17,5 @@ PREP(preload3DEN); PREP(preloadCurator); PREP(openItemContextMenu); + +PREP(getInventoryClassname); diff --git a/addons/ui/fnc_getInventoryClassname.sqf b/addons/ui/fnc_getInventoryClassname.sqf new file mode 100644 index 000000000..6b0dfe20f --- /dev/null +++ b/addons/ui/fnc_getInventoryClassname.sqf @@ -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 + _index - Item index + +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] diff --git a/addons/ui/fnc_initDisplayInventory.sqf b/addons/ui/fnc_initDisplayInventory.sqf index 95913df3d..d6ce5184f 100644 --- a/addons/ui/fnc_initDisplayInventory.sqf +++ b/addons/ui/fnc_initDisplayInventory.sqf @@ -229,89 +229,35 @@ _vestItems setVariable [QGVAR(containerType), "VEST_CONTAINER"]; _backpackItems setVariable [QGVAR(containerType), "BACKPACK_CONTAINER"]; { - // Rename Framework - [{ctrlShown (_this select 0)}, { - params ["_control"]; - private _unit = call CBA_fnc_currentUnit; + 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 _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 _i; - 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 [_i, ""]; - }; - - systemChat format ["class name %1", _classname]; - + private _classname = ([_control, _i] call FUNC(getInventoryClassname)) select 0; private _name = GVAR(renamedItems) getVariable [_classname, ""]; if !(_name isEqualTo "") then { - systemChat format ["renaming %1", _name]; _control lbSetText [_i, _name]; }; }; - }, [_x]] call CBA_fnc_waitUntilAndExecute; + }, 0, [_x]] call CBA_fnc_addPerFrameHandler); + + // Item Context Menu Framework _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; - }; - }; - - // 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, ""]; - }; - + ([_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) = []; +}]; From fc7614af001cf24c345656fb2f2d5ef57f3f12ca Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 14 May 2020 21:32:49 +0200 Subject: [PATCH 3/8] a MouseHolding/Moving engine --- addons/ui/XEH_preInit.sqf | 2 +- addons/ui/fnc_initDisplayInventory.sqf | 45 ++++++++++++++------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/addons/ui/XEH_preInit.sqf b/addons/ui/XEH_preInit.sqf index 884412ec8..512de19c5 100644 --- a/addons/ui/XEH_preInit.sqf +++ b/addons/ui/XEH_preInit.sqf @@ -19,7 +19,7 @@ if (hasInterface) then { }; if (isServer) then { - GVAR(renamedItems) = call CBA_fnc_createNamespace; + GVAR(renamedItems) = true call CBA_fnc_createNamespace; publicVariable QGVAR(renamedItems); }; diff --git a/addons/ui/fnc_initDisplayInventory.sqf b/addons/ui/fnc_initDisplayInventory.sqf index d6ce5184f..1772b6596 100644 --- a/addons/ui/fnc_initDisplayInventory.sqf +++ b/addons/ui/fnc_initDisplayInventory.sqf @@ -228,23 +228,13 @@ _uniformItems setVariable [QGVAR(containerType), "UNIFORM_CONTAINER"]; _vestItems setVariable [QGVAR(containerType), "VEST_CONTAINER"]; _backpackItems setVariable [QGVAR(containerType), "BACKPACK_CONTAINER"]; +private _controls = []; +_display setVariable [QGVAR(controls), _controls]; + { - 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); + _controls pushBack _x; // Item Context Menu Framework - _x ctrlAddEventHandler ["lbDblClick", { params ["_control", "_index"]; ([_control, _index] call FUNC(getInventoryClassname)) params ["_classname", "_container", "_containerType"]; @@ -255,9 +245,24 @@ _backpackItems setVariable [QGVAR(containerType), "BACKPACK_CONTAINER"]; _uniformItems, _vestItems, _backpackItems ]; -_display displayAddEventHandler ["unload", { - { - _x call CBA_fnc_removePerFrameHandler; - } forEach GVAR(inventoryPFH); - GVAR(inventoryPFH) = []; -}]; +private _fnc_update = { + params ["_display"]; + systemChat str _this; + + { + _x 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]; + }; + }; + } forEach (_display getVariable QGVAR(controls)); +}; +_display displayAddEventHandler ["MouseMoving", _fnc_update]; +_display displayAddEventHandler ["MouseHolding", _fnc_update]; From 17773193b80438739cf3b518dd14c5d59e1788fa Mon Sep 17 00:00:00 2001 From: SzwedzikPL Date: Tue, 26 May 2020 07:53:40 +0200 Subject: [PATCH 4/8] Make Item Rename Framework local; Tweak functions and initDisplayInventory; Rename addRenamedItem function to renameInventoryItem Add params with typecheck, hasInterface & empty class check & header comment for public use in renameInventoryItem function Make functions & namespace local Rename getInventoryClassname function to getInventoryItemData Tweak initDisplayInventory function to: - Make Rename Item Framework work if Item Context Framework options are not present - Not not run if no ItemContextMenuOptions and renamedItems are present - Not not register Item Context Framework event handlers if ItemContextMenuOptions are not present - Not register Item Rename framework handlers if renamedItems are not present - Change exitWith to normal if for checking ctrlShown becouse exitWith will exit whole loop before checking rest of controls --- addons/ui/CfgFunctions.hpp | 2 +- addons/ui/XEH_preInit.sqf | 9 +- addons/ui/XEH_preStart.sqf | 2 +- addons/ui/fnc_addRenamedItem.sqf | 35 -- ...sname.sqf => fnc_getInventoryItemData.sqf} | 6 +- addons/ui/fnc_initDisplayInventory.sqf | 321 +++++++++--------- addons/ui/fnc_renameInventoryItem.sqf | 37 ++ 7 files changed, 207 insertions(+), 205 deletions(-) delete mode 100644 addons/ui/fnc_addRenamedItem.sqf rename addons/ui/{fnc_getInventoryClassname.sqf => fnc_getInventoryItemData.sqf} (89%) create mode 100644 addons/ui/fnc_renameInventoryItem.sqf diff --git a/addons/ui/CfgFunctions.hpp b/addons/ui/CfgFunctions.hpp index b7341de64..e9bbaf0c4 100644 --- a/addons/ui/CfgFunctions.hpp +++ b/addons/ui/CfgFunctions.hpp @@ -45,7 +45,7 @@ class CfgFunctions { }; PATHTO_FNC(addPauseMenuOption); - PATHTO_FNC(addRenamedItem); + PATHTO_FNC(renameInventoryItem); PATHTO_FNC(progressBar); PATHTO_FNC(getFov); PATHTO_FNC(getAspectRatio); diff --git a/addons/ui/XEH_preInit.sqf b/addons/ui/XEH_preInit.sqf index 512de19c5..fd8f1eaf7 100644 --- a/addons/ui/XEH_preInit.sqf +++ b/addons/ui/XEH_preInit.sqf @@ -15,16 +15,9 @@ if (hasInterface) then { }]; PREP(openItemContextMenu); - PREP(getInventoryClassname); + PREP(getInventoryItemData); }; -if (isServer) then { - GVAR(renamedItems) = true call CBA_fnc_createNamespace; - publicVariable QGVAR(renamedItems); -}; - -GVAR(inventoryPFH) = []; - // legacy function names FUNC(Add) = CBA_fnc_flexiMenu_Add; FUNC(Remove) = CBA_fnc_flexiMenu_Remove; diff --git a/addons/ui/XEH_preStart.sqf b/addons/ui/XEH_preStart.sqf index d4f6f7b5b..2ac214636 100644 --- a/addons/ui/XEH_preStart.sqf +++ b/addons/ui/XEH_preStart.sqf @@ -18,4 +18,4 @@ PREP(preloadCurator); PREP(openItemContextMenu); -PREP(getInventoryClassname); +PREP(getInventoryItemData); diff --git a/addons/ui/fnc_addRenamedItem.sqf b/addons/ui/fnc_addRenamedItem.sqf deleted file mode 100644 index 34835245a..000000000 --- a/addons/ui/fnc_addRenamedItem.sqf +++ /dev/null @@ -1,35 +0,0 @@ -#include "script_component.hpp" -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_addRenamedItem - -Description: - Rename an item - -Parameters: - _content - Notifications content (lines). - _line1 - First content line. - _line2 - Second content line. - ... - _lineN - N-th content line (may be passed directly if only 1 line is required). - _text - Text to display or path to .paa or .jpg image (may be passed directly if only text is required). - _size - Text or image size multiplier. (optional, default: 1) - _color - RGB or RGBA color (range 0-1). (optional, default: [1, 1, 1, 1]) - _skippable - Skip or overwrite this notification if another entered the queue. (optional, default: false) - -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]; diff --git a/addons/ui/fnc_getInventoryClassname.sqf b/addons/ui/fnc_getInventoryItemData.sqf similarity index 89% rename from addons/ui/fnc_getInventoryClassname.sqf rename to addons/ui/fnc_getInventoryItemData.sqf index 6b0dfe20f..da174ec1e 100644 --- a/addons/ui/fnc_getInventoryClassname.sqf +++ b/addons/ui/fnc_getInventoryItemData.sqf @@ -1,9 +1,9 @@ #include "script_component.hpp" /* ---------------------------------------------------------------------------- -Internal Function: cba_ui_fnc_getInventoryClassname +Internal Function: cba_ui_fnc_getInventoryItemData Description: - Opens the item context menu on the inventory screen. + Returns item data from inventory display control Parameters: _control - RscDisplayInventory control @@ -14,7 +14,7 @@ Returns: Examples: (begin example) - [_groundContainer, 5] call cba_ui_fnc_getInventoryClassname; + [_groundContainer, 5] call cba_ui_fnc_getInventoryItemData; (end) Author: diff --git a/addons/ui/fnc_initDisplayInventory.sqf b/addons/ui/fnc_initDisplayInventory.sqf index 1772b6596..973e0e2d9 100644 --- a/addons/ui/fnc_initDisplayInventory.sqf +++ b/addons/ui/fnc_initDisplayInventory.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" -// Do nothing if no context menu options exist. -if (isNil QGVAR(ItemContextMenuOptions)) exitWith {}; +// Do nothing if no context menu options and renamed items exist. +if (isNil QGVAR(ItemContextMenuOptions) && {isNil QGVAR(renamedItems)}) exitWith {}; params ["_display"]; @@ -88,132 +88,135 @@ _radioSlot setVariable [QGVAR(slotType), "RADIO"]; _compassSlot setVariable [QGVAR(slotType), "COMPASS"]; _watchSlot setVariable [QGVAR(slotType), "WATCH"]; -{ - _x ctrlAddEventHandler ["MouseButtonDblClick", { - params ["_control", "_button"]; - if (_button != 0) exitWith {}; // LMB only - private _unit = call CBA_fnc_currentUnit; - - private _classname = ""; - private _slotType = _control getVariable QGVAR(slotType); - switch _slotType do { - // containers - case "UNIFORM": { - _classname = uniform _unit; - }; - case "VEST": { - _classname = vest _unit; - }; - case "BACKPACK": { - _classname = backpack _unit; - }; - - // gear - case "HEADGEAR": { - _classname = headgear _unit; - }; - case "GOGGLES": { - _classname = goggles _unit; - }; - case "HMD": { - _classname = hmd _unit; - }; - case "BINOCULAR": { - _classname = binocular _unit; - }; - - // rifle - case "RIFLE": { - _classname = primaryWeapon _unit; - }; - case "RIFLE_SILENCER": { - _classname = primaryWeaponItems _unit select 0; - }; - case "RIFLE_BIPOD": { - _classname = primaryWeaponItems _unit select 3; - }; - case "RIFLE_OPTIC": { - _classname = primaryWeaponItems _unit select 2; - }; - case "RIFLE_POINTER": { - _classname = primaryWeaponItems _unit select 1; - }; - case "RIFLE_MAGAZINE": { - _classname = getUnitLoadout _unit param [0, ["","","","",[],[],""]] select 4 param [0, ""]; - }; - case "RIFLE_MAGAZINE_GL": { - _classname = getUnitLoadout _unit param [0, ["","","","",[],[],""]] select 5 param [0, ""]; - }; - - // launcher - case "LAUNCHER": { - _classname = secondaryWeapon _unit; - }; - case "LAUNCHER_SILENCER": { - _classname = secondaryWeaponItems _unit select 0; - }; - case "LAUNCHER_BIPOD": { - _classname = secondaryWeaponItems _unit select 3; - }; - case "LAUNCHER_OPTIC": { - _classname = secondaryWeaponItems _unit select 2; - }; - case "LAUNCHER_POINTER": { - _classname = secondaryWeaponItems _unit select 1; - }; - case "LAUNCHER_MAGAZINE": { - _classname = secondaryWeaponMagazine _unit select 0; - }; - - // pistol - case "PISTOL": { - _classname = handgunWeapon _unit; - }; - case "PISTOL_SILENCER": { - _classname = handgunItems _unit select 0; - }; - case "PISTOL_BIPOD": { - _classname = handgunItems _unit select 3; - }; - case "PISTOL_OPTIC": { - _classname = handgunItems _unit select 2; - }; - case "PISTOL_POINTER": { - _classname = handgunItems _unit select 1; - }; - case "PISTOL_MAGAZINE": { - _classname = handgunMagazine _unit select 0; - }; - - // items - case "MAP": { - _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 0; - }; - case "GPS": { - _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 1; - }; - case "RADIO": { - _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 2; - }; - case "COMPASS": { - _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 3; - }; - case "WATCH": { - _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 4; - }; - }; - - [ctrlParent _control, _unit, _classname, _slotType] call FUNC(openItemContextMenu); - }]; -} forEach [ - _uniformSlot, _vestSlot, _backpackSlot, - _uniformSlotBackground, _vestSlotBackground, _backpackSlotBackground, - _headgearSlot, _glassesSlot, _hmdSlot, _binocularSlot, - _rifleSlot, _rifleSilencerSlot, _rifleBipodSlot, _rifleOpticSlot, _riflePointerSlot, _rifleMagazine2Slot, _rifleMagazineSlot, - _launcherSlot, _launcherSilencerSlot, _launcherBipodSlot, _launcherOpticSlot, _launcherPointerSlot, _launcherMagazineSlot, - _pistolSlot, _pistolSilencerSlot, _pistolBipodSlot, _pistolOpticSlot, _pistolPointerSlot, _pistolMagazineSlot, - _mapSlot, _gpsSlot, _radioSlot, _compassSlot, _watchSlot -]; +// Item Context Menu Framework - MouseButtonDblClick +if !(isNil QGVAR(ItemContextMenuOptions)) then { + { + _x ctrlAddEventHandler ["MouseButtonDblClick", { + params ["_control", "_button"]; + if (_button != 0) exitWith {}; // LMB only + private _unit = call CBA_fnc_currentUnit; + + private _classname = ""; + private _slotType = _control getVariable QGVAR(slotType); + switch _slotType do { + // containers + case "UNIFORM": { + _classname = uniform _unit; + }; + case "VEST": { + _classname = vest _unit; + }; + case "BACKPACK": { + _classname = backpack _unit; + }; + + // gear + case "HEADGEAR": { + _classname = headgear _unit; + }; + case "GOGGLES": { + _classname = goggles _unit; + }; + case "HMD": { + _classname = hmd _unit; + }; + case "BINOCULAR": { + _classname = binocular _unit; + }; + + // rifle + case "RIFLE": { + _classname = primaryWeapon _unit; + }; + case "RIFLE_SILENCER": { + _classname = primaryWeaponItems _unit select 0; + }; + case "RIFLE_BIPOD": { + _classname = primaryWeaponItems _unit select 3; + }; + case "RIFLE_OPTIC": { + _classname = primaryWeaponItems _unit select 2; + }; + case "RIFLE_POINTER": { + _classname = primaryWeaponItems _unit select 1; + }; + case "RIFLE_MAGAZINE": { + _classname = getUnitLoadout _unit param [0, ["","","","",[],[],""]] select 4 param [0, ""]; + }; + case "RIFLE_MAGAZINE_GL": { + _classname = getUnitLoadout _unit param [0, ["","","","",[],[],""]] select 5 param [0, ""]; + }; + + // launcher + case "LAUNCHER": { + _classname = secondaryWeapon _unit; + }; + case "LAUNCHER_SILENCER": { + _classname = secondaryWeaponItems _unit select 0; + }; + case "LAUNCHER_BIPOD": { + _classname = secondaryWeaponItems _unit select 3; + }; + case "LAUNCHER_OPTIC": { + _classname = secondaryWeaponItems _unit select 2; + }; + case "LAUNCHER_POINTER": { + _classname = secondaryWeaponItems _unit select 1; + }; + case "LAUNCHER_MAGAZINE": { + _classname = secondaryWeaponMagazine _unit select 0; + }; + + // pistol + case "PISTOL": { + _classname = handgunWeapon _unit; + }; + case "PISTOL_SILENCER": { + _classname = handgunItems _unit select 0; + }; + case "PISTOL_BIPOD": { + _classname = handgunItems _unit select 3; + }; + case "PISTOL_OPTIC": { + _classname = handgunItems _unit select 2; + }; + case "PISTOL_POINTER": { + _classname = handgunItems _unit select 1; + }; + case "PISTOL_MAGAZINE": { + _classname = handgunMagazine _unit select 0; + }; + + // items + case "MAP": { + _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 0; + }; + case "GPS": { + _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 1; + }; + case "RADIO": { + _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 2; + }; + case "COMPASS": { + _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 3; + }; + case "WATCH": { + _classname = getUnitLoadout _unit param [9, ["","","","","",""]] select 4; + }; + }; + + [ctrlParent _control, _unit, _classname, _slotType] call FUNC(openItemContextMenu); + }]; + } forEach [ + _uniformSlot, _vestSlot, _backpackSlot, + _uniformSlotBackground, _vestSlotBackground, _backpackSlotBackground, + _headgearSlot, _glassesSlot, _hmdSlot, _binocularSlot, + _rifleSlot, _rifleSilencerSlot, _rifleBipodSlot, _rifleOpticSlot, _riflePointerSlot, _rifleMagazine2Slot, _rifleMagazineSlot, + _launcherSlot, _launcherSilencerSlot, _launcherBipodSlot, _launcherOpticSlot, _launcherPointerSlot, _launcherMagazineSlot, + _pistolSlot, _pistolSilencerSlot, _pistolBipodSlot, _pistolOpticSlot, _pistolPointerSlot, _pistolMagazineSlot, + _mapSlot, _gpsSlot, _radioSlot, _compassSlot, _watchSlot + ]; +}; // Containers private _groundItems = _display displayCtrl IDC_FG_GROUND_ITEMS; @@ -228,41 +231,45 @@ _uniformItems setVariable [QGVAR(containerType), "UNIFORM_CONTAINER"]; _vestItems setVariable [QGVAR(containerType), "VEST_CONTAINER"]; _backpackItems setVariable [QGVAR(containerType), "BACKPACK_CONTAINER"]; -private _controls = []; -_display setVariable [QGVAR(controls), _controls]; - -{ - _controls pushBack _x; - - // 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 [ +private _controls = [ _groundItems, _containerItems, _uniformItems, _vestItems, _backpackItems ]; +_display setVariable [QGVAR(controls), _controls]; -private _fnc_update = { - params ["_display"]; - systemChat str _this; +// Item Context Menu Framework - lbDblClick +if !(isNil QGVAR(ItemContextMenuOptions)) then { + { + _x ctrlAddEventHandler ["lbDblClick", { + params ["_control", "_index"]; + ([_control, _index] call FUNC(getInventoryItemData)) params ["_classname", "_container", "_containerType"]; + [ctrlParent _control, _container, _classname, _containerType] call FUNC(openItemContextMenu); + }]; + } forEach _controls; +}; - { - _x params ["_control"]; - if !(ctrlShown _control) exitWith {}; +// Item Rename Framework +if !(isNil QGVAR(renamedItems)) then { + private _fnc_updateInventoryControls = { + params ["_display"]; - // 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]; + private _control = _x; + + if (ctrlShown _control) then { + for [{_i = 0}, {_i < (lbSize _control)}, {_i = _i + 1}] do { + private _classname = ([_control, _i] call FUNC(getInventoryItemData)) select 0; + private _name = GVAR(renamedItems) getVariable _classname; + + if !(_name isEqualTo "") then { + _control lbSetText [_i, _name]; + }; + }; }; - }; - } forEach (_display getVariable QGVAR(controls)); + } forEach (_display getVariable QGVAR(controls)); + }; + + _display call _fnc_updateInventoryControls; + _display displayAddEventHandler ["MouseMoving", _fnc_updateInventoryControls]; + _display displayAddEventHandler ["MouseHolding", _fnc_updateInventoryControls]; }; -_display displayAddEventHandler ["MouseMoving", _fnc_update]; -_display displayAddEventHandler ["MouseHolding", _fnc_update]; diff --git a/addons/ui/fnc_renameInventoryItem.sqf b/addons/ui/fnc_renameInventoryItem.sqf new file mode 100644 index 000000000..2c6a8afbd --- /dev/null +++ b/addons/ui/fnc_renameInventoryItem.sqf @@ -0,0 +1,37 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_renameInventoryItem + +Description: + Renames inventory item locally + +Parameters: + _class - Item classname. + _name - New item name. + +Examples: + (begin example) + ["DocumentsSecret", "SynixeBrett's secret documents"] call CBA_fnc_renameInventoryItem; + (end) + +Returns: + Nothing + +Authors: + SynixeBrett +---------------------------------------------------------------------------- */ + +params [ + ["_class", "", [""]], + ["_name", "", [""]] +]; + +// Exit if no interface or empty class +if (!hasInterface || {_class isEqualTo ""}) exitWith {}; + +// Create local namespace on first use +if (isNil QGVAR(renamedItems)) then { + GVAR(renamedItems) = false call CBA_fnc_createNamespace; +}; + +GVAR(renamedItems) setVariable [_class, _name]; From 67cdc0044bef4ca86c35c9264b0ef9cd1da228d4 Mon Sep 17 00:00:00 2001 From: SzwedzikPL Date: Tue, 26 May 2020 10:19:21 +0200 Subject: [PATCH 5/8] Add change of picture in renameInventoryItem --- addons/ui/fnc_initDisplayInventory.sqf | 13 ++++++++++--- addons/ui/fnc_renameInventoryItem.sqf | 11 +++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/ui/fnc_initDisplayInventory.sqf b/addons/ui/fnc_initDisplayInventory.sqf index 973e0e2d9..6abac58d2 100644 --- a/addons/ui/fnc_initDisplayInventory.sqf +++ b/addons/ui/fnc_initDisplayInventory.sqf @@ -259,10 +259,17 @@ if !(isNil QGVAR(renamedItems)) then { if (ctrlShown _control) then { for [{_i = 0}, {_i < (lbSize _control)}, {_i = _i + 1}] do { private _classname = ([_control, _i] call FUNC(getInventoryItemData)) select 0; - private _name = GVAR(renamedItems) getVariable _classname; + private _renameParams = GVAR(renamedItems) getVariable [_classname, []]; - if !(_name isEqualTo "") then { - _control lbSetText [_i, _name]; + if !(_renameParams isEqualTo []) then { + _renameParams params ["_name", "_picture"]; + + if !(_name isEqualTo "") then { + _control lbSetText [_i, _name]; + }; + if !(_picture isEqualTo "") then { + _control lbSetPicture [_i, _picture]; + }; }; }; }; diff --git a/addons/ui/fnc_renameInventoryItem.sqf b/addons/ui/fnc_renameInventoryItem.sqf index 2c6a8afbd..114df48e9 100644 --- a/addons/ui/fnc_renameInventoryItem.sqf +++ b/addons/ui/fnc_renameInventoryItem.sqf @@ -8,10 +8,12 @@ Description: Parameters: _class - Item classname. _name - New item name. + _picture - New item picture. Examples: (begin example) ["DocumentsSecret", "SynixeBrett's secret documents"] call CBA_fnc_renameInventoryItem; + ["DocumentsSecret", "SynixeBrett's secret documents", "\a3\Missions_F_Oldman\Props\data\FilesSecret_ca.paa"] call CBA_fnc_renameInventoryItem; (end) Returns: @@ -22,8 +24,9 @@ Authors: ---------------------------------------------------------------------------- */ params [ - ["_class", "", [""]], - ["_name", "", [""]] + ["_class", "", [""]], + ["_name", "", [""]], + ["_picture", "", [""]] ]; // Exit if no interface or empty class @@ -31,7 +34,7 @@ if (!hasInterface || {_class isEqualTo ""}) exitWith {}; // Create local namespace on first use if (isNil QGVAR(renamedItems)) then { - GVAR(renamedItems) = false call CBA_fnc_createNamespace; + GVAR(renamedItems) = false call CBA_fnc_createNamespace; }; -GVAR(renamedItems) setVariable [_class, _name]; +GVAR(renamedItems) setVariable [_class, [_name, _picture]]; From 277a3789038e818e38cd331cbc01526c922400d0 Mon Sep 17 00:00:00 2001 From: SzwedzikPL Date: Sat, 30 May 2020 00:35:14 +0200 Subject: [PATCH 6/8] Fix error on undefined item classname --- addons/ui/fnc_initDisplayInventory.sqf | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/addons/ui/fnc_initDisplayInventory.sqf b/addons/ui/fnc_initDisplayInventory.sqf index 6abac58d2..2ea0c0bb9 100644 --- a/addons/ui/fnc_initDisplayInventory.sqf +++ b/addons/ui/fnc_initDisplayInventory.sqf @@ -259,16 +259,18 @@ if !(isNil QGVAR(renamedItems)) then { if (ctrlShown _control) then { for [{_i = 0}, {_i < (lbSize _control)}, {_i = _i + 1}] do { private _classname = ([_control, _i] call FUNC(getInventoryItemData)) select 0; - private _renameParams = GVAR(renamedItems) getVariable [_classname, []]; - - if !(_renameParams isEqualTo []) then { - _renameParams params ["_name", "_picture"]; - - if !(_name isEqualTo "") then { - _control lbSetText [_i, _name]; - }; - if !(_picture isEqualTo "") then { - _control lbSetPicture [_i, _picture]; + if !(isNil "_classname") then { + private _renameParams = GVAR(renamedItems) getVariable [_classname, []]; + + if !(_renameParams isEqualTo []) then { + _renameParams params ["_name", "_picture"]; + + if !(_name isEqualTo "") then { + _control lbSetText [_i, _name]; + }; + if !(_picture isEqualTo "") then { + _control lbSetPicture [_i, _picture]; + }; }; }; }; From db969b3c085d9a26d096960b362df8701463df64 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 5 Jul 2024 00:50:18 -0500 Subject: [PATCH 7/8] use hashmap, configCase Co-Authored-By: johnb432 <58661205+johnb432@users.noreply.github.com> --- addons/ui/fnc_initDisplayInventory.sqf | 14 +++++++------- addons/ui/fnc_renameInventoryItem.sqf | 10 +++++++--- hemtt.toml | 1 - 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/addons/ui/fnc_initDisplayInventory.sqf b/addons/ui/fnc_initDisplayInventory.sqf index 2ea0c0bb9..fde3556ab 100644 --- a/addons/ui/fnc_initDisplayInventory.sqf +++ b/addons/ui/fnc_initDisplayInventory.sqf @@ -237,10 +237,10 @@ private _controls = [ ]; _display setVariable [QGVAR(controls), _controls]; -// Item Context Menu Framework - lbDblClick +// Item Context Menu Framework - LBDblClick if !(isNil QGVAR(ItemContextMenuOptions)) then { { - _x ctrlAddEventHandler ["lbDblClick", { + _x ctrlAddEventHandler ["LBDblClick", { params ["_control", "_index"]; ([_control, _index] call FUNC(getInventoryItemData)) params ["_classname", "_container", "_containerType"]; [ctrlParent _control, _container, _classname, _containerType] call FUNC(openItemContextMenu); @@ -259,16 +259,16 @@ if !(isNil QGVAR(renamedItems)) then { if (ctrlShown _control) then { for [{_i = 0}, {_i < (lbSize _control)}, {_i = _i + 1}] do { private _classname = ([_control, _i] call FUNC(getInventoryItemData)) select 0; - if !(isNil "_classname") then { - private _renameParams = GVAR(renamedItems) getVariable [_classname, []]; + if (!isNil "_classname") then { + private _renameParams = GVAR(renamedItems) getOrDefault [_classname, []]; - if !(_renameParams isEqualTo []) then { + if (_renameParams isNotEqualTo []) then { _renameParams params ["_name", "_picture"]; - if !(_name isEqualTo "") then { + if (_name != "") then { _control lbSetText [_i, _name]; }; - if !(_picture isEqualTo "") then { + if (_picture != "") then { _control lbSetPicture [_i, _picture]; }; }; diff --git a/addons/ui/fnc_renameInventoryItem.sqf b/addons/ui/fnc_renameInventoryItem.sqf index 114df48e9..790c13027 100644 --- a/addons/ui/fnc_renameInventoryItem.sqf +++ b/addons/ui/fnc_renameInventoryItem.sqf @@ -30,11 +30,15 @@ params [ ]; // Exit if no interface or empty class -if (!hasInterface || {_class isEqualTo ""}) exitWith {}; +if (!hasInterface || {_class == ""}) exitWith {}; // Create local namespace on first use if (isNil QGVAR(renamedItems)) then { - GVAR(renamedItems) = false call CBA_fnc_createNamespace; + GVAR(renamedItems) = createHashMap; }; -GVAR(renamedItems) setVariable [_class, [_name, _picture]]; +private _config = _class call CBA_fnc_getItemConfig; +if (isNull _config) exitWith { ERROR_1("Class [%1] does not exists",_class) }; +_class = configName _config; // Ensure class name is in config case + +GVAR(renamedItems) set [_class, [_name, _picture]]; diff --git a/hemtt.toml b/hemtt.toml index fa9579f0b..2a792dc31 100644 --- a/hemtt.toml +++ b/hemtt.toml @@ -1,7 +1,6 @@ # HEMTT pre v1 name = "CBA_A3" prefix = "cba" -mainprefix = "x" author = "CBATeam" mainprefix = "x" files = [ From 88ba4d4ad15adff6dc7758f08602217c1bd9d549 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Mon, 26 Aug 2024 23:57:51 -0500 Subject: [PATCH 8/8] Apply suggestions from code review Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- addons/ui/fnc_getInventoryItemData.sqf | 9 +-------- addons/ui/fnc_renameInventoryItem.sqf | 2 ++ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/addons/ui/fnc_getInventoryItemData.sqf b/addons/ui/fnc_getInventoryItemData.sqf index da174ec1e..62e76bb2d 100644 --- a/addons/ui/fnc_getInventoryItemData.sqf +++ b/addons/ui/fnc_getInventoryItemData.sqf @@ -45,14 +45,7 @@ switch _containerType do { }; }; -// Reports classname, but only for magazines. +// Reports classname for every item type except backpacks (https://feedback.bistudio.com/T183096) 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] diff --git a/addons/ui/fnc_renameInventoryItem.sqf b/addons/ui/fnc_renameInventoryItem.sqf index 790c13027..94ddf0009 100644 --- a/addons/ui/fnc_renameInventoryItem.sqf +++ b/addons/ui/fnc_renameInventoryItem.sqf @@ -42,3 +42,5 @@ if (isNull _config) exitWith { ERROR_1("Class [%1] does not exists",_class) }; _class = configName _config; // Ensure class name is in config case GVAR(renamedItems) set [_class, [_name, _picture]]; + +nil