Add interaction action on demand (#4079)

* Only use addActionEventHandler when needed

-Only install addActionEventHandler when the interaction menu is
actually open
-Less SQF running each frame,
-it should help with issue #4066

* Cleanup debug
This commit is contained in:
PabstMirror 2016-08-05 12:05:15 -05:00 committed by GitHub
parent dc7ac4c42c
commit 919c8469de
5 changed files with 28 additions and 34 deletions

View File

@ -9,7 +9,6 @@ PREP(collectActiveActionTree);
PREP(createAction); PREP(createAction);
PREP(ctrlSetParsedTextCached); PREP(ctrlSetParsedTextCached);
PREP(findActionNode); PREP(findActionNode);
PREP(handlePlayerChanged);
PREP(isSubPath); PREP(isSubPath);
PREP(keyDown); PREP(keyDown);
PREP(keyUp); PREP(keyUp);

View File

@ -3,6 +3,8 @@
if (!hasInterface) exitWith {}; if (!hasInterface) exitWith {};
GVAR(blockDefaultActions) = [];
GVAR(cachedBuildingTypes) = []; GVAR(cachedBuildingTypes) = [];
GVAR(cachedBuildingActionPairs) = []; GVAR(cachedBuildingActionPairs) = [];
@ -53,9 +55,6 @@ GVAR(ParsedTextCached) = [];
[GVAR(openedMenuType), false] call FUNC(keyUp); [GVAR(openedMenuType), false] call FUNC(keyUp);
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
// disable firing while the interact menu is is is opened
["unit", FUNC(handlePlayerChanged)] call CBA_fnc_addPlayerEventHandler;
// background options // background options
["ace_interactMenuOpened", { ["ace_interactMenuOpened", {
if (GVAR(menuBackground)==1) then {[QGVAR(menuBackground), true] call EFUNC(common,blurScreen);}; if (GVAR(menuBackground)==1) then {[QGVAR(menuBackground), true] call EFUNC(common,blurScreen);};

View File

@ -1,30 +0,0 @@
/*
* Author: commy2
* Disables firing while the menu is opened. Called from playerChanged eh.
*
* Arguments:
* 0: New unit to add the addAction eh <OBJECT>
* 1: Old unit to remove the addAction eh <STRING>
*
* Return Value:
* None
*/
#include "script_component.hpp"
params ["_newUnit", "_oldUnit"];
// add to new unit
private _ehid = [_newUnit, "DefaultAction", {GVAR(openedMenuType) >= 0}, {
if (!GVAR(actionOnKeyRelease) && GVAR(actionSelected)) then {
[GVAR(openedMenuType),true] call FUNC(keyUp);
};
}] call EFUNC(common,addActionEventHandler);
_newUnit setVariable [QGVAR(AAEHID), _ehid];
// remove from old unit
_ehid = _oldUnit getVariable [QGVAR(AAEHID), -1];
[_oldUnit, "DefaultAction", _ehid] call EFUNC(common,removeActionEventHandler);
_oldUnit setVariable [QGVAR(AAEHID), -1];

View File

@ -104,4 +104,22 @@ if (GVAR(openedMenuType) == 0) then {
["ace_interactMenuOpened", [_menuType]] call CBA_fnc_localEvent; ["ace_interactMenuOpened", [_menuType]] call CBA_fnc_localEvent;
//Remove the old "DefaultAction" action event handler if it already exists
GVAR(blockDefaultActions) params [["_player", objNull], ["_ehid", -1]];
TRACE_2("blockDefaultActions",_player,_ehid);
if (!isNull _player) then {
[_player, "DefaultAction", _ehid] call EFUNC(common,removeActionEventHandler);
GVAR(blockDefaultActions) = [];
};
//Add the "DefaultAction" action event handler
if (alive ACE_player) then {
private _ehid = [ACE_player, "DefaultAction", {GVAR(openedMenuType) >= 0}, {
if (!GVAR(actionOnKeyRelease) && GVAR(actionSelected)) then {
[GVAR(openedMenuType),true] call FUNC(keyUp);
};
}] call EFUNC(common,addActionEventHandler);
TRACE_2("Added",ACE_player,_ehid);
GVAR(blockDefaultActions) = [ACE_player, _ehid];
};
true true

View File

@ -46,6 +46,14 @@ if(GVAR(actionSelected)) then {
["ace_interactMenuClosed", [GVAR(openedMenuType)]] call CBA_fnc_localEvent; ["ace_interactMenuClosed", [GVAR(openedMenuType)]] call CBA_fnc_localEvent;
//Remove the "DefaultAction" action event handler
GVAR(blockDefaultActions) params [["_player", objNull], ["_ehid", -1]];
TRACE_2("blockDefaultActions",_player,_ehid);
if (!isNull _player) then {
[_player, "DefaultAction", _ehid] call EFUNC(common,removeActionEventHandler);
GVAR(blockDefaultActions) = [];
};
GVAR(keyDown) = false; GVAR(keyDown) = false;
GVAR(keyDownSelfAction) = false; GVAR(keyDownSelfAction) = false;
GVAR(openedMenuType) = -1; GVAR(openedMenuType) = -1;