diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index c6c1e91a50..7cd71e3e71 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -17,7 +17,7 @@ PREP(updateUnits); // Permanent variables GVAR(camMode) = 0; GVAR(camPan) = 0; -GVAR(camPos) = getPos cameraOn; +GVAR(camPos) = [worldSize,worldSize,0]; GVAR(camUnit) = objNull; GVAR(showComp) = true; diff --git a/addons/spectator/functions/fnc_handleCamera.sqf b/addons/spectator/functions/fnc_handleCamera.sqf index 0c79191b63..7f1646c5c6 100644 --- a/addons/spectator/functions/fnc_handleCamera.sqf +++ b/addons/spectator/functions/fnc_handleCamera.sqf @@ -19,6 +19,8 @@ // Kill PFH when not in free cam (or display is closed) 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); _mX = 0; _mY = 0; diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index f4a6bb5923..5c00d5da3a 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -17,10 +17,7 @@ #include "script_component.hpp" -private ["_mode","_args"]; - -_mode = _this select 0; -_args = if (count _this > 1) then {_this select 1} else {[]}; +params ["_mode",["_args",[]]]; switch (toLower _mode) do { // Safely open/close the interface @@ -92,10 +89,9 @@ switch (toLower _mode) do { GVAR(gunCam) = nil; // Cleanup display variables + GVAR(ctrlKey) = nil; GVAR(mouse) = nil; - GVAR(mouseDelta) = nil; GVAR(mousePos) = nil; - GVAR(mousePosOld) = nil; // Reset nametag settings if (["ace_nametags"] call EFUNC(common,isModLoaded)) then { @@ -106,12 +102,11 @@ switch (toLower _mode) do { }; // Dialog events case "onload": { - with uiNamespace do { - GVAR(display) = _args select 0; - }; + _args params ["_display"]; - // Initalize the display - _display = _args select 0; + with uiNamespace do { + GVAR(display) = _display; + }; // Always show interface and hide map upon opening GVAR(showInterface) = true; @@ -140,8 +135,7 @@ switch (toLower _mode) do { }; // Mouse events case "onmousebuttondown": { - private ["_button"]; - _button = _args select 1; + _args params ["_ctrl","_button"]; GVAR(mouse) set [_button,true]; // Detect right click @@ -152,13 +146,12 @@ switch (toLower _mode) do { }; }; case "onmousebuttonup": { - private ["_button"]; - _button = _args select 1; + _args params ["_ctrl","_button"]; + GVAR(mouse) set [_button,false]; }; case "onmousezchanged": { - private ["_zChange"]; - _zChange = _args select 1; + _args params ["_ctrl","_zChange"]; // Scroll to zoom in 3rd person, modifier for FOV if (GVAR(ctrlKey)) then { @@ -168,20 +161,13 @@ switch (toLower _mode) do { }; }; case "onmousemoving": { - private ["_x","_y"]; - _x = _args select 1; - _y = _args select 2; + _args params ["_ctrl","_x","_y"]; [_x,_y] call FUNC(handleMouse); }; // 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; + _args params ["_display","_dik","_shift","_ctrl","_alt"]; switch (_dik) do { case 1: { // Esc @@ -253,11 +239,7 @@ switch (toLower _mode) do { true }; case "onkeyup": { - private ["_dik","_shift","_ctrl","_alt"]; - _dik = _args select 1; - _shift = _args select 2; - _ctrl = _args select 3; - _alt = _args select 4; + _args params ["_display","_dik","_shift","_ctrl","_alt"]; switch (_dik) do { case 16: { // Q @@ -288,11 +270,11 @@ switch (toLower _mode) do { // Tree events case "ontreedblclick": { // Update camera view when listbox unit is double clicked on - private ["_sel","_netID","_newUnit","_newMode"]; - _sel = _args select 1; + _args params ["_tree","_sel"]; // Ensure a unit was selected if (count _sel == 2) then { + private ["_netID","_newUnit","_newMode"]; _netID = (_args select 0) tvData _sel; _newUnit = objectFromNetId _netID; diff --git a/addons/spectator/functions/fnc_handleKilled.sqf b/addons/spectator/functions/fnc_handleKilled.sqf index bea6db537f..adae56f8cd 100644 --- a/addons/spectator/functions/fnc_handleKilled.sqf +++ b/addons/spectator/functions/fnc_handleKilled.sqf @@ -14,9 +14,7 @@ #include "script_component.hpp" -private ["_unit","_killer"]; -_unit = _this select 0; -_killer = _this select 1; +params ["_unit","_killer"]; // Remove from group to prevent appearing on HUD upon respawn [_unit, true, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide); diff --git a/addons/spectator/functions/fnc_handleUnits.sqf b/addons/spectator/functions/fnc_handleUnits.sqf index 5227e49eaf..c0a1f5d060 100644 --- a/addons/spectator/functions/fnc_handleUnits.sqf +++ b/addons/spectator/functions/fnc_handleUnits.sqf @@ -1,6 +1,7 @@ /* * 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: * None @@ -28,6 +29,8 @@ if !(GVAR(camUnit) in GVAR(unitList)) then { [0,objNull] call FUNC(updateCamera); }; +private ["_display","_ctrl","_curSelData","_cachedGrps","_grp","_node","_side","_index"]; + // Fetch tree disableSerialization; _display = GETUVAR(GVAR(display),displayNull); diff --git a/addons/spectator/functions/fnc_moduleSpectatorSettings.sqf b/addons/spectator/functions/fnc_moduleSpectatorSettings.sqf index bda2479df9..267dff0dd9 100644 --- a/addons/spectator/functions/fnc_moduleSpectatorSettings.sqf +++ b/addons/spectator/functions/fnc_moduleSpectatorSettings.sqf @@ -15,10 +15,7 @@ #include "script_component.hpp" -private ["_logic", "_units", "_activated"]; -_logic = _this select 0; -_units = _this select 1; -_activated = _this select 2; +params ["_logic", "_units", "_activated"]; if !(_activated) exitWith {}; diff --git a/addons/spectator/functions/fnc_setSpectator.sqf b/addons/spectator/functions/fnc_setSpectator.sqf index 7624b8f7c3..74834f5606 100644 --- a/addons/spectator/functions/fnc_setSpectator.sqf +++ b/addons/spectator/functions/fnc_setSpectator.sqf @@ -57,7 +57,7 @@ if (_set) then { [_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit); [_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)); _unit setPos (getMarkerPos _marker); }; diff --git a/addons/spectator/functions/fnc_updateCamera.sqf b/addons/spectator/functions/fnc_updateCamera.sqf index 77fb53a6f0..a377bb50f2 100644 --- a/addons/spectator/functions/fnc_updateCamera.sqf +++ b/addons/spectator/functions/fnc_updateCamera.sqf @@ -1,3 +1,23 @@ +/* + * Author: SilentSpike + * Updates the spectator camera view mode and unit + * + * Arguments: + * 0: Camera mode + * - 0: Free + * - 1: Internal + * - 2: External + * 1: Camera unit + * + * Return Value: + * None + * + * Example: + * [0,objNull] call ace_spectator_fnc_updateCamera + * + * Public: No + */ + #include "script_component.hpp" params [["_newMode",GVAR(camMode)],["_newUnit",GVAR(camUnit)]]; diff --git a/addons/spectator/functions/fnc_updateInterface.sqf b/addons/spectator/functions/fnc_updateInterface.sqf index 0d9e19fdf9..98bb30540a 100644 --- a/addons/spectator/functions/fnc_updateInterface.sqf +++ b/addons/spectator/functions/fnc_updateInterface.sqf @@ -1,3 +1,19 @@ +/* + * Author: SilentSpike + * Correctly handles toggling of spectator interface elements for clean UX + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [] call ace_spectator_fnc_updateInterface + * + * Public: No + */ + #include "script_component.hpp" private ["_display","_elements","_show"]; @@ -7,7 +23,7 @@ _display = GETUVAR(GVAR(display),displayNull); _elements = [IDC_COMP,IDC_HELP,IDC_MAP,IDC_TOOL,IDC_UNIT]; _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 { { (_display displayCtrl _x) ctrlShow (_show select _forEachIndex);