ACE3/addons/interact_menu/functions/fnc_compileMenuSelfAction.sqf
Nicolás Badano 310710b6e2 Major plumbing upgrades on interact_menu:
- Store only one compiled menu per class
- Actions added through apis for invidual objects stored on the object separately
- Replaced the concept of uids by paths. This allows adding/removing actions inside other actions loaded from config seamlessly.
- Temporarily removed caching of nearby actions (probe). We may go back to that if needed pretty easily. This allows the player to move freely with the interaction menu opened.
2015-02-27 01:55:16 -03:00

92 lines
2.8 KiB
Plaintext

/*
* Author: NouberNou and CAA-Picard
* Compile the self action menu from config for an object's class
*
* Argument:
* 0: Object <OBJECT>
*
* Return value:
* None
*
* Public: No
*/
#include "script_component.hpp";
EXPLODE_1_PVT(_this,_object);
private ["_objectType","_actionsVarName"];
_objectType = typeOf _object;
_actionsVarName = format [QGVAR(SelfAct_%1), _objectType];
// Exit if the action menu is already compiled for this class
if !(isNil {missionNamespace getVariable [_actionsVarName, nil]}) exitWith {};
private "_recurseFnc";
_recurseFnc = {
private ["_actions", "_displayName", "_distance", "_icon", "_statement", "_selection", "_condition", "_showDisabled",
"_enableInside", "_children", "_entry", "_entryCfg", "_fullPath"];
EXPLODE_2_PVT(_this,_actionsCfg,_parentPath);
_actions = [];
for "_i" from 0 to (count _actionsCfg) - 1 do {
_entryCfg = _actionsCfg select _i;
if(isClass _entryCfg) then {
_displayName = getText (_entryCfg >> "displayName");
_icon = getText (_entryCfg >> "icon");
_statement = compile (getText (_entryCfg >> "statement"));
_condition = getText (_entryCfg >> "condition");
if (_condition == "") then {_condition = "true"};
// Add canInteract (including exceptions) and canInteractWith to condition
_condition = _condition + format [QUOTE( && {%1 call EGVAR(common,canInteract)} && {[ARR_2(ACE_player, _target)] call EFUNC(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")];
_showDisabled = getNumber (_entryCfg >> "showDisabled");
_enableInside = getNumber (_entryCfg >> "enableInside");
_fullPath = (+ _parentPath);
_fullPath pushBack (configName _entryCfg);
_condition = compile _condition;
_children = [_entryCfg, _fullPath] call _recurseFnc;
_entry = [
_displayName,
_icon,
[0,0,0],
_statement,
_condition,
10, //distace
_children,
GVAR(uidCounter),
_fullPath
];
GVAR(uidCounter) = GVAR(uidCounter) + 1;
_actions pushBack _entry;
};
};
_actions
};
private "_actionsCfg";
_actionsCfg = configFile >> "CfgVehicles" >> _objectType >> "ACE_SelfActions";
// Create a master action to base on self action
_actions = [[
"Self Actions",
"\a3\ui_f\data\IGUI\Cfg\Actions\eject_ca.paa",
"Spine3",
{ true },
{ true },
10,
[_actionsCfg, ["SelfActions"]] call _recurseFnc,
GVAR(uidCounter),
["SelfActions"]
]
];
GVAR(uidCounter) = GVAR(uidCounter) + 1;
missionNamespace setVariable [_actionsVarName, _actions];