mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
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:
parent
db2bf60c28
commit
4cf61a026b
@ -3,16 +3,16 @@
|
|||||||
if (!hasInterface) exitWith {};
|
if (!hasInterface) exitWith {};
|
||||||
|
|
||||||
// Wait until player controls (man,vehicle or uav) a thing before compiling the menu
|
// 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) = {
|
DFUNC(newControllableObject) = {
|
||||||
params ["_object"];
|
params ["_object"];
|
||||||
private _type = typeOf _object;
|
private _type = typeOf _object;
|
||||||
TRACE_2("newControllableObject",_object,_type);
|
TRACE_2("newControllableObject",_object,_type);
|
||||||
if (_type == "") exitWith {};
|
if (_type == "") exitWith {};
|
||||||
|
|
||||||
if (!(GVAR(controllableSelfActionsAdded) getVariable [_type, false])) then {
|
if !(_type in GVAR(controllableSelfActionsAdded)) then {
|
||||||
[_type] call FUNC(compileMenuSelfAction);
|
[_type] call FUNC(compileMenuSelfAction);
|
||||||
GVAR(controllableSelfActionsAdded) setVariable [_type, true];
|
GVAR(controllableSelfActionsAdded) set [_type, nil];
|
||||||
[{
|
[{
|
||||||
TRACE_1("sending newControllableObject event",_this);
|
TRACE_1("sending newControllableObject event",_this);
|
||||||
// event for other systems to add self actions, running addActionToClass before this will cause compiling
|
// event for other systems to add self actions, running addActionToClass before this will cause compiling
|
||||||
@ -27,8 +27,7 @@ DFUNC(newControllableObject) = {
|
|||||||
|
|
||||||
GVAR(blockDefaultActions) = [];
|
GVAR(blockDefaultActions) = [];
|
||||||
|
|
||||||
GVAR(cachedBuildingTypes) = [];
|
GVAR(cachedBuildingTypes) = createHashMap;
|
||||||
GVAR(cachedBuildingActionPairs) = [];
|
|
||||||
|
|
||||||
GVAR(ParsedTextCached) = [];
|
GVAR(ParsedTextCached) = [];
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@ if (!hasInterface) exitWith { ADDON = true; };
|
|||||||
|
|
||||||
["All", "init", LINKFUNC(compileMenu)] call CBA_fnc_addClassEventHandler;
|
["All", "init", LINKFUNC(compileMenu)] call CBA_fnc_addClassEventHandler;
|
||||||
|
|
||||||
GVAR(ActNamespace) = [] call CBA_fnc_createNamespace;
|
GVAR(ActNamespace) = createHashMap;
|
||||||
GVAR(ActSelfNamespace) = [] call CBA_fnc_createNamespace;
|
GVAR(ActSelfNamespace) = createHashMap;
|
||||||
|
|
||||||
// Compile actions for CAManBase now and use for all mans types
|
// Compile actions for CAManBase now and use for all mans types
|
||||||
["CAManBase"] call FUNC(compileMenu);
|
["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
|
// Event handlers for all interact menu controls
|
||||||
DFUNC(handleMouseMovement) = {
|
DFUNC(handleMouseMovement) = {
|
||||||
|
@ -48,6 +48,8 @@ if (param [4, false, [false]]) exitwith {
|
|||||||
(_parentPath + [_action select 0])
|
(_parentPath + [_action select 0])
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_objectType = _objectType call EFUNC(common,getConfigName);
|
||||||
|
|
||||||
// Ensure the config menu was compiled first
|
// Ensure the config menu was compiled first
|
||||||
if (_typeNum == 0) then {
|
if (_typeNum == 0) then {
|
||||||
[_objectType] call FUNC(compileMenu);
|
[_objectType] call FUNC(compileMenu);
|
||||||
@ -56,18 +58,14 @@ if (_typeNum == 0) then {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
|
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
|
||||||
private _actionTrees = _namespace getVariable _objectType;
|
private _actionTrees = _namespace getOrDefault [_objectType, [], true];
|
||||||
if (isNil "_actionTrees") then {
|
|
||||||
_actionTrees = [];
|
|
||||||
_namespace setVariable [_objectType, _actionTrees];
|
|
||||||
};
|
|
||||||
|
|
||||||
if (_parentPath isEqualTo ["ACE_MainActions"]) then {
|
if (_parentPath isEqualTo ["ACE_MainActions"]) then {
|
||||||
[_objectType, _typeNum] call FUNC(addMainAction);
|
[_objectType, _typeNum] call FUNC(addMainAction);
|
||||||
};
|
};
|
||||||
|
|
||||||
private _parentNode = [_actionTrees, _parentPath] call FUNC(findActionNode);
|
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);
|
ERROR_4("Failed to add action - action (%1) to parent %2 on object %3 [%4]",(_action select 0),_parentPath,_objectType,_typeNum);
|
||||||
[]
|
[]
|
||||||
};
|
};
|
||||||
|
@ -19,14 +19,10 @@
|
|||||||
params ["_objectType", "_typeNum"];
|
params ["_objectType", "_typeNum"];
|
||||||
|
|
||||||
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
|
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
|
||||||
private _actionTrees = _namespace getVariable _objectType;
|
private _actionTrees = _namespace getOrDefault [_objectType, []];
|
||||||
if (isNil "_actionTrees") then {
|
|
||||||
_actionTrees = [];
|
|
||||||
};
|
|
||||||
|
|
||||||
private _parentNode = [_actionTrees, ["ACE_MainActions"]] call FUNC(findActionNode);
|
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);
|
TRACE_2("No Main Action on object",_objectType,_typeNum);
|
||||||
private _mainAction = ["ACE_MainActions", localize ELSTRING(interaction,MainAction), "", {}, {true}] call FUNC(createAction);
|
private _mainAction = ["ACE_MainActions", localize ELSTRING(interaction,MainAction), "", {}, {true}] call FUNC(createAction);
|
||||||
[_objectType, _typeNum, [], _mainAction] call EFUNC(interact_menu,addActionToClass);
|
[_objectType, _typeNum, [], _mainAction] call EFUNC(interact_menu,addActionToClass);
|
||||||
|
@ -17,22 +17,22 @@
|
|||||||
|
|
||||||
params ["_target"];
|
params ["_target"];
|
||||||
|
|
||||||
private _objectType = _target;
|
private _objectType = if (_target isEqualType objNull) then {
|
||||||
if (_target isEqualType objNull) then {
|
typeOf _target
|
||||||
_objectType = typeOf _target;
|
} else {
|
||||||
|
_target call EFUNC(common,getConfigName)
|
||||||
};
|
};
|
||||||
private _namespace = GVAR(ActNamespace);
|
|
||||||
|
|
||||||
// Exit if the action menu is already compiled for this class
|
// 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
|
if (_objectType isKindOf "VirtualMan_F") exitWith { // these have config: isPlayableLogic = 1
|
||||||
TRACE_1("skipping playable logic",_objectType);
|
TRACE_1("skipping playable logic",_objectType);
|
||||||
_namespace setVariable [_objectType, []];
|
GVAR(ActNamespace) set [_objectType, []];
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((_objectType isKindOf "CAManBase") && {!isNil QGVAR(cacheManActions)}) exitWith {
|
if ((_objectType isKindOf "CAManBase") && {!isNil QGVAR(cacheManActions)}) exitWith {
|
||||||
_namespace setVariable [_objectType, +GVAR(cacheManActions)]; // copy
|
GVAR(ActNamespace) set [_objectType, +GVAR(cacheManActions)]; // copy
|
||||||
};
|
};
|
||||||
|
|
||||||
private _recurseFnc = {
|
private _recurseFnc = {
|
||||||
@ -139,7 +139,7 @@ if (_objectType isKindOf "CAManBase") then {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
_namespace setVariable [_objectType, _actions];
|
GVAR(ActNamespace) set [_objectType, _actions];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[
|
[
|
||||||
|
@ -17,15 +17,14 @@
|
|||||||
|
|
||||||
params ["_target"];
|
params ["_target"];
|
||||||
|
|
||||||
private _objectType = _target;
|
private _objectType = if (_target isEqualType objNull) then {
|
||||||
if (_target isEqualType objNull) then {
|
typeOf _target
|
||||||
_objectType = typeOf _target;
|
} else {
|
||||||
|
_target call EFUNC(common,getConfigName)
|
||||||
};
|
};
|
||||||
private _namespace = GVAR(ActSelfNamespace);
|
|
||||||
|
|
||||||
// Exit if the action menu is already compiled for this class
|
// 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 = {
|
private _recurseFnc = {
|
||||||
params ["_actionsCfg"];
|
params ["_actionsCfg"];
|
||||||
@ -131,4 +130,4 @@ private _actions = [
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
_namespace setVariable [_objectType, _actions];
|
GVAR(ActSelfNamespace) set [_objectType, _actions];
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
params ["_class"];
|
params ["_class"];
|
||||||
|
|
||||||
private _actionTrees = GVAR(ActSelfNamespace) getVariable _class;
|
private _actionTrees = GVAR(ActSelfNamespace) get _class;
|
||||||
private _rootNode = [_actionTrees, ["ACE_SelfActions"]] call FUNC(findActionNode);
|
private _rootNode = [_actionTrees, ["ACE_SelfActions"]] call FUNC(findActionNode);
|
||||||
private _rootActions = _rootNode select 1;
|
private _rootActions = _rootNode select 1;
|
||||||
private _settingCategoryPrefix = format ["ACE %1 - ", LELSTRING(Interaction,InteractionMenuSelf)];
|
private _settingCategoryPrefix = format ["ACE %1 - ", LELSTRING(Interaction,InteractionMenuSelf)];
|
||||||
|
@ -19,17 +19,16 @@
|
|||||||
|
|
||||||
params ["_objectType", "_typeNum", "_fullPath"];
|
params ["_objectType", "_typeNum", "_fullPath"];
|
||||||
|
|
||||||
|
_objectType = _objectType call EFUNC(common,getConfigName);
|
||||||
|
|
||||||
private _res = _fullPath call FUNC(splitPath);
|
private _res = _fullPath call FUNC(splitPath);
|
||||||
_res params ["_parentPath", "_actionName"];
|
_res params ["_parentPath", "_actionName"];
|
||||||
|
|
||||||
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
|
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
|
||||||
private _actionTrees = _namespace getVariable _objectType;
|
private _actionTrees = _namespace getOrDefault [_objectType, []];
|
||||||
if (isNil "_actionTrees") then {
|
|
||||||
_actionTrees = [];
|
|
||||||
};
|
|
||||||
|
|
||||||
private _parentNode = [_actionTrees, _parentPath] call FUNC(findActionNode);
|
private _parentNode = [_actionTrees, _parentPath] call FUNC(findActionNode);
|
||||||
if (isNil {_parentNode}) exitWith {};
|
if (isNil "_parentNode") exitWith {};
|
||||||
|
|
||||||
// Iterate through children of the father
|
// Iterate through children of the father
|
||||||
private _found = false;
|
private _found = false;
|
||||||
|
@ -61,7 +61,7 @@ private _fnc_renderNearbyActions = {
|
|||||||
} forEach GVAR(objectActionList);
|
} forEach GVAR(objectActionList);
|
||||||
|
|
||||||
// Iterate through base level class actions and render them if appropiate
|
// 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;
|
private _action = _x;
|
||||||
// Try to render the menu
|
// Try to render the menu
|
||||||
@ -95,8 +95,7 @@ private _fnc_renderSelfActions = {
|
|||||||
GVAR(objectActionList) = _target getVariable [QGVAR(selfActions), []];
|
GVAR(objectActionList) = _target getVariable [QGVAR(selfActions), []];
|
||||||
|
|
||||||
// Iterate through base level class actions and render them if appropiate
|
// Iterate through base level class actions and render them if appropiate
|
||||||
private _namespace = GVAR(ActSelfNamespace);
|
private _classActions = GVAR(ActSelfNamespace) get typeOf _target;
|
||||||
private _classActions = _namespace getVariable typeOf _target;
|
|
||||||
|
|
||||||
private _pos = if !(GVAR(useCursorMenu)) then {
|
private _pos = if !(GVAR(useCursorMenu)) then {
|
||||||
//Convert to ASL, add offset and then convert back to AGL (handles waves when over water)
|
//Convert to ASL, add offset and then convert back to AGL (handles waves when over water)
|
||||||
|
@ -17,11 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
private _parentPath = [];
|
private _parentPath = [];
|
||||||
for [{private _i = 0},{_i < (count _this) - 1},{_i = _i + 1}] do {
|
|
||||||
_parentPath pushBack (_this select _i);
|
_parentPath append _this;
|
||||||
};
|
|
||||||
private _actionName = if (count _this > 0) then {
|
private _count = count _this;
|
||||||
_this select ((count _this) - 1);
|
|
||||||
|
private _actionName = if (_count > 0) then {
|
||||||
|
_parentPath deleteAt (_count - 1) // TODO: replace with _parentPath deleteAt [-1] and drop _count in 2.18
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
|
|
||||||
params ["_typeOfBuilding"];
|
params ["_typeOfBuilding"];
|
||||||
|
|
||||||
private _searchIndex = GVAR(cachedBuildingTypes) find _typeOfBuilding;
|
private _cachedMemPoints = GVAR(cachedBuildingTypes) get _typeOfBuilding;
|
||||||
if (_searchIndex != -1) exitWith {GVAR(cachedBuildingActionPairs) select _searchIndex};
|
|
||||||
|
if (!isNil "_cachedMemPoints") exitWith {_cachedMemPoints};
|
||||||
|
|
||||||
private _memPoints = [];
|
private _memPoints = [];
|
||||||
private _memPointsActions = [];
|
private _memPointsActions = [];
|
||||||
@ -148,8 +149,6 @@ private _ladders = getArray (configFile >> "CfgVehicles" >> _typeOfBuilding >> "
|
|||||||
|
|
||||||
} forEach _ladders;
|
} forEach _ladders;
|
||||||
|
|
||||||
GVAR(cachedBuildingTypes) pushBack _typeOfBuilding;
|
GVAR(cachedBuildingTypes) set [_typeOfBuilding, [_memPoints, _memPointsActions]];
|
||||||
GVAR(cachedBuildingActionPairs) pushBack [_memPoints, _memPointsActions];
|
|
||||||
|
|
||||||
|
|
||||||
[_memPoints, _memPointsActions]
|
[_memPoints, _memPointsActions]
|
||||||
|
@ -20,11 +20,7 @@
|
|||||||
params ["", "", "_parameters"];
|
params ["", "", "_parameters"];
|
||||||
_parameters params ["_unit"];
|
_parameters params ["_unit"];
|
||||||
|
|
||||||
private _namespace = EGVAR(interact_menu,ActNamespace);
|
private _actionTrees = EGVAR(interact_menu,ActNamespace) getOrDefault [typeOf _unit, []];
|
||||||
private _actionTrees = _namespace getVariable typeOf _unit;
|
|
||||||
if (isNil "_actionTrees") then {
|
|
||||||
_actionTrees = [];
|
|
||||||
};
|
|
||||||
|
|
||||||
private _actions = [];
|
private _actions = [];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user