diff --git a/addons/spectator/UI/interface.hpp b/addons/spectator/UI/interface.hpp index 30171c7b04..e7e48d13ae 100644 --- a/addons/spectator/UI/interface.hpp +++ b/addons/spectator/UI/interface.hpp @@ -57,12 +57,12 @@ class GVAR(interface) { }; class compass180_270: compass0_90 { idc = IDC_COMP_180; - x = COMPASS_W * 1.5; + x = 0; text = "A3\ui_f_curator\data\cfgIngameUI\compass\texture0_ca.paa"; }; class compass270_0: compass0_90 { idc = IDC_COMP_270; - x = COMPASS_W * 2; + x = COMPASS_W * -0.5; text = "A3\ui_f_curator\data\cfgIngameUI\compass\texture90_ca.paa"; }; class compassCaret: RscFrame { @@ -147,14 +147,14 @@ class GVAR(interface) { class unitTools: RscControlsGroupNoScrollbars { idc = IDC_UNIT; x = safeZoneX; - y = safeZoneY; + y = safeZoneY + TOOL_H * 2; w = TOOL_W * 2; h = safeZoneH; class controls { class unitTree: RscTree { idc = IDC_UNIT_TREE; x = 0; - y = TOOL_H * 2; + y = 0; w = TOOL_W * 2; h = safeZoneH - TOOL_H * 5; sizeEx = H_PART(0.8); @@ -170,15 +170,15 @@ class GVAR(interface) { multiselectEnabled = 0; onTreeDblClick = QUOTE([ARR_2('onTreeDblClick',_this)] call FUNC(handleInterface)); }; - class unitRefresh: RscButtonMenu { + class unitRandom: RscButtonMenu { x = 0; - y = safeZoneH - TOOL_H * 3; + y = safeZoneH - TOOL_H * 5; w = TOOL_W * 2; h = TOOL_H; sizeEx = TOOL_H; colorBackground[] = {COL_FORE_D}; - text = CSTRING(RefreshList); - action = QUOTE([] call FUNC(updateUnits)); + text = CSTRING(RandomUnit); + action = QUOTE([nil,objNull] call FUNC(updateCamera)); }; }; }; diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index 7cd71e3e71..52bcb614b3 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -3,6 +3,7 @@ ADDON = false; PREP(handleCamera); +PREP(handleCompass); PREP(handleInterface); PREP(handleKilled); PREP(handleMouse); diff --git a/addons/spectator/functions/fnc_handleCamera.sqf b/addons/spectator/functions/fnc_handleCamera.sqf index 7f1646c5c6..cbedd66a86 100644 --- a/addons/spectator/functions/fnc_handleCamera.sqf +++ b/addons/spectator/functions/fnc_handleCamera.sqf @@ -3,7 +3,8 @@ * Handles free camera manipulation according to input * * Arguments: - * None + * 0: Parameters + * 1: PFH handle * * Return Value: * None diff --git a/addons/spectator/functions/fnc_handleCompass.sqf b/addons/spectator/functions/fnc_handleCompass.sqf new file mode 100644 index 0000000000..02a3eae24a --- /dev/null +++ b/addons/spectator/functions/fnc_handleCompass.sqf @@ -0,0 +1,69 @@ +/* + * Author: SilentSpike, voiper + * Handles the spectator UI compass + * + * Arguments: + * 0: Parameters + * 1: PFH handle + * + * Return Value: + * None + * + * Example: + * [ace_spectator_fnc_handleCompass, 0] call CBA_fnc_addPerFrameHandler; + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_display"]; + +// Kill PFH when display is closed +if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; + +private ["_compass","_NE","_ES","_SW","_WN","_compassW","_degree","_heading","_offset","_positions","_sequence"]; + +_compass = _display displayCtrl IDC_COMP; + +_NE = _compass controlsGroupCtrl IDC_COMP_0; +_ES = _compass controlsGroupCtrl IDC_COMP_90; +_SW = _compass controlsGroupCtrl IDC_COMP_180; +_WN = _compass controlsGroupCtrl IDC_COMP_270; + +_compassW = (ctrlPosition _compass) select 2; +_degree = _compassW / 180; + +// Get direction of screen rather than object (accounts for unit freelook) +_heading = (positionCameraToWorld [0,0,1]) vectorDiff (positionCameraToWorld [0,0,0]); +_heading = (((_heading select 0) atan2 (_heading select 1)) + 360) % 360; +_offset = -(_heading % 90) * _degree; + +_positions = [ + [_compassW * -0.5 + _offset, 0], + [_offset, 0], + [_compassW * 0.5 + _offset, 0], + [_compassW + _offset, 0] +]; + +systemChat str(_heading); + +_sequence = if (_heading < 90) then { + [_SW, _WN, _NE, _ES] +} else { + if (_heading < 180) then { + [_WN, _NE, _ES, _SW] + } else { + if (_heading < 270) then { + [_NE, _ES, _SW, _WN] + } else { + [_ES, _SW, _WN, _NE] + }; + }; +}; + + +{ + _x ctrlSetPosition (_positions select _forEachIndex); + _x ctrlCommit 0; +} forEach _sequence; diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index 9d9002ff37..1ff6a6627b 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -49,9 +49,6 @@ switch (toLower _mode) do { GVAR(camera) camSetFOV GVAR(camFOV); - // Populate the unit list - [] call FUNC(updateUnits); - // Create the dialog createDialog QGVAR(interface); @@ -120,7 +117,10 @@ switch (toLower _mode) do { (_display displayCtrl IDC_TOOL_VIEW) ctrlSetText (["FREE","FIRST","THIRD"] select GVAR(camMode)); // Keep unit tree up to date - [FUNC(handleUnits), 10] call CBA_fnc_addPerFrameHandler; + [FUNC(handleUnits), 20, _display] call CBA_fnc_addPerFrameHandler; + + // Handle the compass heading + [FUNC(handleCompass), 0, _display] call CBA_fnc_addPerFrameHandler; // Hacky way to enable keybindings //_display displayAddEventHandler ["KeyUp", {[_this,'keyup'] call CBA_events_fnc_keyHandler}]; diff --git a/addons/spectator/functions/fnc_handleUnits.sqf b/addons/spectator/functions/fnc_handleUnits.sqf index c0a1f5d060..2b753a5578 100644 --- a/addons/spectator/functions/fnc_handleUnits.sqf +++ b/addons/spectator/functions/fnc_handleUnits.sqf @@ -1,10 +1,11 @@ /* * Author: SilentSpike - * Maintains the unit list and updates the unit tree accordingly + * Maintains the spectatable unit list and updates the unit tree accordingly * Also updates current camera unit when status changes * * Arguments: - * None + * 0: Parameters + * 1: PFH handle * * Return Value: * None @@ -17,23 +18,22 @@ #include "script_component.hpp" +params ["_display"]; + // Kill PFH when display is closed -if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; +if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; // Remove all dead and null units from the list -GVAR(unitList) = GVAR(unitList) - allDead; -GVAR(unitList) = GVAR(unitList) - [objNull]; +[] call FUNC(updateUnits); // Camera shouldn't stay on unit that isn't in the list if !(GVAR(camUnit) in GVAR(unitList)) then { [0,objNull] call FUNC(updateCamera); }; -private ["_display","_ctrl","_curSelData","_cachedGrps","_grp","_node","_side","_index"]; +private ["_ctrl","_curSelData","_cachedGrps","_grp","_node","_side","_index"]; // Fetch tree -disableSerialization; -_display = GETUVAR(GVAR(display),displayNull); _ctrl = (_display displayCtrl IDC_UNIT) controlsGroupCtrl IDC_UNIT_TREE; // Cache current selection diff --git a/addons/spectator/stringtable.xml b/addons/spectator/stringtable.xml index 2c4e6570ed..e714a3e389 100644 --- a/addons/spectator/stringtable.xml +++ b/addons/spectator/stringtable.xml @@ -56,8 +56,8 @@ Spectator Controls - - Refresh Units + + Random Unit