ACE3/addons/spectator/functions/fnc_handleInterface.sqf

307 lines
9.2 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"
private ["_mode","_args"];
_mode = _this select 0;
_args = if (count _this > 1) then {_this select 1} else {[]};
switch (toLower _mode) do {
// Safely open/close the interface
case "open": {
// Prevent reopening
if !(isNull (GETUVAR(GVAR(display),displayNull))) exitWith {};
// Initalize preserved variables
2015-07-15 11:11:19 +00:00
if (isNil QGVAR(camMode)) then { GVAR(camMode) = 0; };
if (isNil QGVAR(camPan)) then { GVAR(camPan) = 0; };
if (isNil QGVAR(camPos)) then { GVAR(camPos) = getPos cameraOn; };
2015-07-15 11:33:32 +00:00
if (isNil QGVAR(camUnit)) then { GVAR(camUnit) = objNull; };
2015-07-15 11:11:19 +00:00
2015-07-15 11:03:54 +00:00
if (isNil QGVAR(savedSpots)) then { GVAR(savedSpots) = []; };
if (isNil QGVAR(savedUnits)) then { GVAR(savedUnits) = []; };
2015-07-15 11:11:19 +00:00
// Initalize camera variables
GVAR(camBank) = 0;
GVAR(camBoom) = [false,false];
GVAR(camDolly) = [false,false,false,false];
GVAR(camFocus) = [-1,-1];
2015-07-15 11:33:32 +00:00
GVAR(camFOV) = 0.7;
2015-07-16 22:58:58 +00:00
GVAR(camPos) set [2,20];
GVAR(camSpeed) = 1;
2015-07-16 16:48:32 +00:00
GVAR(camTilt) = -10;
2015-07-15 11:33:32 +00:00
GVAR(camZoom) = 3;
2015-07-15 13:33:11 +00:00
GVAR(gunCam) = false;
2015-07-15 11:11:19 +00:00
// Initalize display variables
GVAR(ctrlKey) = false;
GVAR(mouse) = [false,false];
GVAR(mouseDelta) = [0.5,0.5];
GVAR(mousePos) = [0.5,0.5];
GVAR(mousePosOld) = [0.5,0.5];
2015-07-15 11:03:54 +00:00
// Initalize the camera view
GVAR(camera) = "Camera" camCreate GVAR(camPos);
2015-07-15 11:11:19 +00:00
GVAR(camera) setDir GVAR(camPan);
[] call FUNC(updateView);
2015-07-15 13:33:11 +00:00
2015-07-16 22:58:58 +00:00
GVAR(camera) camSetFOV GVAR(camFOV);
2015-07-15 13:33:11 +00:00
// Handle camera movement
[FUNC(handleCamera), 0] call CBA_fnc_addPerFrameHandler;
2015-07-15 11:03:54 +00:00
2015-07-16 10:15:33 +00:00
// Populate the unit list
[allUnits] call FUNC(updateUnits);
2015-07-15 11:03:54 +00:00
// Create the dialog
createDialog QGVAR(overlay);
// 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(camBank) = nil;
GVAR(camBoom) = nil;
GVAR(camDolly) = nil;
GVAR(camFocus) = nil;
2015-07-15 11:33:32 +00:00
GVAR(camFOV) = nil;
2015-07-15 11:11:19 +00:00
GVAR(camSpeed) = nil;
GVAR(camTilt) = nil;
2015-07-15 11:33:32 +00:00
GVAR(camZoom) = nil;
2015-07-15 13:33:11 +00:00
GVAR(gunCam) = nil;
2015-07-15 11:11:19 +00:00
// Cleanup display variables
GVAR(mouse) = nil;
GVAR(mouseDelta) = nil;
GVAR(mousePos) = nil;
GVAR(mousePosOld) = 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": {
with uiNamespace do {
GVAR(display) = _args select 0;
};
// Initalize the display
_display = _args select 0;
// Hide the map
(_display displayCtrl IDC_MAP) ctrlShow false;
(_display displayCtrl IDC_MAP) mapCenterOnCamera false;
2015-07-15 11:11:19 +00:00
// Set text values
2015-07-16 22:58:58 +00:00
(_display displayCtrl IDC_TOOL_FOCUS) ctrlSetText str(GVAR(camFocus));
(_display displayCtrl IDC_TOOL_FOV) ctrlSetText str(GVAR(camFOV));
(_display displayCtrl IDC_TOOL_SPEED) ctrlSetText format ["%1 m/s",GVAR(camSpeed)];
(_display displayCtrl IDC_TOOL_VIEW) ctrlSetText (["FREE","FIRST","THIRD"] select GVAR(camMode));
2015-07-15 11:11:19 +00:00
2015-07-16 10:15:33 +00:00
// Keep unit tree up to date
2015-07-16 22:58:58 +00:00
[] call FUNC(handleTree);
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-15 11:11:19 +00:00
// Mouse events
case "onmousebuttondown": {
private ["_button"];
_button = _args select 1;
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
GVAR(gunCam) = !GVAR(gunCam);
[] call FUNC(updateView);
2015-07-15 11:33:32 +00:00
};
2015-07-15 11:11:19 +00:00
};
case "onmousebuttonup": {
private ["_button"];
_button = _args select 1;
GVAR(mouse) set [_button,false];
};
case "onmousezchanged": {
private ["_zChange"];
_zChange = _args select 1;
2015-07-15 11:33:32 +00:00
// Scroll to zoom in 3rd person, modifier for FOV
if (GVAR(ctrlKey)) then {
GVAR(camFOV) = ((GVAR(camFOV) - (_zChange * GVAR(camFOV) * 0.2)) max 0.1) min 1;
} else {
GVAR(camZoom) = (GVAR(camZoom) - (_zChange * GVAR(camZoom) * 0.2)) max 0.1;
};
call FUNC(handleCamera);
2015-07-15 11:11:19 +00:00
};
case "onmousemoving": {
private ["_x","_y"];
_x = _args select 1;
_y = _args select 2;
GVAR(mousePos) = [_x,_y];
call FUNC(handleMouse);
};
2015-07-15 11:03:54 +00:00
// Keyboard events
case "onkeydown": {
private ["_display","_dik","_shift","_ctrl","_alt"];
_display = _args select 0;
_dik = _args select 1;
_shift = _args select 2;
_ctrl = _args select 3;
_alt = _args select 4;
switch (_dik) do {
case 1: { // Esc
// Handle esc menu
};
case 14: { // Backspace
private ["_tree","_show"];
_tree = _display displayCtrl IDC_TREE;
_show = !ctrlShown _tree;
_tree ctrlShow _show;
};
2015-07-15 11:11:19 +00:00
case 16: { // Q
GVAR(camBoom) set [0,true];
};
case 17: { // W
GVAR(camDolly) set [0,true];
};
case 29: { // Ctrl
GVAR(ctrlKey) = true;
};
case 30: { // A
GVAR(camDolly) set [2,true];
};
case 31: { // S
GVAR(camDolly) set [1,true];
};
case 32: { // D
GVAR(camDolly) set [3,true];
};
2015-07-16 20:45:52 +00:00
case 35: { // H
2015-07-16 22:58:58 +00:00
private ["_help","_show"];
_help = _display displayCtrl IDC_HELP;
2015-07-16 20:45:52 +00:00
_show = !ctrlShown _help;
_help ctrlShow _show;
};
2015-07-15 11:11:19 +00:00
case 44: { // Z
GVAR(camBoom) set [1,true];
};
2015-07-15 11:03:54 +00:00
case 50: { // M
private ["_map","_show"];
_map = _display displayCtrl IDC_MAP;
_show = !ctrlShown _map;
_map ctrlShow _show;
//[_show] call FUNC(handleMap);
};
2015-07-15 11:33:32 +00:00
case 57: { // Spacebar
2015-07-16 18:43:16 +00:00
[[1,2,0] select GVAR(camMode)] call FUNC(updateView);
2015-07-15 11:33:32 +00:00
};
2015-07-15 11:03:54 +00:00
};
true
};
case "onkeyup": {
private ["_dik","_shift","_ctrl","_alt"];
_dik = _args select 1;
_shift = _args select 2;
_ctrl = _args select 3;
_alt = _args select 4;
switch (_dik) do {
2015-07-15 11:11:19 +00:00
case 16: { // Q
GVAR(camBoom) set [0,false];
};
case 17: { // W
GVAR(camDolly) set [0,false];
};
case 29: { // Ctrl
GVAR(ctrlKey) = false;
};
case 30: { // A
GVAR(camDolly) set [2,false];
};
case 31: { // S
GVAR(camDolly) set [1,false];
};
case 32: { // D
GVAR(camDolly) set [3,false];
};
case 44: { // Z
GVAR(camBoom) set [1,false];
};
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-16 18:43:16 +00:00
private ["_sel","_netID","_newUnit","_newMode"];
2015-07-16 17:31:49 +00:00
_sel = _args select 1;
// Ensure a unit was selected
if (count _sel == 2) then {
_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 {
_newMode = [1,2,1] select GVAR(camMode);
2015-07-16 16:01:04 +00:00
};
2015-07-16 18:43:16 +00:00
GVAR(camUnit) = _newUnit;
[_newMode] call FUNC(updateView);
2015-07-16 16:01:04 +00:00
};
};
2015-07-15 11:03:54 +00:00
};