ACE3/addons/spectator/functions/fnc_handleInterface.sqf

370 lines
12 KiB
Plaintext
Raw Normal View History

2015-07-15 11:03:54 +00:00
/*
* Author: SilentSpike
* Handles spectator interface events
*
* Arguments:
* 0: Event name <STRING>
* 1: Event arguments <ANY>
*
* Return Value:
* None <NIL>
*
* Example:
* ["onLoad",_this] call ace_spectator_fnc_handleInterface
*
* Public: No
*/
#include "script_component.hpp"
2015-07-18 17:46:46 +00:00
params ["_mode",["_args",[]]];
2015-07-15 11:03:54 +00:00
switch (toLower _mode) do {
// Safely open/close the interface
case "open": {
// Prevent reopening
if !(isNull (GETUVAR(GVAR(display),displayNull))) exitWith {};
2015-07-15 11:11:19 +00:00
// Initalize camera variables
2015-07-21 17:05:29 +00:00
GVAR(camBoom) = 0;
GVAR(camDolly) = [0,0];
2015-07-21 10:59:20 +00:00
GVAR(camGun) = false;
2015-07-15 11:11:19 +00:00
// Initalize display variables
GVAR(ctrlKey) = false;
2015-07-24 10:12:26 +00:00
GVAR(heldKeys) = [];
2015-07-15 11:11:19 +00:00
GVAR(mouse) = [false,false];
GVAR(mousePos) = [0.5,0.5];
2015-07-15 11:03:54 +00:00
// Initalize the camera view
2015-07-21 17:07:55 +00:00
GVAR(camera) = "Camera" camCreate (ASLtoATL GVAR(camPos));
2015-07-20 21:45:11 +00:00
[] call FUNC(transitionCamera);
2015-07-15 13:33:11 +00:00
2015-07-15 11:03:54 +00:00
// Create the dialog
2015-07-17 00:44:49 +00:00
createDialog QGVAR(interface);
2015-07-15 11:03:54 +00:00
// Cache and disable nametag settings
if (["ace_nametags"] call EFUNC(common,isModLoaded)) then {
GVAR(nametagSettingCache) = [EGVAR(nametags,showPlayerNames), EGVAR(nametags,showNamesForAI)];
EGVAR(nametags,showPlayerNames) = 0;
EGVAR(nametags,showNamesForAI) = false;
};
};
case "close": {
// Can't close a second time
if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith {};
// Terminate interface
(GETUVAR(GVAR(display),displayNull)) closeDisplay 0;
// Terminate camera
GVAR(camera) cameraEffect ["terminate", "back"];
camDestroy GVAR(camera);
// Return to player view
ACE_Player switchCamera "internal";
2015-07-15 11:11:19 +00:00
// Cleanup camera variables
GVAR(camera) = nil;
GVAR(camBoom) = nil;
GVAR(camDolly) = nil;
2015-07-21 10:59:20 +00:00
GVAR(camGun) = nil;
2015-07-15 11:11:19 +00:00
// Cleanup display variables
2015-07-18 17:46:46 +00:00
GVAR(ctrlKey) = nil;
2015-07-24 10:12:26 +00:00
GVAR(heldKeys) = nil;
2015-07-15 11:11:19 +00:00
GVAR(mouse) = nil;
GVAR(mousePos) = nil;
2015-07-15 11:03:54 +00:00
// Reset nametag settings
if (["ace_nametags"] call EFUNC(common,isModLoaded)) then {
EGVAR(nametags,showPlayerNames) = GVAR(nametagSettingCache) select 0;
EGVAR(nametags,showNamesForAI) = GVAR(nametagSettingCache) select 1;
GVAR(nametagSettingCache) = nil;
};
};
// Dialog events
case "onload": {
2015-07-18 17:46:46 +00:00
_args params ["_display"];
2015-07-15 11:03:54 +00:00
with uiNamespace do {
2015-07-18 17:46:46 +00:00
GVAR(display) = _display;
2015-07-15 11:03:54 +00:00
};
2015-07-18 14:42:07 +00:00
// Always show interface and hide map upon opening
2015-07-20 21:45:11 +00:00
[_display,nil,nil,!GVAR(showInterface),GVAR(showMap)] call FUNC(toggleInterface);
2015-07-15 11:03:54 +00:00
2015-07-16 10:15:33 +00:00
// Keep unit tree up to date
2015-07-19 12:40:08 +00:00
[FUNC(handleUnits), 21, _display] call CBA_fnc_addPerFrameHandler;
// Handle the compass heading
[FUNC(handleCompass), 0, _display] call CBA_fnc_addPerFrameHandler;
2015-07-15 11:03:54 +00:00
2015-07-19 15:35:53 +00:00
// Handle the toolbar values
[FUNC(handleToolbar), 0, _display] call CBA_fnc_addPerFrameHandler;
2015-07-19 12:31:19 +00:00
2015-07-21 22:20:41 +00:00
// Populate the help splash
{
((_display displayCtrl IDC_HELP) controlsGroupCtrl IDC_HELP_LIST) lnbAddRow _x;
} forEach [
[localize LSTRING(freeCamForward),"W"],
[localize LSTRING(freeCamBackward),"S"],
[localize LSTRING(freeCamLeft),"A"],
[localize LSTRING(freeCamRight),"D"],
[localize LSTRING(freeCamUp),"Q"],
[localize LSTRING(freeCamDown),"Z"],
2015-07-24 10:12:26 +00:00
[localize LSTRING(freeCamNextVis),"N"],
[localize LSTRING(freeCamPrevVis),"Ctrl + N"],
2015-07-21 22:20:41 +00:00
[localize LSTRING(freeCamSpeed),"Scrollwheel"],
[localize LSTRING(freeCamZoom),"Ctrl + Scrollwheel"]
];
2015-07-15 11:03:54 +00:00
// Hacky way to enable keybindings
//_display displayAddEventHandler ["KeyUp", {[_this,'keyup'] call CBA_events_fnc_keyHandler}];
//_display displayAddEventHandler ["KeyDown", {[_this,'keydown'] call CBA_events_fnc_keyHandler}];
};
case "onunload": {
with uiNamespace do {
GVAR(display) = nil;
};
2015-07-18 16:06:13 +00:00
GVAR(camHandler) = nil;
2015-07-15 11:03:54 +00:00
};
2015-07-15 11:11:19 +00:00
// Mouse events
case "onmousebuttondown": {
2015-07-18 17:46:46 +00:00
_args params ["_ctrl","_button"];
2015-07-15 11:11:19 +00:00
GVAR(mouse) set [_button,true];
2015-07-15 11:33:32 +00:00
// Detect right click
if ((_button == 1) && (GVAR(camMode) == 1)) then {
2015-07-15 13:33:11 +00:00
// In first person toggle sights mode
2015-07-21 17:05:29 +00:00
GVAR(camGun) = !GVAR(camGun);
2015-07-20 21:45:11 +00:00
[] call FUNC(transitionCamera);
2015-07-15 11:33:32 +00:00
};
2015-07-15 11:11:19 +00:00
};
case "onmousebuttonup": {
2015-07-18 17:46:46 +00:00
_args params ["_ctrl","_button"];
2015-07-15 11:11:19 +00:00
GVAR(mouse) set [_button,false];
2015-07-21 17:44:24 +00:00
if (_button == 0) then { GVAR(camDolly) = [0,0]; };
2015-07-15 11:11:19 +00:00
};
case "onmousezchanged": {
2015-07-18 17:46:46 +00:00
_args params ["_ctrl","_zChange"];
2015-07-15 11:33:32 +00:00
2015-07-19 21:30:44 +00:00
// Scroll to change speed, modifier for zoom
2015-07-15 11:33:32 +00:00
if (GVAR(ctrlKey)) then {
2015-07-19 21:30:44 +00:00
GVAR(camZoom) = ((GVAR(camZoom) + _zChange * 0.1) max 0.01) min 2;
2015-07-15 11:33:32 +00:00
} else {
2015-07-21 18:36:20 +00:00
GVAR(camSpeed) = ((GVAR(camSpeed) + _zChange * 0.2) max 0.05) min 10;
2015-07-15 11:33:32 +00:00
};
2015-07-15 11:11:19 +00:00
};
case "onmousemoving": {
2015-07-18 17:46:46 +00:00
_args params ["_ctrl","_x","_y"];
2015-07-15 11:11:19 +00:00
2015-07-18 15:59:05 +00:00
[_x,_y] call FUNC(handleMouse);
2015-07-15 11:11:19 +00:00
};
2015-07-15 11:03:54 +00:00
// Keyboard events
case "onkeydown": {
2015-07-18 17:46:46 +00:00
_args params ["_display","_dik","_shift","_ctrl","_alt"];
2015-07-15 11:03:54 +00:00
2015-07-24 10:12:26 +00:00
// Handle held keys (prevent repeat calling)
if (_dik in GVAR(heldKeys)) exitwith {};
GVAR(heldKeys) pushBack _dik;
2015-07-15 11:03:54 +00:00
switch (_dik) do {
case 1: { // Esc
2015-07-18 14:42:07 +00:00
[player,false] call FUNC(setSpectator); // Handle esc menu goes here, currently closes for purposes of testing
2015-07-15 11:03:54 +00:00
};
2015-07-19 21:50:13 +00:00
case 2: { // 1
2015-07-20 21:45:11 +00:00
[_display,nil,nil,nil,nil,nil,true] call FUNC(toggleInterface);
2015-07-19 21:50:13 +00:00
};
case 3: { // 2
2015-07-20 21:45:11 +00:00
[_display,nil,nil,nil,nil,true] call FUNC(toggleInterface);
2015-07-19 21:50:13 +00:00
};
case 4: { // 3
2015-07-20 21:45:11 +00:00
[_display,true] call FUNC(toggleInterface);
2015-07-19 21:50:13 +00:00
};
2015-07-15 11:03:54 +00:00
case 14: { // Backspace
2015-07-20 21:45:11 +00:00
[_display,nil,nil,true] call FUNC(toggleInterface);
2015-07-15 11:03:54 +00:00
};
2015-07-15 11:11:19 +00:00
case 16: { // Q
2015-07-21 17:05:29 +00:00
GVAR(camBoom) = 0.5;
2015-07-15 11:11:19 +00:00
};
case 17: { // W
2015-07-21 17:44:24 +00:00
GVAR(camDolly) set [1, GVAR(camSpeed)];
2015-07-15 11:11:19 +00:00
};
case 29: { // Ctrl
GVAR(ctrlKey) = true;
};
case 30: { // A
2015-07-21 17:44:24 +00:00
GVAR(camDolly) set [0, -GVAR(camSpeed)];
2015-07-15 11:11:19 +00:00
};
case 31: { // S
2015-07-21 17:44:24 +00:00
GVAR(camDolly) set [1, -GVAR(camSpeed)];
2015-07-15 11:11:19 +00:00
};
case 32: { // D
2015-07-21 17:44:24 +00:00
GVAR(camDolly) set [0, GVAR(camSpeed)];
2015-07-15 11:11:19 +00:00
};
2015-07-16 20:45:52 +00:00
case 35: { // H
2015-07-20 21:45:11 +00:00
[_display,nil,true] call FUNC(toggleInterface);
2015-07-18 14:42:07 +00:00
};
2015-07-15 11:11:19 +00:00
case 44: { // Z
2015-07-21 17:05:29 +00:00
GVAR(camBoom) = -0.5;
2015-07-21 10:59:20 +00:00
};
case 49: { // N
2015-07-24 10:12:26 +00:00
if (_ctrl) then {
[nil,nil,-1] call FUNC(cycleCamera);
} else {
[nil,nil,1] call FUNC(cycleCamera);
};
2015-07-15 11:11:19 +00:00
};
2015-07-15 11:03:54 +00:00
case 50: { // M
2015-07-20 21:45:11 +00:00
[_display,nil,nil,nil,true] call FUNC(toggleInterface);
2015-07-20 19:30:13 +00:00
(_display displayCtrl IDC_MAP) ctrlMapAnimAdd [0, 0.5, [GVAR(camUnit),GVAR(camera)] select (GVAR(camMode) == 0)];
ctrlMapAnimCommit (_display displayCtrl IDC_MAP);
2015-07-15 11:03:54 +00:00
};
2015-07-15 11:33:32 +00:00
case 57: { // Spacebar
2015-07-18 16:13:27 +00:00
// Freecam attachment here, if in external then set cam pos and attach
};
case 200: { // Up arrow
2015-07-21 12:31:13 +00:00
[-1] call FUNC(cycleCamera);
2015-07-15 11:33:32 +00:00
};
2015-07-18 15:20:19 +00:00
case 203: { // Left arrow
2015-07-21 15:06:07 +00:00
[nil,1] call FUNC(cycleCamera);
2015-07-18 15:20:19 +00:00
};
case 205: { // Right arrow
2015-07-21 15:06:07 +00:00
[nil,-1] call FUNC(cycleCamera);
2015-07-18 15:20:19 +00:00
};
2015-07-18 18:05:18 +00:00
case 208: { // Down arrow
2015-07-21 12:31:13 +00:00
[1] call FUNC(cycleCamera);
2015-07-18 18:05:18 +00:00
};
2015-07-15 11:03:54 +00:00
};
true
};
case "onkeyup": {
2015-07-18 17:46:46 +00:00
_args params ["_display","_dik","_shift","_ctrl","_alt"];
2015-07-15 11:03:54 +00:00
2015-07-24 10:12:26 +00:00
// No longer being held
GVAR(heldKeys) = GVAR(heldKeys) - [_dik];
2015-07-15 11:03:54 +00:00
switch (_dik) do {
2015-07-15 11:11:19 +00:00
case 16: { // Q
2015-07-21 17:26:49 +00:00
GVAR(camBoom) = 0;
2015-07-15 11:11:19 +00:00
};
case 17: { // W
2015-07-21 17:44:24 +00:00
GVAR(camDolly) set [1, 0];
2015-07-15 11:11:19 +00:00
};
case 29: { // Ctrl
GVAR(ctrlKey) = false;
};
case 30: { // A
2015-07-21 17:44:24 +00:00
GVAR(camDolly) set [0, 0];
2015-07-15 11:11:19 +00:00
};
case 31: { // S
2015-07-21 17:44:24 +00:00
GVAR(camDolly) set [1, 0];
2015-07-15 11:11:19 +00:00
};
case 32: { // D
2015-07-21 17:44:24 +00:00
GVAR(camDolly) set [0, 0];
2015-07-15 11:11:19 +00:00
};
case 44: { // Z
2015-07-21 17:26:49 +00:00
GVAR(camBoom) = 0;
2015-07-15 11:11:19 +00:00
};
2015-07-15 11:03:54 +00:00
};
true
};
2015-07-16 16:01:04 +00:00
// Tree events
case "ontreedblclick": {
2015-07-16 17:31:49 +00:00
// Update camera view when listbox unit is double clicked on
2015-07-18 17:46:46 +00:00
_args params ["_tree","_sel"];
2015-07-16 17:31:49 +00:00
// Ensure a unit was selected
2015-07-20 16:42:11 +00:00
if (count _sel == 3) then {
2015-07-18 17:46:46 +00:00
private ["_netID","_newUnit","_newMode"];
2015-07-16 17:31:49 +00:00
_netID = (_args select 0) tvData _sel;
2015-07-16 18:43:16 +00:00
_newUnit = objectFromNetId _netID;
2015-07-16 17:31:49 +00:00
// When unit is reselected, toggle camera mode
if (_newUnit == GVAR(camUnit) || GVAR(camMode) == 0) then {
2015-07-17 00:52:08 +00:00
_newMode = [2,2,1] select GVAR(camMode);
2015-07-16 16:01:04 +00:00
};
2015-07-21 14:53:20 +00:00
[_newMode,_newUnit] call FUNC(transitionCamera);
2015-07-16 16:01:04 +00:00
};
};
2015-07-19 12:40:08 +00:00
case "onunitsupdate": {
2015-07-19 22:03:40 +00:00
_args params ["_tree"];
2015-07-21 20:21:46 +00:00
private ["_curSelData","_cachedGrps","_cachedSides","_grp","_side","_sNode","_gNode","_uNode"];
2015-07-19 12:40:08 +00:00
// Cache current selection
2015-07-19 22:03:40 +00:00
_curSelData = _tree tvData (tvCurSel _tree);
2015-07-19 12:40:08 +00:00
// Clear the tree
2015-07-19 22:03:40 +00:00
tvClear _tree;
2015-07-19 12:40:08 +00:00
// Update the tree from the unit list
_cachedGrps = [];
2015-07-21 20:21:46 +00:00
_cachedSides = [];
2015-07-19 12:40:08 +00:00
{
_grp = group _x;
2015-07-21 20:21:46 +00:00
_side = WFSideText side _grp;
2015-07-19 12:40:08 +00:00
2015-07-20 16:42:11 +00:00
// Use correct side node
2015-07-21 20:21:46 +00:00
if !(_side in _cachedSides) then {
// Add side node
_sNode = _tree tvAdd [[], _side];
_cachedSides pushBack _side;
_cachedSides pushBack _sNode;
} else {
// If side already processed, use existing node
_sNode = _cachedSides select ((_cachedSides find _side) + 1);
};
2015-07-20 16:42:11 +00:00
// Use correct group node
if !(_grp in _cachedGrps) then {
// Add group node
_gNode = _tree tvAdd [[_sNode], groupID _grp];
2015-07-19 12:40:08 +00:00
_cachedGrps pushBack _grp;
2015-07-20 16:42:11 +00:00
_cachedGrps pushBack _gNode;
2015-07-19 12:40:08 +00:00
} else {
2015-07-20 16:42:11 +00:00
// If group already processed, use existing node
_gNode = _cachedGrps select ((_cachedGrps find _grp) + 1);
2015-07-19 12:40:08 +00:00
};
2015-07-20 16:42:11 +00:00
_uNode = _tree tvAdd [[_sNode,_gNode], name _x];
_tree tvSetData [[_sNode,_gNode,_uNode], netID _x];
2015-07-19 12:40:08 +00:00
// Preserve the previous selection
2015-07-20 16:42:11 +00:00
if (_curSelData == (_tree tvData [_sNode,_gNode,_uNode])) then {
_tree tvSetCurSel [_sNode,_gNode,_uNode];
2015-07-19 12:40:08 +00:00
};
2015-07-20 16:42:11 +00:00
_tree tvSort [[_sNode,_gNode],false];
_tree tvExpand [_sNode,_gNode];
2015-07-19 12:40:08 +00:00
} forEach GVAR(unitList);
2015-07-21 20:21:46 +00:00
{
if (typeName _x == "SCALAR") then {
_tree tvSort [[_x],false];
_tree tvExpand [_x];
};
} forEach _cachedSides;
_tree tvSort [[],false];
2015-07-19 12:40:08 +00:00
};
2015-07-20 19:30:13 +00:00
// Map events
case "onmapdblclick": {
_args params ["_map","_button","_x","_y","_shift","_ctrl"];
if (GVAR(camMode == 0) && (_button == 0) && _ctrl) then {
_newPos = _map ctrlMapScreenToWorld [_x,_y];
2015-07-21 17:05:29 +00:00
_oldZ = (ASLtoATL GVAR(camPos)) select 2;
2015-07-21 17:07:55 +00:00
_newPos set [2, _oldZ];
2015-07-21 17:05:29 +00:00
GVAR(camPos) = (ATLtoASL _newPos);
2015-07-20 19:30:13 +00:00
};
};
2015-07-15 11:03:54 +00:00
};