ACE3/addons/interaction/functions/fn_showMenu.sqf

121 lines
4.6 KiB
Plaintext
Raw Normal View History

2015-01-11 19:32:51 +00:00
/*
Name: AGM_Interaction_fnc_showMenu
2015-01-11 23:13:47 +00:00
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:
2015-01-11 23:13:47 +00:00
[0, GVAR(Target)] call AGM_Interaction_fnc_showMenu;
2015-01-11 19:32:51 +00:00
[1, player] call AGM_Interaction_fnc_showMenu;
2015-01-11 23:13:47 +00:00
[2, GVAR(Target), "AGM_Explosives"] call AGM_Interaction_fnc_showMenu;
2015-01-11 19:32:51 +00:00
[3, player, "AGM_Explosives"] call AGM_Interaction_fnc_showMenu;
*/
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-11 23:13:47 +00:00
#define DEFAULT_ICON PATHOF(UI\dot_ca.paa)
2015-01-11 19:32:51 +00:00
#define DEFAULT_DISTANCE 4 // seems to be 4
_player = AGM_player;
_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 {};
if !([_player, _object] call EFUNC(core,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;
2015-01-11 23:13:47 +00:00
_result = [_object, _parents, [], [], missionConfigFile >> "CfgVehicles", true, ["AGM_Actions", "AGM_SelfActions"] select _menuType, _this select 2] call FUNC(GetActions);
_actions = ([_object, _parents, _result select 0, _result select 1,configFile >> "CfgVehicles", false, ["AGM_Actions", "AGM_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;
2015-01-11 23:13:47 +00:00
_result = [_vehicle, _parents, [], [], missionConfigFile >> "CfgVehicles", true, ["AGM_Actions", "AGM_SelfActions"] select _menuType, _this select 2] call FUNC(GetActions);
_actions = _actions + (([_vehicle, _parents, _result select 0, _result select 1,configFile >> "CfgVehicles", false, ["AGM_Actions", "AGM_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(AGM_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 {
2015-01-11 23:13:47 +00:00
_customActions = _customActions + ((_vehicle getVariable [[QGVAR(Interactions), QGVAR(AGM_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);