Interact Menu - Use hashmaps for interactions (#9920)

* Use hashmaps for interactions

* Update addons/interact_menu/functions/fnc_splitPath.sqf

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* Account for case sensitivity

* Update addons/interact_menu/functions/fnc_compileMenu.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Update addons/interact_menu/functions/fnc_compileMenuSelfAction.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

---------

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
johnb432 2024-05-22 03:18:32 +02:00 committed by GitHub
parent db2bf60c28
commit 4cf61a026b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 46 additions and 59 deletions

View File

@ -3,16 +3,16 @@
if (!hasInterface) exitWith {};
// Wait until player controls (man,vehicle or uav) a thing before compiling the menu
GVAR(controllableSelfActionsAdded) = [] call CBA_fnc_createNamespace;
GVAR(controllableSelfActionsAdded) = createHashMap;
DFUNC(newControllableObject) = {
params ["_object"];
private _type = typeOf _object;
TRACE_2("newControllableObject",_object,_type);
if (_type == "") exitWith {};
if (!(GVAR(controllableSelfActionsAdded) getVariable [_type, false])) then {
if !(_type in GVAR(controllableSelfActionsAdded)) then {
[_type] call FUNC(compileMenuSelfAction);
GVAR(controllableSelfActionsAdded) setVariable [_type, true];
GVAR(controllableSelfActionsAdded) set [_type, nil];
[{
TRACE_1("sending newControllableObject event",_this);
// event for other systems to add self actions, running addActionToClass before this will cause compiling
@ -27,8 +27,7 @@ DFUNC(newControllableObject) = {
GVAR(blockDefaultActions) = [];
GVAR(cachedBuildingTypes) = [];
GVAR(cachedBuildingActionPairs) = [];
GVAR(cachedBuildingTypes) = createHashMap;
GVAR(ParsedTextCached) = [];

View File

@ -12,12 +12,12 @@ if (!hasInterface) exitWith { ADDON = true; };
["All", "init", LINKFUNC(compileMenu)] call CBA_fnc_addClassEventHandler;
GVAR(ActNamespace) = [] call CBA_fnc_createNamespace;
GVAR(ActSelfNamespace) = [] call CBA_fnc_createNamespace;
GVAR(ActNamespace) = createHashMap;
GVAR(ActSelfNamespace) = createHashMap;
// Compile actions for CAManBase now and use for all mans types
["CAManBase"] call FUNC(compileMenu);
GVAR(cacheManActions) = +(GVAR(ActNamespace) getVariable ["CAManBase", []]); // copy
GVAR(cacheManActions) = +(GVAR(ActNamespace) getOrDefault ["CAManBase" call EFUNC(common,getConfigName), []]); // copy
// Event handlers for all interact menu controls
DFUNC(handleMouseMovement) = {

View File

@ -48,6 +48,8 @@ if (param [4, false, [false]]) exitwith {
(_parentPath + [_action select 0])
};
_objectType = _objectType call EFUNC(common,getConfigName);
// Ensure the config menu was compiled first
if (_typeNum == 0) then {
[_objectType] call FUNC(compileMenu);
@ -56,18 +58,14 @@ if (_typeNum == 0) then {
};
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
private _actionTrees = _namespace getVariable _objectType;
if (isNil "_actionTrees") then {
_actionTrees = [];
_namespace setVariable [_objectType, _actionTrees];
};
private _actionTrees = _namespace getOrDefault [_objectType, [], true];
if (_parentPath isEqualTo ["ACE_MainActions"]) then {
[_objectType, _typeNum] call FUNC(addMainAction);
};
private _parentNode = [_actionTrees, _parentPath] call FUNC(findActionNode);
if (isNil {_parentNode}) exitWith {
if (isNil "_parentNode") exitWith {
ERROR_4("Failed to add action - action (%1) to parent %2 on object %3 [%4]",(_action select 0),_parentPath,_objectType,_typeNum);
[]
};

View File

@ -19,14 +19,10 @@
params ["_objectType", "_typeNum"];
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
private _actionTrees = _namespace getVariable _objectType;
if (isNil "_actionTrees") then {
_actionTrees = [];
};
private _actionTrees = _namespace getOrDefault [_objectType, []];
private _parentNode = [_actionTrees, ["ACE_MainActions"]] call FUNC(findActionNode);
if (isNil {_parentNode}) then {
if (isNil "_parentNode") then {
TRACE_2("No Main Action on object",_objectType,_typeNum);
private _mainAction = ["ACE_MainActions", localize ELSTRING(interaction,MainAction), "", {}, {true}] call FUNC(createAction);
[_objectType, _typeNum, [], _mainAction] call EFUNC(interact_menu,addActionToClass);

View File

@ -17,22 +17,22 @@
params ["_target"];
private _objectType = _target;
if (_target isEqualType objNull) then {
_objectType = typeOf _target;
private _objectType = if (_target isEqualType objNull) then {
typeOf _target
} else {
_target call EFUNC(common,getConfigName)
};
private _namespace = GVAR(ActNamespace);
// Exit if the action menu is already compiled for this class
if (!isNil {_namespace getVariable _objectType}) exitWith {};
if (_objectType in GVAR(ActNamespace)) exitWith {};
if (_objectType isKindOf "VirtualMan_F") exitWith { // these have config: isPlayableLogic = 1
TRACE_1("skipping playable logic",_objectType);
_namespace setVariable [_objectType, []];
GVAR(ActNamespace) set [_objectType, []];
};
if ((_objectType isKindOf "CAManBase") && {!isNil QGVAR(cacheManActions)}) exitWith {
_namespace setVariable [_objectType, +GVAR(cacheManActions)]; // copy
GVAR(ActNamespace) set [_objectType, +GVAR(cacheManActions)]; // copy
};
private _recurseFnc = {
@ -139,7 +139,7 @@ if (_objectType isKindOf "CAManBase") then {
};
};
_namespace setVariable [_objectType, _actions];
GVAR(ActNamespace) set [_objectType, _actions];
/*
[

View File

@ -17,15 +17,14 @@
params ["_target"];
private _objectType = _target;
if (_target isEqualType objNull) then {
_objectType = typeOf _target;
private _objectType = if (_target isEqualType objNull) then {
typeOf _target
} else {
_target call EFUNC(common,getConfigName)
};
private _namespace = GVAR(ActSelfNamespace);
// Exit if the action menu is already compiled for this class
if (!isNil {_namespace getVariable _objectType}) exitWith {};
if (_objectType in GVAR(actSelfNamespace)) exitWith {};
private _recurseFnc = {
params ["_actionsCfg"];
@ -131,4 +130,4 @@ private _actions = [
]
];
_namespace setVariable [_objectType, _actions];
GVAR(ActSelfNamespace) set [_objectType, _actions];

View File

@ -17,7 +17,7 @@
params ["_class"];
private _actionTrees = GVAR(ActSelfNamespace) getVariable _class;
private _actionTrees = GVAR(ActSelfNamespace) get _class;
private _rootNode = [_actionTrees, ["ACE_SelfActions"]] call FUNC(findActionNode);
private _rootActions = _rootNode select 1;
private _settingCategoryPrefix = format ["ACE %1 - ", LELSTRING(Interaction,InteractionMenuSelf)];

View File

@ -19,17 +19,16 @@
params ["_objectType", "_typeNum", "_fullPath"];
_objectType = _objectType call EFUNC(common,getConfigName);
private _res = _fullPath call FUNC(splitPath);
_res params ["_parentPath", "_actionName"];
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
private _actionTrees = _namespace getVariable _objectType;
if (isNil "_actionTrees") then {
_actionTrees = [];
};
private _actionTrees = _namespace getOrDefault [_objectType, []];
private _parentNode = [_actionTrees, _parentPath] call FUNC(findActionNode);
if (isNil {_parentNode}) exitWith {};
if (isNil "_parentNode") exitWith {};
// Iterate through children of the father
private _found = false;

View File

@ -61,7 +61,7 @@ private _fnc_renderNearbyActions = {
} forEach GVAR(objectActionList);
// Iterate through base level class actions and render them if appropiate
private _classActions = GVAR(ActNamespace) getVariable [typeOf _target, []];
private _classActions = GVAR(ActNamespace) getOrDefault [typeOf _target, []];
{
private _action = _x;
// Try to render the menu
@ -95,8 +95,7 @@ private _fnc_renderSelfActions = {
GVAR(objectActionList) = _target getVariable [QGVAR(selfActions), []];
// Iterate through base level class actions and render them if appropiate
private _namespace = GVAR(ActSelfNamespace);
private _classActions = _namespace getVariable typeOf _target;
private _classActions = GVAR(ActSelfNamespace) get typeOf _target;
private _pos = if !(GVAR(useCursorMenu)) then {
//Convert to ASL, add offset and then convert back to AGL (handles waves when over water)

View File

@ -17,11 +17,13 @@
*/
private _parentPath = [];
for [{private _i = 0},{_i < (count _this) - 1},{_i = _i + 1}] do {
_parentPath pushBack (_this select _i);
};
private _actionName = if (count _this > 0) then {
_this select ((count _this) - 1);
_parentPath append _this;
private _count = count _this;
private _actionName = if (_count > 0) then {
_parentPath deleteAt (_count - 1) // TODO: replace with _parentPath deleteAt [-1] and drop _count in 2.18
} else {
""
};

View File

@ -17,8 +17,9 @@
params ["_typeOfBuilding"];
private _searchIndex = GVAR(cachedBuildingTypes) find _typeOfBuilding;
if (_searchIndex != -1) exitWith {GVAR(cachedBuildingActionPairs) select _searchIndex};
private _cachedMemPoints = GVAR(cachedBuildingTypes) get _typeOfBuilding;
if (!isNil "_cachedMemPoints") exitWith {_cachedMemPoints};
private _memPoints = [];
private _memPointsActions = [];
@ -148,8 +149,6 @@ private _ladders = getArray (configFile >> "CfgVehicles" >> _typeOfBuilding >> "
} forEach _ladders;
GVAR(cachedBuildingTypes) pushBack _typeOfBuilding;
GVAR(cachedBuildingActionPairs) pushBack [_memPoints, _memPointsActions];
GVAR(cachedBuildingTypes) set [_typeOfBuilding, [_memPoints, _memPointsActions]];
[_memPoints, _memPointsActions]

View File

@ -20,11 +20,7 @@
params ["", "", "_parameters"];
_parameters params ["_unit"];
private _namespace = EGVAR(interact_menu,ActNamespace);
private _actionTrees = _namespace getVariable typeOf _unit;
if (isNil "_actionTrees") then {
_actionTrees = [];
};
private _actionTrees = EGVAR(interact_menu,ActNamespace) getOrDefault [typeOf _unit, []];
private _actions = [];