mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Interact Menu - Add inheritance support to removeActionFromClass (#8396)
* Add inheritance & exclusion support * Update documentation in wiki * additional check for parent class in findIf * forEach instead of count Co-authored-by: PabstMirror <pabstmirror@gmail.com> * condition for children of excluded classes * touch everything but the params check * apply configName in same line * fix param data type for _excludedClasses Co-authored-by: PabstMirror <pabstmirror@gmail.com> * Update addons/interact_menu/functions/fnc_removeActionFromClass.sqf Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> * Fix & formatting * Fix missing _x & headers, remove invalid classes --------- Co-authored-by: Salluci <69561145+Salluci@users.noreply.github.com> Co-authored-by: PabstMirror <pabstmirror@gmail.com> Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
This commit is contained in:
parent
c491b78468
commit
4226cd383e
@ -88,8 +88,8 @@ GVAR(inheritedClassesMan) = [];
|
|||||||
if (GVAR(inheritedClassesAll) pushBackUnique _type == -1) exitWith { END_COUNTER(InitPost); };
|
if (GVAR(inheritedClassesAll) pushBackUnique _type == -1) exitWith { END_COUNTER(InitPost); };
|
||||||
|
|
||||||
{
|
{
|
||||||
_x params ["_objectType", "_typeNum", "_parentPath", "_action"];
|
_x params ["_objectType", "_typeNum", "_parentPath", "_action", "_excludedClasses"];
|
||||||
if (_object isKindOf _objectType) then {
|
if (_type isKindOf _objectType && {_excludedClasses findIf {_type isKindOf _x} == -1}) then {
|
||||||
[_type, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
|
[_type, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
|
||||||
};
|
};
|
||||||
} forEach GVAR(inheritedActionsAll);
|
} forEach GVAR(inheritedActionsAll);
|
||||||
@ -102,8 +102,10 @@ GVAR(inheritedClassesMan) = [];
|
|||||||
|
|
||||||
if (GVAR(inheritedClassesMan) pushBackUnique _type == -1) exitWith { END_COUNTER(InitPost); };
|
if (GVAR(inheritedClassesMan) pushBackUnique _type == -1) exitWith { END_COUNTER(InitPost); };
|
||||||
{
|
{
|
||||||
_x params ["_typeNum", "_parentPath", "_action"];
|
_x params ["_typeNum", "_parentPath", "_action", "_excludedClasses"];
|
||||||
|
if (_excludedClasses findIf {_type isKindOf _x} == -1) then { // skip excluded classes and children
|
||||||
[_type, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
|
[_type, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
|
||||||
|
};
|
||||||
} forEach GVAR(inheritedActionsMan);
|
} forEach GVAR(inheritedActionsMan);
|
||||||
END_COUNTER(InitPost);
|
END_COUNTER(InitPost);
|
||||||
}, true, ["VirtualMan_F"]] call CBA_fnc_addClassEventHandler;
|
}, true, ["VirtualMan_F"]] call CBA_fnc_addClassEventHandler;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "..\script_component.hpp"
|
#include "..\script_component.hpp"
|
||||||
/*
|
/*
|
||||||
* Author: esteldunedain
|
* Author: esteldunedain
|
||||||
* Insert an ACE action to a class, under a certain path
|
* Inserts an ACE action to a class, under a certain path.
|
||||||
* Note: This function is NOT global.
|
* Note: This function is NOT global.
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
@ -10,12 +10,13 @@
|
|||||||
* 2: Parent path of the new action <ARRAY>
|
* 2: Parent path of the new action <ARRAY>
|
||||||
* 3: Action <ARRAY>
|
* 3: Action <ARRAY>
|
||||||
* 4: Use Inheritance <BOOL> (default: false)
|
* 4: Use Inheritance <BOOL> (default: false)
|
||||||
|
* 5: Classes excluded from inheritance (children included) <ARRAY> (default: [])
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* The entry full path, which can be used to remove the entry, or add children entries <ARRAY>.
|
* The entry full path, which can be used to remove the entry, or add children entries <ARRAY>.
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* [typeOf cursorTarget, 0, ["ACE_TapShoulderRight"],VulcanPinchAction] call ace_interact_menu_fnc_addActionToClass;
|
* [typeOf cursorTarget, 0, ["ACE_TapShoulderRight"], VulcanPinchAction] call ace_interact_menu_fnc_addActionToClass;
|
||||||
*
|
*
|
||||||
* Public: Yes
|
* Public: Yes
|
||||||
*/
|
*/
|
||||||
@ -25,22 +26,30 @@ if (!params [["_objectType", "", [""]], ["_typeNum", 0, [0]], ["_parentPath", []
|
|||||||
ERROR("Bad Params");
|
ERROR("Bad Params");
|
||||||
[]
|
[]
|
||||||
};
|
};
|
||||||
TRACE_4("addActionToClass",_objectType,_typeNum,_parentPath,_action);
|
private _useInheritance = _this param [4, false, [false]];
|
||||||
|
private _excludedClasses = _this param [5, [], [[]]];
|
||||||
|
TRACE_6("addActionToClass",_objectType,_typeNum,_parentPath,_action,_useInheritance,_excludedClasses);
|
||||||
|
|
||||||
if (param [4, false, [false]]) exitwith {
|
if (_useInheritance) exitwith {
|
||||||
BEGIN_COUNTER(addAction);
|
BEGIN_COUNTER(addAction);
|
||||||
|
private _cfgVehicles = configFile >> "CfgVehicles"; // store this so we don't resolve for every element
|
||||||
|
_excludedClasses = (_excludedClasses apply {configName (_cfgVehicles >> _x)}) - [""]; // ends up being faster than toLower'ing everything else
|
||||||
if (_objectType == "CAManBase") then {
|
if (_objectType == "CAManBase") then {
|
||||||
GVAR(inheritedActionsMan) pushBack [_typeNum, _parentPath, _action];
|
GVAR(inheritedActionsMan) pushBack [_typeNum, _parentPath, _action, _excludedClasses];
|
||||||
{
|
{
|
||||||
[_x, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
|
private _type = _x;
|
||||||
} forEach GVAR(inheritedClassesMan);
|
if (_excludedClasses findIf {_type isKindOf _x} == -1) then { // skip excluded classes and children
|
||||||
} else {
|
|
||||||
GVAR(inheritedActionsAll) pushBack [_objectType, _typeNum, _parentPath, _action];
|
|
||||||
{
|
|
||||||
if (_x isKindOf _objectType) then {
|
|
||||||
[_x, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
|
[_x, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
|
||||||
};
|
};
|
||||||
} forEach GVAR(inheritedClassesAll);
|
} forEach (GVAR(inheritedClassesMan) - _excludedClasses);
|
||||||
|
} else {
|
||||||
|
GVAR(inheritedActionsAll) pushBack [_objectType, _typeNum, _parentPath, _action, _excludedClasses];
|
||||||
|
{
|
||||||
|
private _type = _x;
|
||||||
|
if (_type isKindOf _objectType && {_excludedClasses findIf {_type isKindOf _x} == -1}) then {
|
||||||
|
[_type, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
|
||||||
|
};
|
||||||
|
} forEach (GVAR(inheritedClassesAll) - _excludedClasses);
|
||||||
};
|
};
|
||||||
END_COUNTER(addAction);
|
END_COUNTER(addAction);
|
||||||
|
|
||||||
|
@ -1,29 +1,63 @@
|
|||||||
#include "..\script_component.hpp"
|
#include "..\script_component.hpp"
|
||||||
/*
|
/*
|
||||||
* Author: esteldunedain
|
* Author: esteldunedain
|
||||||
* Removes an action from a class
|
* Removes an action from a class.
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* 0: TypeOf of the class <STRING>
|
* 0: TypeOf of the class <STRING>
|
||||||
* 1: Type of action, 0 for actions, 1 for self-actions <NUMBER>
|
* 1: Type of action, 0 for actions, 1 for self-actions <NUMBER>
|
||||||
* 2: Full path of the new action <ARRAY>
|
* 2: Full path of the new action <ARRAY>
|
||||||
|
* 3: Remove action from child classes <BOOL> (default: false)
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* [typeOf cursorTarget, 0,["ACE_TapShoulderRight","VulcanPinch"]] call ace_interact_menu_fnc_removeActionFromClass;
|
* [typeOf cursorTarget, 0, ["ACE_TapShoulderRight", "VulcanPinch"]] call ace_interact_menu_fnc_removeActionFromClass;
|
||||||
*
|
*
|
||||||
* Public: No
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
|
||||||
params ["_objectType", "_typeNum", "_fullPath"];
|
params ["_objectType", "_typeNum", "_fullPath", ["_useInheritance", false, [false]]];
|
||||||
|
|
||||||
_objectType = _objectType call EFUNC(common,getConfigName);
|
_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"];
|
||||||
|
|
||||||
|
if (_useInheritance) exitWith {
|
||||||
|
// Only need to run for classes that have already been initialized
|
||||||
|
{
|
||||||
|
[_x, _typeNum, _fullPath] call FUNC(removeActionFromClass);
|
||||||
|
} forEach (GVAR(inheritedClassesAll) select {_x isKindOf _objectType});
|
||||||
|
|
||||||
|
// Find same path and actionName, and check if it's a parent class, needs to be checked for all classes
|
||||||
|
private _index = GVAR(inheritedActionsAll) findIf {
|
||||||
|
_x params ["_currentType", "", "_currentParentPath", "_currentAction"];
|
||||||
|
|
||||||
|
[_objectType isKindOf _currentType, _currentParentPath, _currentAction select 0] isEqualTo [true, _parentPath, _actionName]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add to exclude classes
|
||||||
|
if (_index != -1) then {
|
||||||
|
(GVAR(inheritedActionsAll) select _index select 4) pushBackUnique _objectType;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Children of CAManBase need special treatment because of inheritedActionsMan array
|
||||||
|
if (_objectType isKindOf "CAManBase") then {
|
||||||
|
private _index = GVAR(inheritedActionsMan) findIf {
|
||||||
|
_x params ["", "_currentParentPath", "_currentAction"];
|
||||||
|
|
||||||
|
[_currentParentPath, _currentAction select 0] isEqualTo [_parentPath, _actionName]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Different index because array doesn't include _objectType
|
||||||
|
if (_index != -1) then {
|
||||||
|
(GVAR(inheritedActionsMan) select _index select 3) pushBackUnique _objectType;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
|
private _namespace = [GVAR(ActNamespace), GVAR(ActSelfNamespace)] select _typeNum;
|
||||||
private _actionTrees = _namespace getOrDefault [_objectType, []];
|
private _actionTrees = _namespace getOrDefault [_objectType, []];
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ Important: `ace_common_fnc_canInteractWith` is not automatically checked and nee
|
|||||||
* 2: Parent path of the new action <ARRAY>
|
* 2: Parent path of the new action <ARRAY>
|
||||||
* 3: Action <ARRAY>
|
* 3: Action <ARRAY>
|
||||||
* 4: Use Inheritance (Default: False) <BOOL><OPTIONAL>
|
* 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.
|
By default this function will not use inheritance, so actions will only be added to the specific class.
|
||||||
@ -169,6 +170,10 @@ Using `addActionToClass` inheritance:
|
|||||||
_action = ["CheckFuel", "Check Fuel", "", {hint format ["Fuel: %1", fuel _target]}, {true}] call ace_interact_menu_fnc_createAction;
|
_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;
|
["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.
|
// 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;
|
_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;
|
["Tank_F", 0, ["ACE_MainActions", "CheckFuel"], _action, true] call ace_interact_menu_fnc_addActionToClass;
|
||||||
|
Loading…
Reference in New Issue
Block a user