Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interact Menu - Use hashmaps for interactions #9920

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions addons/interact_menu/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,8 +27,7 @@ DFUNC(newControllableObject) = {

GVAR(blockDefaultActions) = [];

GVAR(cachedBuildingTypes) = [];
GVAR(cachedBuildingActionPairs) = [];
GVAR(cachedBuildingTypes) = createHashMap;

GVAR(ParsedTextCached) = [];

Expand Down
6 changes: 3 additions & 3 deletions addons/interact_menu/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better safe than sorry, I guess

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, in case, somehow, a mod managed to change it - highly unlikely, so we could probably remove it.


// Event handlers for all interact menu controls
DFUNC(handleMouseMovement) = {
Expand Down
10 changes: 4 additions & 6 deletions addons/interact_menu/functions/fnc_addActionToClass.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved

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);
[]
};
Expand Down
8 changes: 2 additions & 6 deletions addons/interact_menu/functions/fnc_addMainAction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions addons/interact_menu/functions/fnc_compileMenu.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
_objectType call EFUNC(common,getConfigName)
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
};
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 = {
Expand Down Expand Up @@ -140,7 +140,7 @@ if (_objectType isKindOf "CAManBase") then {
};
};

_namespace setVariable [_objectType, _actions];
GVAR(ActNamespace) set [_objectType, _actions];

/*
[
Expand Down
13 changes: 6 additions & 7 deletions addons/interact_menu/functions/fnc_compileMenuSelfAction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
_objectType call EFUNC(common,getConfigName)
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
};
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"];
Expand Down Expand Up @@ -132,4 +131,4 @@ private _actions = [
]
];

_namespace setVariable [_objectType, _actions];
GVAR(ActSelfNamespace) set [_objectType, _actions];
2 changes: 1 addition & 1 deletion addons/interact_menu/functions/fnc_initMenuReorder.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
9 changes: 4 additions & 5 deletions addons/interact_menu/functions/fnc_removeActionFromClass.sqf
Copy link
Contributor

@LinkIsGrim LinkIsGrim Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not public so it doesn't matter, but this does have some 3rd party use and will become case-sensitive

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions addons/interact_menu/functions/fnc_renderActionPoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions addons/interact_menu/functions/fnc_splitPath.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
""
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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]
6 changes: 1 addition & 5 deletions addons/interaction/functions/fnc_addPassengerActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down