Allow to dynamically modify actions at runtime. An optional code entry called modifierFunction can be added. That code is called before evaluating the action, allowing to dynamically change the actions name, icon, etc

This commit is contained in:
esteldunedain 2015-04-16 23:53:54 -03:00
parent e12831bee4
commit bdd3422150
4 changed files with 25 additions and 6 deletions

View File

@ -22,6 +22,13 @@ private ["_target","_player","_fullPath","_activeChildren","_dynamicChildren","_
_target = _object; _target = _object;
_player = ACE_player; _player = ACE_player;
// Check if the function should be modified first
if !((_origActionData select 10) isEqualTo {}) then {
// It should, so make a copy and pass it to the modifierFunction
_origActionData = +_origActionData;
[_target, ACE_player, _origActionData select 6, _origActionData] call (_origActionData select 10);
};
// Return nothing if the action itself is not active // Return nothing if the action itself is not active
if !([_target, ACE_player, _origActionData select 6] call (_origActionData select 4)) exitWith { if !([_target, ACE_player, _origActionData select 6] call (_origActionData select 4)) exitWith {
[] []

View File

@ -27,7 +27,7 @@ if !(isNil {missionNamespace getVariable [_actionsVarName, nil]}) exitWith {};
private "_recurseFnc"; private "_recurseFnc";
_recurseFnc = { _recurseFnc = {
private ["_actions", "_displayName", "_distance", "_icon", "_statement", "_selection", "_condition", "_showDisabled", private ["_actions", "_displayName", "_distance", "_icon", "_statement", "_selection", "_condition", "_showDisabled",
"_enableInside", "_canCollapse", "_runOnHover", "_children", "_entry", "_entryCfg", "_insertChildren"]; "_enableInside", "_canCollapse", "_runOnHover", "_children", "_entry", "_entryCfg", "_insertChildren", "_modifierFunction"];
EXPLODE_1_PVT(_this,_actionsCfg); EXPLODE_1_PVT(_this,_actionsCfg);
_actions = []; _actions = [];
@ -56,6 +56,7 @@ _recurseFnc = {
_condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, _target, %1)] call EFUNC(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")]; _condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, _target, %1)] call EFUNC(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")];
_insertChildren = compile (getText (_entryCfg >> "insertChildren")); _insertChildren = compile (getText (_entryCfg >> "insertChildren"));
_modifierFunction = compile (getText (_entryCfg >> "modifierFunction"));
_showDisabled = (getNumber (_entryCfg >> "showDisabled")) > 0; _showDisabled = (getNumber (_entryCfg >> "showDisabled")) > 0;
_enableInside = (getNumber (_entryCfg >> "enableInside")) > 0; _enableInside = (getNumber (_entryCfg >> "enableInside")) > 0;
@ -76,7 +77,8 @@ _recurseFnc = {
[], [],
_selection, _selection,
_distance, _distance,
[_showDisabled,_enableInside,_canCollapse,_runOnHover] [_showDisabled,_enableInside,_canCollapse,_runOnHover],
_modifierFunction
], ],
_children _children
]; ];

View File

@ -27,7 +27,7 @@ if !(isNil {missionNamespace getVariable [_actionsVarName, nil]}) exitWith {};
private "_recurseFnc"; private "_recurseFnc";
_recurseFnc = { _recurseFnc = {
private ["_actions", "_displayName", "_distance", "_icon", "_statement", "_selection", "_condition", "_showDisabled", private ["_actions", "_displayName", "_distance", "_icon", "_statement", "_selection", "_condition", "_showDisabled",
"_enableInside", "_canCollapse", "_runOnHover", "_children", "_entry", "_entryCfg", "_insertChildren"]; "_enableInside", "_canCollapse", "_runOnHover", "_children", "_entry", "_entryCfg", "_insertChildren", "_modifierFunction"];
EXPLODE_1_PVT(_this,_actionsCfg); EXPLODE_1_PVT(_this,_actionsCfg);
_actions = []; _actions = [];
@ -46,6 +46,7 @@ _recurseFnc = {
_condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, _target, %1)] call EFUNC(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")]; _condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, _target, %1)] call EFUNC(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")];
_insertChildren = compile (getText (_entryCfg >> "insertChildren")); _insertChildren = compile (getText (_entryCfg >> "insertChildren"));
_modifierFunction = compile (getText (_entryCfg >> "modifierFunction"));
_showDisabled = (getNumber (_entryCfg >> "showDisabled")) > 0; _showDisabled = (getNumber (_entryCfg >> "showDisabled")) > 0;
_enableInside = (getNumber (_entryCfg >> "enableInside")) > 0; _enableInside = (getNumber (_entryCfg >> "enableInside")) > 0;
@ -66,7 +67,8 @@ _recurseFnc = {
[], [],
[0,0,0], [0,0,0],
10, //distace 10, //distace
[_showDisabled,_enableInside,_canCollapse,_runOnHover] [_showDisabled,_enableInside,_canCollapse,_runOnHover],
_modifierFunction
], ],
_children _children
]; ];

View File

@ -14,6 +14,7 @@
* 7: Position (Position or Selection Name) <POSITION> or <STRING> (Optional) * 7: Position (Position or Selection Name) <POSITION> or <STRING> (Optional)
* 8: Distance <NUMBER> (Optional) * 8: Distance <NUMBER> (Optional)
* 9: Other parameters <ARRAY> (Optional) * 9: Other parameters <ARRAY> (Optional)
* 10: Modifier function <CODE> (Optional)
* *
* Return value: * Return value:
* Action <ARRAY> * Action <ARRAY>
@ -27,7 +28,7 @@
EXPLODE_5_PVT(_this,_actionName,_displayName,_icon,_statement,_condition); EXPLODE_5_PVT(_this,_actionName,_displayName,_icon,_statement,_condition);
private ["_insertChildren","_customParams","_position","_distance","_params"]; private ["_insertChildren","_customParams","_position","_distance","_params", "_modifierFunction"];
_insertChildren = if (count _this > 5) then { _insertChildren = if (count _this > 5) then {
_this select 5 _this select 5
@ -59,6 +60,12 @@ _params = if (count _this > 9) then {
[false,false,false,false] [false,false,false,false]
}; };
_modifierFunction = if (count _this > 10) then {
_this select 10
} else {
{}
};
[ [
_actionName, _actionName,
_displayName, _displayName,
@ -70,5 +77,6 @@ _params = if (count _this > 9) then {
_customParams, _customParams,
_position, _position,
_distance, _distance,
_params _params,
_modifierFunction
] ]