Function cleanup

This commit is contained in:
SilentSpike 2015-07-18 18:46:46 +01:00
parent f7cf983e92
commit 7091ac21e9
9 changed files with 62 additions and 44 deletions

View File

@ -17,7 +17,7 @@ PREP(updateUnits);
// Permanent variables // Permanent variables
GVAR(camMode) = 0; GVAR(camMode) = 0;
GVAR(camPan) = 0; GVAR(camPan) = 0;
GVAR(camPos) = getPos cameraOn; GVAR(camPos) = [worldSize,worldSize,0];
GVAR(camUnit) = objNull; GVAR(camUnit) = objNull;
GVAR(showComp) = true; GVAR(showComp) = true;

View File

@ -19,6 +19,8 @@
// Kill PFH when not in free cam (or display is closed) // Kill PFH when not in free cam (or display is closed)
if (isNil QGVAR(camHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; if (isNil QGVAR(camHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
private ["_oldPos","_mX","_mY","_mZ","_pan","_x","_y","_z"];
_oldPos = getPosASL GVAR(camera); _oldPos = getPosASL GVAR(camera);
_mX = 0; _mX = 0;
_mY = 0; _mY = 0;

View File

@ -17,10 +17,7 @@
#include "script_component.hpp" #include "script_component.hpp"
private ["_mode","_args"]; params ["_mode",["_args",[]]];
_mode = _this select 0;
_args = if (count _this > 1) then {_this select 1} else {[]};
switch (toLower _mode) do { switch (toLower _mode) do {
// Safely open/close the interface // Safely open/close the interface
@ -92,10 +89,9 @@ switch (toLower _mode) do {
GVAR(gunCam) = nil; GVAR(gunCam) = nil;
// Cleanup display variables // Cleanup display variables
GVAR(ctrlKey) = nil;
GVAR(mouse) = nil; GVAR(mouse) = nil;
GVAR(mouseDelta) = nil;
GVAR(mousePos) = nil; GVAR(mousePos) = nil;
GVAR(mousePosOld) = nil;
// Reset nametag settings // Reset nametag settings
if (["ace_nametags"] call EFUNC(common,isModLoaded)) then { if (["ace_nametags"] call EFUNC(common,isModLoaded)) then {
@ -106,12 +102,11 @@ switch (toLower _mode) do {
}; };
// Dialog events // Dialog events
case "onload": { case "onload": {
with uiNamespace do { _args params ["_display"];
GVAR(display) = _args select 0;
};
// Initalize the display with uiNamespace do {
_display = _args select 0; GVAR(display) = _display;
};
// Always show interface and hide map upon opening // Always show interface and hide map upon opening
GVAR(showInterface) = true; GVAR(showInterface) = true;
@ -140,8 +135,7 @@ switch (toLower _mode) do {
}; };
// Mouse events // Mouse events
case "onmousebuttondown": { case "onmousebuttondown": {
private ["_button"]; _args params ["_ctrl","_button"];
_button = _args select 1;
GVAR(mouse) set [_button,true]; GVAR(mouse) set [_button,true];
// Detect right click // Detect right click
@ -152,13 +146,12 @@ switch (toLower _mode) do {
}; };
}; };
case "onmousebuttonup": { case "onmousebuttonup": {
private ["_button"]; _args params ["_ctrl","_button"];
_button = _args select 1;
GVAR(mouse) set [_button,false]; GVAR(mouse) set [_button,false];
}; };
case "onmousezchanged": { case "onmousezchanged": {
private ["_zChange"]; _args params ["_ctrl","_zChange"];
_zChange = _args select 1;
// Scroll to zoom in 3rd person, modifier for FOV // Scroll to zoom in 3rd person, modifier for FOV
if (GVAR(ctrlKey)) then { if (GVAR(ctrlKey)) then {
@ -168,20 +161,13 @@ switch (toLower _mode) do {
}; };
}; };
case "onmousemoving": { case "onmousemoving": {
private ["_x","_y"]; _args params ["_ctrl","_x","_y"];
_x = _args select 1;
_y = _args select 2;
[_x,_y] call FUNC(handleMouse); [_x,_y] call FUNC(handleMouse);
}; };
// Keyboard events // Keyboard events
case "onkeydown": { case "onkeydown": {
private ["_display","_dik","_shift","_ctrl","_alt"]; _args params ["_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 { switch (_dik) do {
case 1: { // Esc case 1: { // Esc
@ -253,11 +239,7 @@ switch (toLower _mode) do {
true true
}; };
case "onkeyup": { case "onkeyup": {
private ["_dik","_shift","_ctrl","_alt"]; _args params ["_display","_dik","_shift","_ctrl","_alt"];
_dik = _args select 1;
_shift = _args select 2;
_ctrl = _args select 3;
_alt = _args select 4;
switch (_dik) do { switch (_dik) do {
case 16: { // Q case 16: { // Q
@ -288,11 +270,11 @@ switch (toLower _mode) do {
// Tree events // Tree events
case "ontreedblclick": { case "ontreedblclick": {
// Update camera view when listbox unit is double clicked on // Update camera view when listbox unit is double clicked on
private ["_sel","_netID","_newUnit","_newMode"]; _args params ["_tree","_sel"];
_sel = _args select 1;
// Ensure a unit was selected // Ensure a unit was selected
if (count _sel == 2) then { if (count _sel == 2) then {
private ["_netID","_newUnit","_newMode"];
_netID = (_args select 0) tvData _sel; _netID = (_args select 0) tvData _sel;
_newUnit = objectFromNetId _netID; _newUnit = objectFromNetId _netID;

View File

@ -14,9 +14,7 @@
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit","_killer"]; params ["_unit","_killer"];
_unit = _this select 0;
_killer = _this select 1;
// Remove from group to prevent appearing on HUD upon respawn // Remove from group to prevent appearing on HUD upon respawn
[_unit, true, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide); [_unit, true, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide);

View File

@ -1,6 +1,7 @@
/* /*
* Author: SilentSpike * Author: SilentSpike
* Tracks the the unit list and updates the unit tree according to its status * Maintains the unit list and updates the unit tree accordingly
* Also updates current camera unit when status changes
* *
* Arguments: * Arguments:
* None <NIL> * None <NIL>
@ -28,6 +29,8 @@ if !(GVAR(camUnit) in GVAR(unitList)) then {
[0,objNull] call FUNC(updateCamera); [0,objNull] call FUNC(updateCamera);
}; };
private ["_display","_ctrl","_curSelData","_cachedGrps","_grp","_node","_side","_index"];
// Fetch tree // Fetch tree
disableSerialization; disableSerialization;
_display = GETUVAR(GVAR(display),displayNull); _display = GETUVAR(GVAR(display),displayNull);

View File

@ -15,10 +15,7 @@
#include "script_component.hpp" #include "script_component.hpp"
private ["_logic", "_units", "_activated"]; params ["_logic", "_units", "_activated"];
_logic = _this select 0;
_units = _this select 1;
_activated = _this select 2;
if !(_activated) exitWith {}; if !(_activated) exitWith {};

View File

@ -57,7 +57,7 @@ if (_set) then {
[_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit); [_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit);
[_unit, QGVAR(isSpectator)] call EFUNC(common,unmuteUnit); [_unit, QGVAR(isSpectator)] call EFUNC(common,unmuteUnit);
private ["_marker"]; private "_marker";
_marker = ["respawn_west","respawn_east","respawn_guerrila","respawn_civilian"] select ([west,east,resistance,civilian] find (side group _unit)); _marker = ["respawn_west","respawn_east","respawn_guerrila","respawn_civilian"] select ([west,east,resistance,civilian] find (side group _unit));
_unit setPos (getMarkerPos _marker); _unit setPos (getMarkerPos _marker);
}; };

View File

@ -1,3 +1,23 @@
/*
* Author: SilentSpike
* Updates the spectator camera view mode and unit
*
* Arguments:
* 0: Camera mode <NUMBER>
* - 0: Free
* - 1: Internal
* - 2: External
* 1: Camera unit <OBJECT>
*
* Return Value:
* None <NIL>
*
* Example:
* [0,objNull] call ace_spectator_fnc_updateCamera
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
params [["_newMode",GVAR(camMode)],["_newUnit",GVAR(camUnit)]]; params [["_newMode",GVAR(camMode)],["_newUnit",GVAR(camUnit)]];

View File

@ -1,3 +1,19 @@
/*
* Author: SilentSpike
* Correctly handles toggling of spectator interface elements for clean UX
*
* Arguments:
* None <NIL>
*
* Return Value:
* None <NIL>
*
* Example:
* [] call ace_spectator_fnc_updateInterface
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
private ["_display","_elements","_show"]; private ["_display","_elements","_show"];
@ -7,7 +23,7 @@ _display = GETUVAR(GVAR(display),displayNull);
_elements = [IDC_COMP,IDC_HELP,IDC_MAP,IDC_TOOL,IDC_UNIT]; _elements = [IDC_COMP,IDC_HELP,IDC_MAP,IDC_TOOL,IDC_UNIT];
_show = [GVAR(showComp),GVAR(showHelp),GVAR(showMap),GVAR(showTool),GVAR(showUnit)]; _show = [GVAR(showComp),GVAR(showHelp),GVAR(showMap),GVAR(showTool),GVAR(showUnit)];
// Hide/show interface elements in accordance with good UX design // Hide/show interface elements as appropriate
if (GVAR(showInterface)) then { if (GVAR(showInterface)) then {
{ {
(_display displayCtrl _x) ctrlShow (_show select _forEachIndex); (_display displayCtrl _x) ctrlShow (_show select _forEachIndex);