From ff5eb34e1060e1632c9c11239485eeb1dd3d8bf3 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 31 Jan 2019 19:25:16 -0600 Subject: [PATCH] Interaction Menu - Only compile self actions when needed (#6792) * Interaction Menu - Only compile self actions when needed * Update XEH_clientInit.sqf * fix spellling * format/comments * Don't compile actions on headless servers * Update addons/zeus/XEH_postInit.sqf Co-Authored-By: PabstMirror --- addons/interact_menu/CfgEventHandlers.hpp | 8 ------- addons/interact_menu/XEH_clientInit.sqf | 23 +++++++++++++++++++ addons/interact_menu/XEH_preInit.sqf | 4 ++++ .../functions/fnc_addActionToClass.sqf | 1 + .../functions/fnc_addActionToObject.sqf | 1 + .../functions/fnc_addActionToZeus.sqf | 1 + .../functions/fnc_createAction.sqf | 1 + addons/zeus/XEH_postInit.sqf | 18 ++++++++++----- 8 files changed, 43 insertions(+), 14 deletions(-) diff --git a/addons/interact_menu/CfgEventHandlers.hpp b/addons/interact_menu/CfgEventHandlers.hpp index b8bb1264e1..b5880fb05b 100644 --- a/addons/interact_menu/CfgEventHandlers.hpp +++ b/addons/interact_menu/CfgEventHandlers.hpp @@ -17,14 +17,6 @@ class Extended_PostInit_EventHandlers { }; }; -class Extended_InitPost_EventHandlers { - class All { - class GVAR(compileMenu) { - init = QUOTE(_this call FUNC(compileMenu);_this call FUNC(compileMenuSelfAction)); - }; - }; -}; - class Extended_DisplayLoad_EventHandlers { class RscDiary { ADDON = QUOTE(call COMPILE_FILE(XEH_displayLoad)); diff --git a/addons/interact_menu/XEH_clientInit.sqf b/addons/interact_menu/XEH_clientInit.sqf index d6d5cd065c..9a44674e42 100644 --- a/addons/interact_menu/XEH_clientInit.sqf +++ b/addons/interact_menu/XEH_clientInit.sqf @@ -2,6 +2,29 @@ if (!hasInterface) exitWith {}; +// Wait until player controls (man,vehicle or uav) a thing before compiling the menu +GVAR(controllableSelfActionsAdded) = [] call CBA_fnc_createNamespace; +DFUNC(newControllableObject) = { + params ["_object"]; + private _type = typeOf _object; + TRACE_2("newControllableObject",_object,_type); + if (_type == "") exitWith {}; + + if (!(GVAR(controllableSelfActionsAdded) getVariable [_type, false])) then { + [_type] call FUNC(compileMenuSelfAction); + GVAR(controllableSelfActionsAdded) setVariable [_type, true]; + [{ + TRACE_1("sending newControllableObject event",_this); + // event for other systems to add self actions, running addActionToClass before this will cause compiling + [QGVAR(newControllableObject), _this] call CBA_fnc_localEvent; + }, [_type]] call CBA_fnc_execNextFrame; // delay event a frame to ensure postInit has run for all addons + }; +}; +["unit", {[_this select 0] call FUNC(newControllableObject)}, true] call CBA_fnc_addPlayerEventHandler; +["vehicle", {[_this select 1] call FUNC(newControllableObject)}, true] call CBA_fnc_addPlayerEventHandler; +["ACE_controlledUAV", {[_this select 0] call FUNC(newControllableObject)}] call CBA_fnc_addEventHandler; + + GVAR(blockDefaultActions) = []; GVAR(cachedBuildingTypes) = []; diff --git a/addons/interact_menu/XEH_preInit.sqf b/addons/interact_menu/XEH_preInit.sqf index a05eac1bb5..1524ccb504 100644 --- a/addons/interact_menu/XEH_preInit.sqf +++ b/addons/interact_menu/XEH_preInit.sqf @@ -8,6 +8,10 @@ PREP_RECOMPILE_END; #include "initSettings.sqf" +if (!hasInterface) exitWith { ADDON = true; }; + +["All", "init", {_this call FUNC(compileMenu)}] call CBA_fnc_addClassEventHandler; + GVAR(ActNamespace) = [] call CBA_fnc_createNamespace; GVAR(ActSelfNamespace) = [] call CBA_fnc_createNamespace; diff --git a/addons/interact_menu/functions/fnc_addActionToClass.sqf b/addons/interact_menu/functions/fnc_addActionToClass.sqf index 558c497667..20c229bfc6 100644 --- a/addons/interact_menu/functions/fnc_addActionToClass.sqf +++ b/addons/interact_menu/functions/fnc_addActionToClass.sqf @@ -20,6 +20,7 @@ * Public: Yes */ +if (!hasInterface) exitWith { [] }; if (!params [["_objectType", "", [""]], ["_typeNum", 0, [0]], ["_parentPath", [], [[]]], ["_action", [], [[]], 11]]) exitWith { ERROR("Bad Params"); [] diff --git a/addons/interact_menu/functions/fnc_addActionToObject.sqf b/addons/interact_menu/functions/fnc_addActionToObject.sqf index 3ee7c5c332..f3102469a5 100644 --- a/addons/interact_menu/functions/fnc_addActionToObject.sqf +++ b/addons/interact_menu/functions/fnc_addActionToObject.sqf @@ -19,6 +19,7 @@ * Public: Yes */ +if (!hasInterface) exitWith { [] }; if (!params [["_object", objNull, [objNull]], ["_typeNum", 0, [0]], ["_parentPath", [], [[]]], ["_action", [], [[]], 11]]) exitWith { ERROR("Bad Params"); [] diff --git a/addons/interact_menu/functions/fnc_addActionToZeus.sqf b/addons/interact_menu/functions/fnc_addActionToZeus.sqf index 65ef178fb0..538ea5fe16 100644 --- a/addons/interact_menu/functions/fnc_addActionToZeus.sqf +++ b/addons/interact_menu/functions/fnc_addActionToZeus.sqf @@ -17,6 +17,7 @@ * Public: Yes */ +if (!hasInterface) exitWith { [] }; if (!params [["_parentPath", [], [[]]], ["_action", [], [[]], 11]]) exitWith {ERROR("Bad Params"); []}; if ((_parentPath param [0, ""]) != "ACE_ZeusActions") exitWith {ERROR_1("Bad path %1 - should have ACE_ZeusActions as base", _parentPath); []}; TRACE_2("addActionToZeus",_parentPath,_action); diff --git a/addons/interact_menu/functions/fnc_createAction.sqf b/addons/interact_menu/functions/fnc_createAction.sqf index f8c61c3842..428f8a26d7 100644 --- a/addons/interact_menu/functions/fnc_createAction.sqf +++ b/addons/interact_menu/functions/fnc_createAction.sqf @@ -28,6 +28,7 @@ // IGNORE_PRIVATE_WARNING(_actionName,_displayName,_icon,_statement,_condition,_insertChildren,_customParams,_position,_distance,_params,_modifierFunction); +if (!hasInterface) exitWith { [] }; params [ "_actionName", "_displayName", diff --git a/addons/zeus/XEH_postInit.sqf b/addons/zeus/XEH_postInit.sqf index 85527f0ab2..a6b77df6c3 100644 --- a/addons/zeus/XEH_postInit.sqf +++ b/addons/zeus/XEH_postInit.sqf @@ -82,7 +82,12 @@ if (hasInterface) then { [localize "str_a3_cfgvehicles_moduletasksetstate_f_arguments_state_values_created_0"] call EFUNC(common,displayTextStructured); }] call CBA_fnc_addEventHandler; - private _action = [ + [QEGVAR(interact_menu,newControllableObject), { + params ["_type"]; + if (!(_type isKindOf "CAManBase")) exitWith {}; + TRACE_1("Adding zeus actions",_type); + + private _action = [ QGVAR(create), LLSTRING(CreateZeus), "\A3\Ui_F_Curator\Data\Logos\arma3_curator_eye_32_ca.paa", @@ -99,10 +104,10 @@ if (hasInterface) then { } && {isNil QGVAR(zeus)} } - ] call EFUNC(interact_menu,createAction); - ["CAManBase", 1, ["ACE_SelfActions"], _action, true] call EFUNC(interact_menu,addActionToClass); + ] call EFUNC(interact_menu,createAction); + [_type, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToClass); - _action = [ + _action = [ QGVAR(delete), LLSTRING(DeleteZeus), "\A3\Ui_F_Curator\Data\Logos\arma3_curator_eye_32_ca.paa", @@ -111,6 +116,7 @@ if (hasInterface) then { GVAR(zeus) = nil; }, {!(isNil QGVAR(zeus) || {isNull GVAR(zeus)})} - ] call EFUNC(interact_menu,createAction); - ["CAManBase", 1, ["ACE_SelfActions"], _action, true] call EFUNC(interact_menu,addActionToClass); + ] call EFUNC(interact_menu,createAction); + [_type, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToClass); + }] call CBA_fnc_addEventHandler; };