mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Interact menu:
- Allow dynamically adding children actions just-in-time - Added optional custom parameters for actions
This commit is contained in:
parent
3030b78ea2
commit
acd3ca0d56
@ -7,6 +7,7 @@ PREP(addClassAction);
|
||||
PREP(compileMenu);
|
||||
PREP(compileMenuSelfAction);
|
||||
PREP(collectActiveActionTree);
|
||||
PREP(createAction);
|
||||
PREP(keyDown);
|
||||
PREP(keyDownSelfAction);
|
||||
PREP(keyUp);
|
||||
|
@ -14,6 +14,8 @@
|
||||
* 7: Condition <CODE>
|
||||
* 8: Distance <NUMBER>
|
||||
* 9: Other parameters <ARRAY> (Optional)
|
||||
* 10: Insert children code <CODE> (Optional)
|
||||
* 11: Action parameters <ANY> (Optional)
|
||||
*
|
||||
* Return value:
|
||||
* The entry full path, which can be used to remove the entry, or add children entries <ARRAY>.
|
||||
@ -27,7 +29,7 @@
|
||||
|
||||
EXPLODE_9_PVT(_this,_object,_typeNum,_fullPath,_displayName,_icon,_position,_statement,_condition,_distance);
|
||||
|
||||
private ["_varName","_actions","_params","_entry"];
|
||||
private ["_varName","_actions","_params","_insertChildren","_parameters","_entry"];
|
||||
|
||||
_varName = [QGVAR(actions),QGVAR(selfActions)] select _typeNum;
|
||||
_actions = _object getVariable [_varName, []];
|
||||
@ -40,6 +42,16 @@ if (count _this > 9) then {
|
||||
_params = _this select 9;
|
||||
};
|
||||
|
||||
_insertChildren = {};
|
||||
if (count _this > 10) then {
|
||||
_insertChildren = _this select 10;
|
||||
};
|
||||
|
||||
_parameters = [];
|
||||
if (count _this > 11) then {
|
||||
_parameters = _this select 11;
|
||||
};
|
||||
|
||||
_entry = [
|
||||
[
|
||||
_displayName,
|
||||
@ -49,7 +61,9 @@ _entry = [
|
||||
_condition,
|
||||
_distance,
|
||||
_params,
|
||||
+ _fullPath
|
||||
+ _fullPath,
|
||||
_insertChildren,
|
||||
_parameters
|
||||
],
|
||||
[]
|
||||
];
|
||||
|
@ -14,6 +14,8 @@
|
||||
* 7: Condition <CODE>
|
||||
* 8: Distance <NUMBER>
|
||||
* 9: Other parameters <ARRAY> (Optional)
|
||||
* 10: Insert children code <CODE> (Optional)
|
||||
* 11: Action parameters <ANY> (Optional)
|
||||
*
|
||||
* Return value:
|
||||
* The entry full path, which can be used to remove the entry, or add children entries <ARRAY>.
|
||||
@ -34,7 +36,7 @@ if (_typeNum == 0) then {
|
||||
[_objectType] call FUNC(compileMenuSelfAction);
|
||||
};
|
||||
|
||||
private ["_varName","_actions","_params","_entry", "_parentLevel", "_foundParentLevel", "_fnc_findFolder"];
|
||||
private ["_varName","_actions","_params","_insertChildren","_parameters","_entry", "_parentLevel", "_foundParentLevel", "_fnc_findFolder"];
|
||||
|
||||
_varName = format [[QGVAR(Act_%1), QGVAR(SelfAct_%1)] select _typeNum, _objectType];
|
||||
_actions = missionNamespace getVariable [_varName, []];
|
||||
@ -47,6 +49,16 @@ if (count _this > 9) then {
|
||||
_params = _this select 9;
|
||||
};
|
||||
|
||||
_insertChildren = {};
|
||||
if (count _this > 10) then {
|
||||
_insertChildren = _this select 10;
|
||||
};
|
||||
|
||||
_parameters = [];
|
||||
if (count _this > 11) then {
|
||||
_parameters = _this select 11;
|
||||
};
|
||||
|
||||
// Search the class action trees and find where to insert the entry
|
||||
_parentLevel = _actions;
|
||||
_foundParentLevel = false;
|
||||
@ -84,7 +96,9 @@ _entry = [
|
||||
_condition,
|
||||
_distance,
|
||||
_params,
|
||||
+ _fullPath
|
||||
+ _fullPath,
|
||||
_insertChildren,
|
||||
_parameters
|
||||
],
|
||||
[]
|
||||
];
|
||||
|
@ -22,12 +22,17 @@ _target = _object;
|
||||
_player = ACE_player;
|
||||
|
||||
// Return nothing if the action itself is not active
|
||||
if !([_target, ACE_player] call (_origActionData select 4)) exitWith {
|
||||
if !([_target, ACE_player, _origActionData select 9] call (_origActionData select 4)) exitWith {
|
||||
[]
|
||||
};
|
||||
|
||||
_activeChildren = [];
|
||||
|
||||
// If there's a statement to dynamically insert children then execute it
|
||||
if (count _origActionData > 8 && {!({} isEqualTo (_origActionData select 8))}) then {
|
||||
_activeChildren = [_target, ACE_player, _origActionData select 9] call (_origActionData select 8);
|
||||
};
|
||||
|
||||
// Collect children class actions
|
||||
{
|
||||
_action = [_object, _x] call FUNC(collectActiveActionTree);
|
||||
@ -64,9 +69,12 @@ _activeChildren = [];
|
||||
|
||||
|
||||
// If the original action has no statement, and no children, don't display it
|
||||
/*
|
||||
if ((count _activeChildren) == 0 && ((_origActionData select 3) isEqualTo {})) exitWith {
|
||||
// @todo: Account for showDisabled?
|
||||
[]
|
||||
};
|
||||
*/
|
||||
|
||||
//diag_log [_origActionData, _activeChildren, _object];
|
||||
[_origActionData, _activeChildren, _object]
|
||||
|
@ -27,7 +27,7 @@ if !(isNil {missionNamespace getVariable [_actionsVarName, nil]}) exitWith {};
|
||||
private "_recurseFnc";
|
||||
_recurseFnc = {
|
||||
private ["_actions", "_displayName", "_distance", "_icon", "_statement", "_selection", "_condition", "_showDisabled",
|
||||
"_enableInside", "_canCollapse", "_runOnHover", "_children", "_entry", "_entryCfg", "_fullPath"];
|
||||
"_enableInside", "_canCollapse", "_runOnHover", "_children", "_entry", "_entryCfg", "_fullPath", "_insertChildren"];
|
||||
EXPLODE_2_PVT(_this,_actionsCfg,_parentPath);
|
||||
_actions = [];
|
||||
|
||||
@ -46,7 +46,9 @@ _recurseFnc = {
|
||||
if (_condition == "") then {_condition = "true"};
|
||||
|
||||
// Add canInteract (including exceptions) and canInteractWith to condition
|
||||
_condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, _target, %1)] call EGVAR(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"));
|
||||
|
||||
_showDisabled = (getNumber (_entryCfg >> "showDisabled")) > 0;
|
||||
_enableInside = (getNumber (_entryCfg >> "enableInside")) > 0;
|
||||
@ -68,7 +70,9 @@ _recurseFnc = {
|
||||
_condition,
|
||||
_distance,
|
||||
[_showDisabled,_enableInside,_canCollapse,_runOnHover],
|
||||
_fullPath
|
||||
_fullPath,
|
||||
_insertChildren,
|
||||
[]
|
||||
],
|
||||
_children
|
||||
];
|
||||
|
@ -27,7 +27,7 @@ if !(isNil {missionNamespace getVariable [_actionsVarName, nil]}) exitWith {};
|
||||
private "_recurseFnc";
|
||||
_recurseFnc = {
|
||||
private ["_actions", "_displayName", "_distance", "_icon", "_statement", "_selection", "_condition", "_showDisabled",
|
||||
"_enableInside", "_canCollapse", "_runOnHover", "_children", "_entry", "_entryCfg", "_fullPath"];
|
||||
"_enableInside", "_canCollapse", "_runOnHover", "_children", "_entry", "_entryCfg", "_fullPath", "_insertChildren"];
|
||||
EXPLODE_2_PVT(_this,_actionsCfg,_parentPath);
|
||||
_actions = [];
|
||||
|
||||
@ -43,7 +43,9 @@ _recurseFnc = {
|
||||
if (_condition == "") then {_condition = "true"};
|
||||
|
||||
// Add canInteract (including exceptions) and canInteractWith to condition
|
||||
_condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, objNull, %1)] call EGVAR(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")];
|
||||
_condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, objNull, %1)] call EFUNC(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")];
|
||||
|
||||
_insertChildren = compile (getText (_entryCfg >> "insertChildren"));
|
||||
|
||||
_showDisabled = (getNumber (_entryCfg >> "showDisabled")) > 0;
|
||||
_enableInside = (getNumber (_entryCfg >> "enableInside")) > 0;
|
||||
@ -65,7 +67,9 @@ _recurseFnc = {
|
||||
_condition,
|
||||
10, //distace
|
||||
[_showDisabled,_enableInside,_canCollapse,_runOnHover],
|
||||
_fullPath
|
||||
_fullPath,
|
||||
_insertChildren,
|
||||
[]
|
||||
],
|
||||
_children
|
||||
];
|
||||
@ -89,7 +93,9 @@ _actions = [
|
||||
{ true },
|
||||
10,
|
||||
[false,true,false],
|
||||
["ACE_SelfActions"]
|
||||
["ACE_SelfActions"],
|
||||
{},
|
||||
[]
|
||||
],
|
||||
[_actionsCfg, ["ACE_SelfActions"]] call _recurseFnc
|
||||
]
|
||||
|
63
addons/interact_menu/functions/fnc_createAction.sqf
Normal file
63
addons/interact_menu/functions/fnc_createAction.sqf
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Author: CAA-Picard
|
||||
* Creates an isolated ACE action
|
||||
* Note: This function is NOT global.
|
||||
*
|
||||
* Argument:
|
||||
* 0: Action name <STRING>
|
||||
* 1: Name of the action shown in the menu <STRING>
|
||||
* 2: Icon <STRING>
|
||||
* 3: Position (Position or Selection Name) <POSITION> or <STRING>
|
||||
* 4: Statement <CODE>
|
||||
* 5: Condition <CODE>
|
||||
* 6: Distance <NUMBER>
|
||||
* 7: Other parameters <ARRAY> (Optional)
|
||||
* 8: Insert children code <CODE> (Optional)
|
||||
* 9: Action parameters <ANY> (Optional)
|
||||
*
|
||||
* Return value:
|
||||
* Action
|
||||
*
|
||||
* Example:
|
||||
* [[VulcanPinch"],"Vulcan Pinch","",[0,0,0],{_target setDamage 1;},{true},100,{},[parameters]] call ace_interact_menu_fnc_addAction;
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
EXPLODE_7_PVT(_this,_fullPath,_displayName,_icon,_position,_statement,_condition,_distance);
|
||||
|
||||
private ["_actions","_params","_insertChildren","_parameters","_entry"];
|
||||
|
||||
_params = [false,false,false,false];
|
||||
if (count _this > 7) then {
|
||||
_params = _this select 7;
|
||||
};
|
||||
|
||||
_insertChildren = {};
|
||||
if (count _this > 8) then {
|
||||
_insertChildren = _this select 8;
|
||||
};
|
||||
|
||||
_parameters = [];
|
||||
if (count _this > 9) then {
|
||||
_parameters = _this select 9;
|
||||
};
|
||||
|
||||
_entry = [
|
||||
[
|
||||
_displayName,
|
||||
_icon,
|
||||
_position,
|
||||
_statement,
|
||||
_condition,
|
||||
_distance,
|
||||
_params,
|
||||
+ _fullPath,
|
||||
_insertChildren,
|
||||
_parameters
|
||||
],
|
||||
[]
|
||||
];
|
||||
|
||||
_entry
|
@ -16,7 +16,7 @@ if(GVAR(actionSelected)) then {
|
||||
this = GVAR(selectedTarget);
|
||||
_player = ACE_Player;
|
||||
_target = GVAR(selectedTarget);
|
||||
[GVAR(selectedTarget), ACE_player] call GVAR(selectedStatement);
|
||||
[GVAR(selectedTarget), ACE_player, (GVAR(selectedAction) select 0) select 9] call GVAR(selectedStatement);
|
||||
};
|
||||
|
||||
if (GVAR(keyDown)) then {
|
||||
|
@ -20,7 +20,7 @@ if(GVAR(actionSelected)) then {
|
||||
this = GVAR(selectedTarget);
|
||||
_player = ACE_Player;
|
||||
_target = GVAR(selectedTarget);
|
||||
[GVAR(selectedTarget), ACE_player] call GVAR(selectedStatement);
|
||||
[GVAR(selectedTarget), ACE_player, (GVAR(selectedAction) select 0) select 9] call GVAR(selectedStatement);
|
||||
};
|
||||
|
||||
if (GVAR(keyDownSelfAction)) then {
|
||||
|
Loading…
Reference in New Issue
Block a user