Allow inheritance for addActionToClass (#4272)

* Allow inheritance for addActionToClass

* Update Headers

* Use inline code for inheritance example
This commit is contained in:
PabstMirror 2016-08-27 03:35:21 -05:00 committed by Glowbal
parent 1366a6f15f
commit df7aa38a7a
3 changed files with 33 additions and 2 deletions

View File

@ -8,6 +8,7 @@
* 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: 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)
* *
* 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>.
@ -15,13 +16,29 @@
* 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: No * Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
if (!params [["_objectType", "", [""]], ["_typeNum", 0, [0]], ["_parentPath", [], [[]]], ["_action", [], [[]], 11]]) exitWith { if (!params [["_objectType", "", [""]], ["_typeNum", 0, [0]], ["_parentPath", [], [[]]], ["_action", [], [[]], 11]]) exitWith {
ERROR("Bad Params"); ERROR("Bad Params");
}; };
TRACE_4("params",_objectType,_typeNum,_parentPath,_action);
if (param [4, false, [false]]) exitwith {
if (isNil QGVAR(inheritedActions)) then {GVAR(inheritedActions) = [];};
private _index = GVAR(inheritedActions) pushBack [[], _typeNum, _parentPath, _action];
private _initEH = compile format ['
params ["_object"];
private _typeOf = typeOf _object;
(GVAR(inheritedActions) select %1) params ["_addedClasses", "_typeNum", "_parentPath", "_action"];
if (_typeOf in _addedClasses) exitWith {};
_addedClasses pushBack _typeOf;
[_typeOf, _typeNum, _parentPath, _action] call FUNC(addActionToClass);
', _index];
TRACE_2("Added inheritable action",_objectType,_index);
[_objectType, "init", _initEH, true, [], true] call CBA_fnc_addClassEventHandler;
};
// Ensure the config menu was compiled first // Ensure the config menu was compiled first
if (_typeNum == 0) then { if (_typeNum == 0) then {

View File

@ -22,7 +22,7 @@
* Example: * Example:
* ["VulcanPinch","Vulcan Pinch","",{_target setDamage 1;},{true},{},[parameters], [0,0,0], 100] call ace_interact_menu_fnc_createAction; * ["VulcanPinch","Vulcan Pinch","",{_target setDamage 1;},{true},{},[parameters], [0,0,0], 100] call ace_interact_menu_fnc_createAction;
* *
* Public: No * Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -97,8 +97,10 @@ Important: `ace_common_fnc_canInteractWith` is not automatically checked and nee
* 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: 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>
*/ */
``` ```
By default this function will not use inheritance, so actions will only be added to the specific class.
### 2.3 fnc_addActionToObject ### 2.3 fnc_addActionToObject
@ -136,6 +138,18 @@ _action = ["Open RDF","Radio Direction Finder","pabst\RDF.jpg",_statement,_condi
[(typeOf _unit), 1, ["ACE_SelfActions"], _action] call ace_interact_menu_fnc_addActionToClass; [(typeOf _unit), 1, ["ACE_SelfActions"], _action] call ace_interact_menu_fnc_addActionToClass;
``` ```
Using `addActionToClass` inheritance:
```cpp
// Adds action to check fuel levels for all land vehicles
_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;
// 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;
```
### 2.5 Advanced Example ### 2.5 Advanced Example
This adds an interaction to a unit that allows passing items that the player is carrying. This adds an interaction to a unit that allows passing items that the player is carrying.