ACE3/addons/interact_menu/functions/fnc_compileMenuSelfAction.sqf

136 lines
4.9 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
2015-02-21 20:11:03 +00:00
/*
2015-03-24 04:18:00 +00:00
* Author: NouberNou and esteldunedain
* Compile the self action menu from config for an object's class
2015-02-21 20:11:03 +00:00
*
2016-06-18 09:50:41 +00:00
* Arguments:
* 0: Object or class name <OBJECT> or <STRING>
2015-02-21 20:11:03 +00:00
*
2016-06-18 09:50:41 +00:00
* Return Value:
2015-02-21 20:11:03 +00:00
* None
*
* Example:
* [bob] call ACE_interact_menu_fnc_compileMenuSelfAction
*
2015-02-21 20:11:03 +00:00
* Public: No
*/
2015-02-18 21:58:06 +00:00
params ["_target"];
2015-02-18 21:58:06 +00:00
2016-01-08 04:43:37 +00:00
private _objectType = _target;
if (_target isEqualType objNull) then {
_objectType = typeOf _target;
};
2016-03-06 05:22:38 +00:00
private _namespace = GVAR(ActSelfNamespace);
2015-02-18 21:58:06 +00:00
// Exit if the action menu is already compiled for this class
2020-02-11 22:43:08 +00:00
if (!isNil {_namespace getVariable _objectType}) exitWith {};
2015-02-18 21:58:06 +00:00
2016-01-08 04:43:37 +00:00
private _recurseFnc = {
params ["_actionsCfg"];
2016-01-08 04:43:37 +00:00
private _actions = [];
{
2016-01-08 04:43:37 +00:00
private _entryCfg = _x;
2020-02-11 22:43:08 +00:00
if (isClass _entryCfg) then {
2016-01-08 04:43:37 +00:00
private _displayName = getText (_entryCfg >> "displayName");
private _icon = if (isArray (_entryCfg >> "icon")) then {
getArray (_entryCfg >> "icon");
} else {
[getText (_entryCfg >> "icon"), "#FFFFFF"];
};
2016-01-08 04:43:37 +00:00
private _statement = compile (getText (_entryCfg >> "statement"));
2015-02-18 21:58:06 +00:00
2016-01-08 04:43:37 +00:00
private _condition = getText (_entryCfg >> "condition");
2015-02-18 21:58:06 +00:00
// Add canInteract (including exceptions) and canInteractWith to condition
private _canInteractCondition = format [QUOTE([ARR_3(ACE_player,_target,%1)] call EFUNC(common,canInteractWith)), getArray (_entryCfg >> "exceptions")];
private _conditionFormatPattern = ["%1 && {%2}", "%2"] select (_condition isEqualTo "" || {_condition == "true"});
_condition = compile format [_conditionFormatPattern, _condition, _canInteractCondition];
2016-01-08 04:43:37 +00:00
private _insertChildren = compile (getText (_entryCfg >> "insertChildren"));
private _modifierFunction = compile (getText (_entryCfg >> "modifierFunction"));
2015-02-18 21:58:06 +00:00
2016-01-08 04:43:37 +00:00
private _showDisabled = (getNumber (_entryCfg >> "showDisabled")) > 0;
private _enableInside = (getNumber (_entryCfg >> "enableInside")) > 0;
private _canCollapse = (getNumber (_entryCfg >> "canCollapse")) > 0;
private _runOnHover = true;
if (isText (_entryCfg >> "runOnHover")) then {
_runOnHover = compile getText (_entryCfg >> "runOnHover");
} else {
_runOnHover = (getNumber (_entryCfg >> "runOnHover")) > 0;
};
2015-02-18 21:58:06 +00:00
2016-01-08 04:43:37 +00:00
private _children = [_entryCfg] call _recurseFnc;
2016-01-08 04:43:37 +00:00
private _entry = [
[
configName _entryCfg,
_displayName,
_icon,
_statement,
_condition,
_insertChildren,
[],
[0,0,0],
10, //distace
[_showDisabled,_enableInside,_canCollapse,_runOnHover, true],
_modifierFunction
],
_children
2015-02-18 21:58:06 +00:00
];
_actions pushBack _entry;
};
2016-01-08 04:43:37 +00:00
nil
} count (configProperties [_actionsCfg, "isClass _x", true]);
2015-02-18 21:58:06 +00:00
_actions
};
2016-01-08 04:43:37 +00:00
private _actionsCfg = configFile >> "CfgVehicles" >> _objectType >> "ACE_SelfActions";
2015-02-18 21:58:06 +00:00
2016-01-08 04:43:37 +00:00
private _baseDisplayName = "";
private _baseIcon = "";
2015-04-01 04:56:41 +00:00
if (_objectType isKindOf "CAManBase") then {
2015-05-28 19:59:04 +00:00
_baseDisplayName = localize LSTRING(SelfActionsRoot);
2015-04-01 04:56:41 +00:00
_baseIcon = "\a3\ui_f\data\IGUI\Cfg\Actions\eject_ca.paa";
} else {
_baseDisplayName = getText (configFile >> "CfgVehicles" >> _objectType >> "displayName");
//Alt would be to just use a static text, if veh names end up being too long:
2015-05-28 19:59:04 +00:00
// _baseDisplayName = localize LSTRING(VehicleActionsRoot);
//Pull the icon from the vehicle's config:
2015-04-01 04:56:41 +00:00
_baseIcon = getText (configFile >> "CfgVehicles" >> _objectType >> "Icon");
//icon could be a CfgVehicleIcons
if isText (configFile >> "CfgVehicleIcons" >> _baseIcon) then {
_baseIcon = getText (configFile >> "CfgVehicleIcons" >> _baseIcon);
};
2015-04-01 04:56:41 +00:00
};
TRACE_1("Building ACE_SelfActions",_objectType);
// Create a master action to base on self action
private _actions = [
[
[
"ACE_SelfActions",
_baseDisplayName,
_baseIcon,
{
// Dummy statement so it's not collapsed when there's no available actions
true
},
{[ACE_player, _target, ["isNotInside","isNotDragging", "isNotCarrying", "isNotSwimming", "notOnMap", "isNotEscorting", "isNotSurrendering", "isNotSitting", "isNotOnLadder", "isNotRefueling"]] call EFUNC(common,canInteractWith)},
{},
{},
"Spine3",
10,
2016-01-08 04:43:37 +00:00
[false,true,false,false,false]
],
[_actionsCfg] call _recurseFnc
]
];
2015-02-18 21:58:06 +00:00
2016-03-06 05:22:38 +00:00
_namespace setVariable [_objectType, _actions];