ACE3/addons/spectator/functions/fnc_handleInterface.sqf

328 lines
10 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
GVAR(camBoom) = [false,false];
GVAR(camDolly) = [false,false,false,false];
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;
GVAR(mouse) = [false,false];
GVAR(mousePos) = [0.5,0.5];
2015-07-15 11:03:54 +00:00
// Initalize the camera view
GVAR(camera) = "Camera" camCreate 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-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-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
GVAR(gunCam) = !GVAR(gunCam);
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];
};
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-19 21:30:44 +00:00
GVAR(camSpeed) = (GVAR(camSpeed) + _zChange * 0.2) max 0.05;
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
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
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-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
GVAR(camBoom) set [1,true];
2015-07-21 10:59:20 +00:00
};
case 49: { // N
2015-07-21 12:31:13 +00:00
[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
};
case 205: { // Right arrow
};
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
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-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-20 16:42:11 +00:00
private ["_curSelData","_cachedGrps","_grp","_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
2015-07-20 16:42:11 +00:00
// Add side nodes
{
_tree tvAdd [[], _x];
_tree tvExpand [_forEachIndex];
} forEach ["West","East","Resistance","Civilian","Unknown"];
2015-07-19 12:40:08 +00:00
// Update the tree from the unit list
_cachedGrps = [];
{
_grp = group _x;
2015-07-20 16:42:11 +00:00
// Use correct side node
_sNode = [west,east,resistance,civilian] find (side _grp);
if (_sNode == -1) then { _sNode = 4 };
// 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-20 16:42:11 +00:00
{ _tree tvSort [[_x], false]; } forEach [0,1,2,3,4];
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-20 22:30:18 +00:00
_newPos set [2, GVAR(camPos) select 2];
GVAR(camPos) = _newPos;
2015-07-20 19:30:13 +00:00
};
};
2015-07-15 11:03:54 +00:00
};