ACE3/addons/interaction/functions/fnc_showMenu.sqf

119 lines
4.5 KiB
Plaintext
Raw Normal View History

2015-01-11 19:32:51 +00:00
/*
Author:
commy2
Garth de Wet (LH)
aeroson
2015-01-11 23:13:47 +00:00
2015-01-11 19:32:51 +00:00
Description:
2015-01-11 23:13:47 +00:00
Parameters:
2015-01-11 19:32:51 +00:00
0: NUMBER - Menu type (0 - interaction, 1 - self-interaction, 2 - sub-interaction, 3 - sub-self-interaction)
1: OBJECT - Target object
2: STRING - Sub-Menu ClassName
2015-01-11 23:13:47 +00:00
2015-01-11 19:32:51 +00:00
Returns:
Nothing
2015-01-11 23:13:47 +00:00
2015-01-11 19:32:51 +00:00
Example:
[0, GVAR(Target)] call FUNC(showMenu);
[1, player] call FUNC(showMenu);
[2, GVAR(Target), "ACE_Explosives"] call FUNC(showMenu);
[3, player, "ACE_Explosives"] call FUNC(showMenu);
2015-01-11 19:32:51 +00:00
*/
2015-01-11 23:13:47 +00:00
#include "script_component.hpp"
2015-01-11 19:32:51 +00:00
private ["_player", "_vehicle", "_mainButtonAction", "_object", "_index", "_actions", "_result", "_menuType"];
2015-01-13 05:14:27 +00:00
#define DEFAULT_ICON QUOTE(PATHOF(UI\dot_ca.paa))
2015-01-11 19:32:51 +00:00
#define DEFAULT_DISTANCE 4 // seems to be 4
_player = ACE_player;
2015-01-11 19:32:51 +00:00
_vehicle = vehicle _player;
2015-01-11 23:13:47 +00:00
GVAR(MenuType) = _this select 0; // 0 Interaction, 1 Self Interaction
2015-01-11 19:32:51 +00:00
_mainButtonAction = [
2015-01-11 23:13:47 +00:00
{call FUNC(hideMenu)},
{call FUNC(hideMenu)},
{"Default" call FUNC(openMenu)},
{"Default" call FUNC(openMenuSelf)}
] select GVAR(MenuType);
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
_menuType = GVAR(MenuType) % 2;
uiNamespace setVariable [QGVAR(CursorPosition), [controlNull, 0.5, 0.5, -1]];
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
GVAR(Target) = _this select 1;
_object = GVAR(Target);
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
if (_menuType == 0 && {(isNull (_object) || {!([_object, 4] call FUNC(isInRange))})}) exitWith {};
2015-01-13 05:14:27 +00:00
if !([_player, _object] call EFUNC(common,canInteractWith)) exitWith {};
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
// add actions or self actions of GVAR(Target)
2015-01-11 19:32:51 +00:00
_parents = [configFile >> "CfgVehicles" >> typeOf _object, true] call BIS_fnc_returnParents;
_result = [_object, _parents, [], [], missionConfigFile >> "CfgVehicles", true, ["ACE_Actions", "ACE_SelfActions"] select _menuType, _this select 2] call FUNC(GetActions);
_actions = ([_object, _parents, _result select 0, _result select 1,configFile >> "CfgVehicles", false, ["ACE_Actions", "ACE_SelfActions"] select _menuType, _this select 2] call FUNC(GetActions) select 0);
2015-01-11 19:32:51 +00:00
// add self actions of vehicle _player
if (_menuType == 1 && {_player != _vehicle}) then {
_parents = [configFile >> "CfgVehicles" >> typeOf _vehicle, true] call BIS_fnc_returnParents;
_result = [_vehicle, _parents, [], [], missionConfigFile >> "CfgVehicles", true, ["ACE_Actions", "ACE_SelfActions"] select _menuType, _this select 2] call FUNC(GetActions);
_actions = _actions + (([_vehicle, _parents, _result select 0, _result select 1,configFile >> "CfgVehicles", false, ["ACE_Actions", "ACE_SelfActions"] select _menuType, _this select 2] call FUNC(GetActions) select 0));
2015-01-11 19:32:51 +00:00
};
// custom defined actions, stored in variable instead of cfg like above
2015-01-11 23:13:47 +00:00
if (GVAR(MenuType) < 2) then {
2015-01-11 19:32:51 +00:00
private ["_customActions", "_customAction", "_displayName", "_distance","_condition","_statement","_showDisabled", "_priority"];
2015-01-11 23:13:47 +00:00
// add interactions or self interactions of GVAR(Target)
_customActions = (_object getVariable [[QGVAR(Interactions), QGVAR(ACE_InteractionsSelf)] select _menuType, [-1, [], []]]) select 2;
2015-01-11 19:32:51 +00:00
// add self interactions of vehicle _player
if (_menuType == 1 && {_player != _vehicle}) then {
_customActions = _customActions + ((_vehicle getVariable [[QGVAR(Interactions), QGVAR(ACE_InteractionsSelf)] select _menuType, [-1, [], []]]) select 2);
2015-01-11 19:32:51 +00:00
};
if(_menuType==0) then {
private ["_distance"];
for "_index" from 0 to (count _customActions - 1) do {
_customAction = _customActions select _index;
_displayName = _customAction select 0;
_distance = _customAction select 1;
_condition = _customAction select 2;
_statement = _customAction select 3;
_showDisabled = _customAction select 4;
_priority = _customAction select 5;
2015-01-11 23:13:47 +00:00
if ((_showDisabled || {[_object, _player] call _condition}) && {[_object, _distance] call FUNC(isInRange) || {_distance == 0}}) then {
2015-01-11 19:32:51 +00:00
_actions pushBack [_displayName, _statement, _condition, _priority, [], DEFAULT_ICON, "", {true}, [], _distance, ""];
};
};
} else { // self interactions do not have distance
for "_index" from 0 to (count _customActions - 1) do {
2015-01-11 23:13:47 +00:00
2015-01-11 19:32:51 +00:00
_customAction = _customActions select _index;
_displayName = _customAction select 0;
_condition = _customAction select 1;
_statement = _customAction select 2;
_showDisabled = _customAction select 3;
_priority = _customAction select 4;
if (_showDisabled || {[_object, _player] call _condition}) then {
_actions pushBack [_displayName, _statement, _condition, _priority, [], DEFAULT_ICON, "", {true}, [], DEFAULT_DISTANCE, ""];
};
};
};
};
2015-01-11 23:13:47 +00:00
if (count _actions == 0) exitWith {};
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
_actions call FUNC(sortOptionsByPriority);
GVAR(Buttons) = _actions;
[_mainButtonAction, (_this select 2) != "", (profileNamespace getVariable [QGVAR(FlowMenu), false]), _menuType == 1, _object] call FUNC(initialiseInteraction);