ACE3/addons/interaction/functions/fn_initialiseInteraction.sqf

170 lines
6.4 KiB
Plaintext
Raw Normal View History

2015-01-11 19:32:51 +00:00
/*
Name: AGM_Interaction_fnc_initialiseInteraction
Author:
commy2
Garth de Wet (LH)
Description:
Initialises the interaction click handlers.
Parameters:
0 : CODE - code to call when right clicking/center button
1 : BOOLEAN - Submenu
2 : BOOLEAN - Flow Menu
3 : BOOLEAN - Self interaction
4 : OBJECT - Target
Returns:
Nothing
Example:
2015-01-11 23:13:47 +00:00
[{"Default" call AGM_Interaction_fnc_openMenu;}, true, (profileNamespace getVariable [QGVAR(FlowMenu), false]), GVAR(Target)] call AGM_Interaction_fnc_initialiseInteraction;
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 ["_subMenu", "_selfMenu", "_target"];
2015-01-11 23:13:47 +00:00
GVAR(MainButton) = _this select 0;
2015-01-11 19:32:51 +00:00
_subMenu = _this select 1;
_selfMenu = _this select 3;
_target = _this select 4;
_player = AGM_player;
_vehicle = vehicle _player;
2015-01-11 23:13:47 +00:00
//_object = [GVAR(Target), _player] select (GVAR(MenuType) % 2 == 1);
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
if !([_target, 5] call GVAR(isInRange)) exitWith {};
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
GVAR(Shortcuts) = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
2015-01-11 19:32:51 +00:00
// Flow menu
if (_this select 2) then {
2015-01-11 23:13:47 +00:00
(QGVAR(FlowMenu) call BIS_fnc_rscLayer) cutRsc [QGVAR(FlowMenu), "PLAIN",0.5, false];
2015-01-11 19:32:51 +00:00
AGM_Interaction_SelectedButton = 0;
(findDisplay 1713999) closeDisplay 1;
if (_player getVariable ["AGM_AcceptAction", -1] == -1) then {
2015-01-11 23:13:47 +00:00
[{if(isNil {GVAR(MainButton)} || {!(profileNamespace getVariable [QGVAR(FlowMenu), false])})exitWith{false};(-(_this select 0) / 1.2) call FUNC(MoveDown);true}] call EFUNC(core,addScrollWheelEventHandler);
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
_player setVariable ["AGM_AcceptAction", [_player, "DefaultAction", {(!isNil {GVAR(MainButton)}) && {(profileNamespace getVariable [QGVAR(FlowMenu), false])}}, {_action = GVAR(Buttons) select AGM_Interaction_SelectedButton;_target = GVAR(Target);_player = AGM_player;_vehicle = vehicle _player;if ([_target, _player] call (_action select 2)) then {call FUNC(hideMenu);if(count _action == 12) then{(_action select 11) call (_action select 1);}else{[_target, _player] call (_action select 1);};};}] call EFUNC(core,addActionEventHandler)];
_player setVariable ["AGM_AcceptAction", [_player, "menuBack", {(!isNil {GVAR(MainButton)}) && {(profileNamespace getVariable [QGVAR(FlowMenu), false])}}, {call GVAR(MainButton);}] call EFUNC(core,addActionEventHandler)];
2015-01-11 19:32:51 +00:00
};
2015-01-11 23:13:47 +00:00
0 call FUNC(moveDown);
[localize "STR_AGM_Interaction_MakeSelection", if (_subMenu)then{localize "STR_AGM_Interaction_Back"}else{""}, localize "STR_AGM_Interaction_ScrollHint"] call FUNC(showMouseHint);
((uiNamespace getVariable QGVAR(Flow_Display)) displayCtrl (1210)) ctrlShow _subMenu;
2015-01-11 19:32:51 +00:00
}else{ // Rose
2015-01-11 23:13:47 +00:00
if (!isNull(uiNamespace getVariable QGVAR(Flow_Display))) then {
(uiNameSpace getVariable QGVAR(Flow_Display)) closeDisplay 0;
call FUNC(hideMouseHint);
2015-01-11 19:32:51 +00:00
};
if (!_subMenu || {isNull (findDisplay 1713999)}) then {
(findDisplay 1713999) closeDisplay 1;
2015-01-11 23:13:47 +00:00
(findDisplay 46) createDisplay QGVAR(Dialog);
2015-01-11 19:32:51 +00:00
// Add eventhandlers
2015-01-11 23:13:47 +00:00
(findDisplay 1713999) displayAddEventHandler ["KeyDown", QUOTE( _this call EFUNC(core,onKeyDown) )];
(findDisplay 1713999) displayAddEventHandler ["KeyUp", QUOTE( _this call EFUNC(core,onKeyUp) )];
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
(findDisplay 1713999) displayAddEventHandler ["KeyDown", QUOTE( _this call FUNC(menuKeyInput) )];
2015-01-11 19:32:51 +00:00
};
disableSerialization;
2015-01-11 23:13:47 +00:00
_dlgInteractionDialog = uiNamespace getVariable QGVAR(Dialog);
2015-01-11 19:32:51 +00:00
_ctrlInteractionDialog = _dlgInteractionDialog displayCtrl 3;
2015-01-11 23:13:47 +00:00
if (profileNamespace getVariable [QGVAR(AutoCenterCursor), true]) then {setMousePosition [0.5, 0.5]};
2015-01-11 19:32:51 +00:00
if !(_subMenu) then {
2015-01-11 23:13:47 +00:00
_ctrlInteractionDialog ctrlSetText ([_target] call EFUNC(core,getName));
2015-01-11 19:32:51 +00:00
} else {
_ctrlInteractionDialog ctrlSetText localize "STR_AGM_Interaction_Back";
};
2015-01-11 23:13:47 +00:00
_buttons = GVAR(Buttons);
2015-01-11 19:32:51 +00:00
_count = count _buttons;
for "_i" from 0 to 9 do {
_ctrlInteractionDialog = _dlgInteractionDialog displayCtrl (10 + _i);
_ctrlInteractionDialog ctrlShow true;
_ctrlInteractionDialogIcon = _dlgInteractionDialog displayCtrl (20 + _i);
_ctrlInteractionDialogShortcut = _dlgInteractionDialog displayCtrl (30 + _i);
//_ctrlInteractionDialogBackground = _dlgInteractionDialog displayCtrl (40 + _i);
if (_i < _count) then {
_action = _buttons select _i;
_ctrlInteractionDialog ctrlSetText (_action select 0);
_ctrlInteractionDialog ctrlEnable ([_target, _player] call (_action select 2));
_ctrlInteractionDialog ctrlSetTooltip (_action select 6);
_ctrlInteractionDialogIcon ctrlSetText (_action select 5);
_ctrlInteractionDialogShortcut ctrlSetText (_action select 10);
//_ctrlInteractionDialogBackground ctrlShow true;
2015-01-11 23:13:47 +00:00
GVAR(Shortcuts) set [_i, [_action select 10] call EFUNC(core,letterToCode)];
2015-01-11 19:32:51 +00:00
} else {
_ctrlInteractionDialog ctrlSetText "";
_ctrlInteractionDialog ctrlEnable false;
_ctrlInteractionDialog ctrlSetTooltip "";
_ctrlInteractionDialogIcon ctrlSetText "";
_ctrlInteractionDialogShortcut ctrlSetText "";
//_ctrlInteractionDialogBackground ctrlShow false;
};
};
// Update Buttons
2015-01-11 23:13:47 +00:00
terminate (missionNamespace getVariable [QGVAR(updateMenuHandle), scriptNull]);
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
GVAR(updateMenuHandle) = 0 spawn {
2015-01-11 19:32:51 +00:00
disableSerialization;
2015-01-11 23:13:47 +00:00
_dlgMenu = uiNamespace getVariable [QGVAR(Dialog), displayNull];
2015-01-11 19:32:51 +00:00
_ctrlTooltip = _dlgMenu displayCtrl 40;
_player = AGM_player;
_vehicle = vehicle _player;
2015-01-11 23:13:47 +00:00
_target = [GVAR(Target), _player] select (GVAR(MenuType) % 2 == 1);
2015-01-11 19:32:51 +00:00
waitUntil {
2015-01-11 23:13:47 +00:00
if !([_target, 5] call GVAR(isInRange)) exitWith {
2015-01-11 19:32:51 +00:00
(findDisplay 1713999) closeDisplay 1
};
2015-01-11 23:13:47 +00:00
GVAR(Tooltips) = [[], [], [], [], [], [], [], [], [], []];
2015-01-11 19:32:51 +00:00
{
_ctrlText = _dlgMenu displayCtrl (10 + _forEachIndex);
_ctrlIcon = _dlgMenu displayCtrl (20 + _forEachIndex);
_condition = _x select 2;
_conditionShow = _x select 7;
_distance = _x select 9;
2015-01-11 23:13:47 +00:00
GVAR(CurrentTooltip) = [];
2015-01-11 19:32:51 +00:00
2015-01-11 23:13:47 +00:00
_enable = (_distance == 0 || {[_target, _distance] call GVAR(isInRange)}) && {[_target, _player] call _condition} && {[_target, _player] call _conditionShow};
2015-01-11 19:32:51 +00:00
if (isNil "_enable") then {_enable = false};
2015-01-11 23:13:47 +00:00
GVAR(Tooltips) set [_forEachIndex, GVAR(CurrentTooltip)];
2015-01-11 19:32:51 +00:00
// apply conditional tooltips
/*if (_forEachIndex == call AGM_Interaction_fnc_getSelectedButton) then {
_tooltip = _x select 6;
_showTooltip = _tooltip != "";
_tooltip = text _tooltip;
{
_showTooltip = true;
_tooltip = composeText [_tooltip, lineBreak, _x];
2015-01-11 23:13:47 +00:00
} forEach (GVAR(Tooltips) select _forEachIndex);
2015-01-11 19:32:51 +00:00
_ctrlTooltip ctrlSetStructuredText _tooltip;
_ctrlTooltip ctrlShow _showTooltip;
};*/
_ctrlText ctrlEnable _enable;
_ctrlIcon ctrlEnable _enable;
2015-01-11 23:13:47 +00:00
} forEach GVAR(Buttons);
2015-01-11 19:32:51 +00:00
sleep 0.5;
isNull (findDisplay 1713999)
};
};
};