From 08472f63437a5619a56e55a7bddb976fc5a77b00 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Thu, 4 Feb 2021 21:01:35 +0400 Subject: [PATCH] Interact Menu - Combine parent menu with single child (#8060) * Combine parent menu with single child * Adapt fastroping Cut ropes action for the setting * Change setting name and description * Fix action object when child action has different object Co-authored-by: PabstMirror * Adapt quickmount Change Seat actions Co-authored-by: PabstMirror --- addons/chemlights/CfgVehicles.hpp | 5 +-- addons/fastroping/CfgVehicles.hpp | 5 +-- .../functions/fnc_collectActiveActionTree.sqf | 32 +++++++++++++++++-- addons/interact_menu/initSettings.sqf | 8 +++++ addons/interact_menu/stringtable.xml | 8 +++++ addons/map/CfgVehicles.hpp | 6 ++-- addons/quickmount/CfgVehicles.hpp | 3 +- .../functions/fnc_canShowFreeSeats.sqf | 12 ++++--- 8 files changed, 61 insertions(+), 18 deletions(-) diff --git a/addons/chemlights/CfgVehicles.hpp b/addons/chemlights/CfgVehicles.hpp index 02856b99e7..e01fb79b87 100644 --- a/addons/chemlights/CfgVehicles.hpp +++ b/addons/chemlights/CfgVehicles.hpp @@ -9,11 +9,8 @@ class CfgVehicles { class ACE_Chemlights { displayName = CSTRING(Action_Chemlights); icon = "\a3\ui_f\data\gui\cfg\Hints\chemlights_ca.paa"; - condition = QUOTE(count ([ACE_player] call FUNC(getShieldComponents)) > 0); - statement = "true"; exceptions[] = {"isNotDragging", "isNotSwimming", "notOnMap", "isNotInside", "isNotSitting"}; - insertChildren = QUOTE(_this call DFUNC(compileChemlightMenu)); - showDisabled = 0; + insertChildren = QUOTE(call DFUNC(compileChemlightMenu)); }; }; }; diff --git a/addons/fastroping/CfgVehicles.hpp b/addons/fastroping/CfgVehicles.hpp index 2a130b37f9..24f996d825 100644 --- a/addons/fastroping/CfgVehicles.hpp +++ b/addons/fastroping/CfgVehicles.hpp @@ -75,8 +75,9 @@ class CfgVehicles { }; class ACE_cutRopes { displayName = CSTRING(Interaction_cutRopes); - condition = QUOTE(true); - statement = ""; + condition = QUOTE([_target] call FUNC(canCutRopes)); + // should not be empty to work with EGVAR(interact_menu,consolidateSingleChild) setting + statement = QUOTE(true); class confirmCutRopes { displayName = ECSTRING(common,confirm); condition = QUOTE([_target] call FUNC(canCutRopes)); diff --git a/addons/interact_menu/functions/fnc_collectActiveActionTree.sqf b/addons/interact_menu/functions/fnc_collectActiveActionTree.sqf index e7fecfcac8..a59a7ff787 100644 --- a/addons/interact_menu/functions/fnc_collectActiveActionTree.sqf +++ b/addons/interact_menu/functions/fnc_collectActiveActionTree.sqf @@ -13,7 +13,7 @@ * Active children * * Example: - * [bob, [array], [array], 5] call ACE_interact_menu_fnc_collectActoveActionTree + * [bob, [array], [array], 5] call ACE_interact_menu_fnc_collectActiveActionTree * * Public: No */ @@ -31,7 +31,17 @@ if !((_origActionData select 10) isEqualTo {}) then { [_target, ACE_player, _origActionData select 6, _origActionData] call (_origActionData select 10); }; -_origActionData params ["_actionName", "", "", "_statementCode", "_conditionCode", "_insertChildrenCode", "_customParams", "", "_distance"]; +_origActionData params [ + "_actionName", + "_displayName", + "", + "_statementCode", + "_conditionCode", + "_insertChildrenCode", + "_customParams", + "_position", + "_distance" +]; // Return nothing if the action itself is not active if !([_target, ACE_player, _customParams] call _conditionCode) exitWith { @@ -91,5 +101,23 @@ if ((_activeChildren isEqualTo []) && {_statementCode isEqualTo {}}) exitWith { [] }; +if (GVAR(consolidateSingleChild) && {count _activeChildren == 1} && {_statementCode isEqualTo {}}) then { + _activeChildren select 0 params ["_childActionData", "_childChildren", "_childObject"]; + _childActionData params ["", "_displayNameChild", "_iconChild", "_statementChild", "", "", "_customParamsChild", "", "", "_paramsChild"]; + _origActionData = [ + _actionName, + format ["%1 > %2", _displayName, _displayNameChild], + _iconChild, + _statementChild, + _conditionCode, + _insertChildrenCode, + _customParamsChild, + _position, + _distance, + _paramsChild + ]; + _activeChildren = _childChildren; + _object = _childObject; +}; [_origActionData, _activeChildren, _object] diff --git a/addons/interact_menu/initSettings.sqf b/addons/interact_menu/initSettings.sqf index 8d353906f6..6b58196f07 100644 --- a/addons/interact_menu/initSettings.sqf +++ b/addons/interact_menu/initSettings.sqf @@ -8,6 +8,14 @@ {GVAR(selectorColorHex) = _this call BIS_fnc_colorRGBtoHTML} // Stored in Hex to avoid constant conversion ] call CBA_settings_fnc_init; +[ + QGVAR(consolidateSingleChild), + "CHECKBOX", + [LSTRING(consolidateSingleChild), LSTRING(consolidateSingleChild_Description)], + format ["ACE %1", LLSTRING(Category_InteractionMenu)], + false +] call CBA_fnc_addSetting; + [ QGVAR(alwaysUseCursorInteraction), "CHECKBOX", diff --git a/addons/interact_menu/stringtable.xml b/addons/interact_menu/stringtable.xml index 106fb1aebc..4da4d9ae35 100644 --- a/addons/interact_menu/stringtable.xml +++ b/addons/interact_menu/stringtable.xml @@ -489,5 +489,13 @@ Selector de color Seçici Renk + + Consolidate single child actions + Объединять с единственным дочерним действием + + + Combines parent action with only one child action together. + Объединять родительское действие с единственным дочерним действием в одно. + diff --git a/addons/map/CfgVehicles.hpp b/addons/map/CfgVehicles.hpp index 3da69a1216..181978551a 100644 --- a/addons/map/CfgVehicles.hpp +++ b/addons/map/CfgVehicles.hpp @@ -5,11 +5,9 @@ class CfgVehicles { class ACE_MapFlashlight { displayName = CSTRING(Action_Flashlights); icon = QUOTE(\a3\ui_f\data\IGUI\Cfg\VehicleToggles\lightsiconon_ca.paa); - condition = QUOTE(GVAR(mapIllumination) && visibleMap && {!([] isEqualTo (_player call FUNC(getUnitFlashlights)))}); - statement = "true"; + condition = QUOTE(GVAR(mapIllumination) && visibleMap); exceptions[] = {"isNotDragging", "notOnMap", "isNotInside", "isNotSitting"}; - insertChildren = QUOTE(_this call DFUNC(compileFlashlightMenu)); - showDisabled = 0; + insertChildren = QUOTE(call DFUNC(compileFlashlightMenu)); }; }; }; diff --git a/addons/quickmount/CfgVehicles.hpp b/addons/quickmount/CfgVehicles.hpp index a0b54df48b..f58cb5df33 100644 --- a/addons/quickmount/CfgVehicles.hpp +++ b/addons/quickmount/CfgVehicles.hpp @@ -51,8 +51,7 @@ class CfgVehicles { class GVAR(ChangeSeat) { \ displayName = CSTRING(ChangeSeat); \ condition = QUOTE(call DFUNC(canShowFreeSeats)); \ - statement = ""; \ - insertChildren = QUOTE((_this select 2) param [ARR_2(0, [])]); \ + insertChildren = QUOTE(call DFUNC(addFreeSeatsActions)); \ }; \ } diff --git a/addons/quickmount/functions/fnc_canShowFreeSeats.sqf b/addons/quickmount/functions/fnc_canShowFreeSeats.sqf index 506dbd78ac..8fd2f9c840 100644 --- a/addons/quickmount/functions/fnc_canShowFreeSeats.sqf +++ b/addons/quickmount/functions/fnc_canShowFreeSeats.sqf @@ -19,7 +19,6 @@ params ["_vehicle", "_unit", "_args"]; -_args set [0, []]; private _isInVehicle = _unit in _vehicle; GVAR(enabled) @@ -40,7 +39,12 @@ GVAR(enabled) || {_vehicle isKindOf "Air"} // except Air } && { - private _subActions = _this call FUNC(addFreeSeatsActions); - _args set [0, _subActions]; - !([] isEqualTo _subActions) + _isInVehicle + || { + // because Get In action has its own statement + // we have to cache subactions in args and reuse them in insertChildren code + private _subActions = _this call FUNC(addFreeSeatsActions); + _args set [0, _subActions]; + !([] isEqualTo _subActions) + } }