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 - Add inheritance support to removeActionFromClass #8396

Merged
merged 17 commits into from
Aug 5, 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
10 changes: 6 additions & 4 deletions addons/interact_menu/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ GVAR(inheritedClassesMan) = [];
if (GVAR(inheritedClassesAll) pushBackUnique _type == -1) exitWith { END_COUNTER(InitPost); };

{
_x params ["_objectType", "_typeNum", "_parentPath", "_action"];
if (_object isKindOf _objectType) then {
_x params ["_objectType", "_typeNum", "_parentPath", "_action", "_excludeClasses"];
if (_type isKindOf _objectType && {(_excludeClasses isEqualTo []) || {_excludeClasses findIf {_type isKindOf _x} == -1}}) then {
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
[_type, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
};
} forEach GVAR(inheritedActionsAll);
Expand All @@ -102,8 +102,10 @@ GVAR(inheritedClassesMan) = [];

if (GVAR(inheritedClassesMan) pushBackUnique _type == -1) exitWith { END_COUNTER(InitPost); };
{
_x params ["_typeNum", "_parentPath", "_action"];
[_type, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
_x params ["_typeNum", "_parentPath", "_action", "_excludeClasses"];
if ((_excludeClasses isEqualTo []) || {_excludeClasses findIf {_type isKindOf _x} == -1}) then { // skip excluded classes and children
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
[_type, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
};
} forEach GVAR(inheritedActionsMan);
END_COUNTER(InitPost);
}, true, ["VirtualMan_F"]] call CBA_fnc_addClassEventHandler;
Expand Down
15 changes: 9 additions & 6 deletions addons/interact_menu/functions/fnc_addActionToClass.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* 2: Parent path of the new action <ARRAY>
* 3: Action <ARRAY>
* 4: Use Inheritance <BOOL> (default: false)
* 5: Classes excluded from inheritance (children included) <ARRAY> (default: [])
*
* Return Value:
* The entry full path, which can be used to remove the entry, or add children entries <ARRAY>.
Expand All @@ -25,22 +26,24 @@ if (!params [["_objectType", "", [""]], ["_typeNum", 0, [0]], ["_parentPath", []
ERROR("Bad Params");
[]
};
TRACE_4("addActionToClass",_objectType,_typeNum,_parentPath,_action);
TRACE_6("addActionToClass",_objectType,_typeNum,_parentPath,_action,_useInheritance,_excludeClasses);
private _useInheritance = _this param [4, false, [false]];
private _excludeClasses = _this param [5, [], []];
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

if (param [4, false, [false]]) exitwith {
if (_useInheritance) exitwith {
BEGIN_COUNTER(addAction);
if (_objectType == "CAManBase") then {
GVAR(inheritedActionsMan) pushBack [_typeNum, _parentPath, _action];
GVAR(inheritedActionsMan) pushBack [_typeNum, _parentPath, _action, _excludeClasses];
{
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
[_x, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
} forEach GVAR(inheritedClassesMan);
} forEach (GVAR(inheritedClassesMan) - _excludeClasses);
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
} else {
GVAR(inheritedActionsAll) pushBack [_objectType, _typeNum, _parentPath, _action];
GVAR(inheritedActionsAll) pushBack [_objectType, _typeNum, _parentPath, _action, _excludeClasses];
{
if (_x isKindOf _objectType) then {
[_x, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
};
} forEach GVAR(inheritedClassesAll);
} forEach (GVAR(inheritedClassesAll) - _excludeClasses);
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
};
END_COUNTER(addAction);

Expand Down
21 changes: 20 additions & 1 deletion addons/interact_menu/functions/fnc_removeActionFromClass.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* 0: TypeOf of the class <STRING>
* 1: Type of action, 0 for actions, 1 for self-actions <NUMBER>
* 2: Full path of the new action <ARRAY>
* 3: Remove action from child classes <BOOL> (default: false)
*
* Return Value:
* None
Expand All @@ -17,11 +18,29 @@
* Public: No
*/

params ["_objectType", "_typeNum", "_fullPath"];
params ["_objectType", "_typeNum", "_fullPath", ["_inherit", false, [false]]];

private _res = _fullPath call FUNC(splitPath);
_res params ["_parentPath", "_actionName"];

if (_inherit) exitWith {
private _children = (format ["(configName _x) isKindOf '%1'", _objectType]) configClasses (configFile >> "CfgVehicles");
{[configName _x, _typeNum, _fullPath] call FUNC(removeActionFromClass)} count _children;
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved

private _index = GVAR(inheritedActionsAll) findIf { // find same path and actionName, and check if it's a parent class
[_objectType isKindOf (_x select 0), _x select 2, _x select 3 select 0] isEqualTo [true, _parentPath, _actionName]
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
};
if (_index != -1) then {
(GVAR(inheritedActionsAll) select _index select 4) pushBack _objectType; // add to exclude classes
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
};
if (_objectType isKindOf "CAManBase") then { // only children of CAManBase
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
private _index = GVAR(inheritedActionsMan) findIf {[_x select 1, _x select 2 select 0] isEqualTo [_parentPath, _actionName]};
if (_index != -1) then {
(GVAR(inheritedActionsMan) select _index select 3) pushBack _objectType; // different index because array doesn't include _objectType
};
};
};

private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
private _actionTrees = _namespace getVariable _objectType;
if (isNil "_actionTrees") then {
Expand Down
7 changes: 6 additions & 1 deletion docs/wiki/framework/interactionMenu-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Important: `ace_common_fnc_canInteractWith` is not automatically checked and nee
* 2: Parent path of the new action <ARRAY>
* 3: Action <ARRAY>
* 4: Use Inheritance (Default: False) <BOOL><OPTIONAL>
* 5: Classes excluded from inheritance (children included) (Default: []) <ARRAY><OPTIONAL>
*/
```
By default this function will not use inheritance, so actions will only be added to the specific class.
Expand Down Expand Up @@ -162,6 +163,10 @@ Using `addActionToClass` inheritance:
_action = ["CheckFuel", "Check Fuel", "", {hint format ["Fuel: %1", fuel _target]}, {true}] call ace_interact_menu_fnc_createAction;
["LandVehicle", 0, ["ACE_MainActions"], _action, true] call ace_interact_menu_fnc_addActionToClass;

// Same as above, but children of "MRAP_01_Base" will not have the action
_action = ["CheckFuel", "Check Fuel", "", {hint format ["Fuel: %1", fuel _target]}, {true}] call ace_interact_menu_fnc_createAction;
["LandVehicle", 0, ["ACE_MainActions"], _action, true, ["MRAP_01_Base"]] call ace_interact_menu_fnc_addActionToClass;

// Adds action to check external fuel levels on tanks. Will be a sub action of the previous action.
_action = ["CheckExtTank","Check External Tank","",{hint format ["Ext Tank: %1", 5]},{true}] call ace_interact_menu_fnc_createAction;
["Tank_F", 0, ["ACE_MainActions", "CheckFuel"], _action, true] call ace_interact_menu_fnc_addActionToClass;
Expand Down Expand Up @@ -233,7 +238,7 @@ This is the ideal way to add self interaction actions, as adding them via `addAc
params ["_type"]; // string of the object's classname
if (!(_type isKindOf "Car")) exitWith {};
if ((getNumber (configFile >> "CfgVehicles" >> _type >> "side")) != 3) exitWith {};

private _action = ["playRadio","Play Radio","",{playMusic "NeverGonnaGiveYouUp"},{true}] call ace_interact_menu_fnc_createAction;
[_type, 1, ["ACE_SelfActions"], _action, true] call ace_interact_menu_fnc_addActionToClass;
}] call CBA_fnc_addEventHandler;
Expand Down