From 21ce877115268758d2fae2cbd4e9b2c294678c62 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sat, 25 Jul 2015 12:28:03 +0100 Subject: [PATCH] Handle unit icons and provide setting --- addons/spectator/ACE_Settings.hpp | 10 ++-- addons/spectator/CfgVehicles.hpp | 14 ++--- addons/spectator/XEH_postInit.sqf | 9 --- addons/spectator/XEH_preInit.sqf | 1 + .../spectator/functions/fnc_handleIcons.sqf | 57 +++++++++++++++++++ .../functions/fnc_handleInterface.sqf | 3 +- .../functions/fnc_moduleSpectatorSettings.sqf | 2 +- .../functions/fnc_toggleInterface.sqf | 8 +-- .../functions/fnc_transitionCamera.sqf | 6 ++ addons/spectator/stringtable.xml | 12 ++-- 10 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 addons/spectator/functions/fnc_handleIcons.sqf diff --git a/addons/spectator/ACE_Settings.hpp b/addons/spectator/ACE_Settings.hpp index bdf9d5f429..539f7cef2d 100644 --- a/addons/spectator/ACE_Settings.hpp +++ b/addons/spectator/ACE_Settings.hpp @@ -1,11 +1,7 @@ class ACE_Settings { - class GVAR(enabledSystem) { - typeName = "BOOL"; - value = 0; - }; class GVAR(filterUnits) { typeName = "SCALAR"; - value = 0; + value = 1; values[] = {CSTRING(units_none), CSTRING(units_players), CSTRING(units_all)}; }; class GVAR(filterSides) { @@ -23,4 +19,8 @@ class ACE_Settings { value = 0; values[] = {CSTRING(modes_all), CSTRING(visions_nv), CSTRING(visions_ti), "$STR_Special_None"}; }; + class GVAR(unitIcons) { + typeName = "BOOL"; + value = 1; + }; }; diff --git a/addons/spectator/CfgVehicles.hpp b/addons/spectator/CfgVehicles.hpp index d6e21789db..8e685dae07 100644 --- a/addons/spectator/CfgVehicles.hpp +++ b/addons/spectator/CfgVehicles.hpp @@ -9,12 +9,6 @@ class CfgVehicles { isGlobal = 1; author = ECSTRING(common,ACETeam); class Arguments { - class spectatorSystem { - displayName = CSTRING(system_DisplayName); - description = CSTRING(system_Description); - typeName = "BOOL"; - defaultValue = 0; - }; class unitsFilter { displayName = CSTRING(units_DisplayName); description = CSTRING(units_Description); @@ -23,11 +17,11 @@ class CfgVehicles { class none { name = CSTRING(units_none); value = 0; - default = 1; }; class players { name = CSTRING(units_players); value = 1; + default = 1; }; class all { name = CSTRING(units_all); @@ -111,6 +105,12 @@ class CfgVehicles { }; }; }; + class unitIcons { + displayName = CSTRING(icons_DisplayName); + description = CSTRING(icons_Description); + typeName = "BOOL"; + defaultValue = 1; + }; }; class ModuleDescription { description = CSTRING(Settings_Description); diff --git a/addons/spectator/XEH_postInit.sqf b/addons/spectator/XEH_postInit.sqf index 52d5963d09..b0a8be6fdc 100644 --- a/addons/spectator/XEH_postInit.sqf +++ b/addons/spectator/XEH_postInit.sqf @@ -4,16 +4,7 @@ // Add interaction menu exception ["isNotSpectating", {!((_this select 0) getVariable [QGVAR(isSpectator), false])}] call EFUNC(common,addCanInteractWithCondition); -// Run spectator framework if enabled ["SettingsInitialized", { GVAR(availableModes) = [[0,1,2], [1,2], [0], [1], [2]] select GVAR(restrictModes); GVAR(availableVisions) = [[-2,-1,0,1], [-2,-1], [-2,0,1], [-2]] select GVAR(restrictVisions); - - if !(hasInterface) exitWith {}; - - if (GVAR(system)) then { - // Add event handlers to correctly enter spectator upon death - player addEventHandler ["Killed", FUNC(handleKilled)]; - player addEventHandler ["Respawn", FUNC(handleRespawn)]; - }; }] call EFUNC(common,addEventHandler); diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index cf6304f99a..e5872c3272 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -6,6 +6,7 @@ PREP(cacheUnitInfo); PREP(cycleCamera); PREP(handleCamera); PREP(handleCompass); +PREP(handleIcons); PREP(handleInterface); PREP(handleKilled); PREP(handleMouse); diff --git a/addons/spectator/functions/fnc_handleIcons.sqf b/addons/spectator/functions/fnc_handleIcons.sqf new file mode 100644 index 0000000000..c52943ad10 --- /dev/null +++ b/addons/spectator/functions/fnc_handleIcons.sqf @@ -0,0 +1,57 @@ +/* + * Author: SilentSpike + * Handles rendering the spectator 3D unit icons + * + * Arguments: + * 0: Parameters + * 1: PFH handle + * + * Return Value: + * None + * + * Example: + * [ace_spectator_fnc_handleIcons, 0] call CBA_fnc_addPerFrameHandler; + * + * Public: No + */ + +#include "script_component.hpp" + +// Kill PFH when not in free cam (or display is closed) +if (isNil QGVAR(iconHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; + +if !(GVAR(showIcons)) exitWith {}; + +private ["_cachedVehicles","_unit","_cameraPos","_cameraDir","_lambda","_uPos","_cmd","_txt"]; +_cachedVehicles = []; +{ + _unit = vehicle _x; + + // Only try each vehicle once + if !(_unit in _cachedVehicles) then { + _cachedVehicles pushBack _unit; + + // Within 200m + if ((GVAR(camera) distanceSqr _unit) < 40000) then { + _cameraPos = (positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL); + _cameraDir = ((positionCameraToWorld [0, 0, 1]) call EFUNC(common,positionToASL)) vectorDiff _cameraPos; + + // Quick oclussion test (taken from interact_menu) + _lambda = ((getPosASL _x) vectorDiff _cameraPos) vectorDotProduct _cameraDir; + if (_lambda > -1) then { + _uPos = worldToScreen (visiblePosition _unit); + + // Only draw if onscreen + if ((_uPos select 0 > safeZoneXAbs) && (_uPos select 0 < safeZoneXAbs + safeZoneWAbs)) then { + if ((_uPos select 1 > safeZoneY) && (_uPos select 1 < safeZoneY + safeZoneH)) then { + // Use commander's info if available + _cmd = [_x, effectiveCommander _unit] select ((effectiveCommander _unit) in GVAR(unitList)); + _txt = ["", GETVAR(_cmd,GVAR(uName),"")] select (isPlayer _cmd); + + drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", GETVAR(_cmd,GVAR(uColor),[ARR_4(0,0,0,0)]), _unit modelToWorldVisual [0,0,3], 0.7, 0.7, 0, _txt, 1, 0.02]; + }; + }; + }; + }; + }; +} forEach GVAR(unitList); diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index db54d53c09..b69e34c964 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -154,6 +154,7 @@ switch (toLower _mode) do { GVAR(camHandler) = nil; GVAR(compHandler) = nil; + GVAR(iconHandler) = nil; GVAR(toolHandler) = nil; }; // Mouse events @@ -391,7 +392,7 @@ switch (toLower _mode) do { _newPos = _map ctrlMapScreenToWorld [_x,_y]; _oldZ = (ASLtoATL GVAR(camPos)) select 2; _newPos set [2, _oldZ]; - GVAR(camPos) = (ATLtoASL _newPos); + [nil,nil,nil, _newPos] call FUNC(setCameraAttributes); }; }; case "ondraw": { diff --git a/addons/spectator/functions/fnc_moduleSpectatorSettings.sqf b/addons/spectator/functions/fnc_moduleSpectatorSettings.sqf index beb8f0be38..c23fb7ad20 100644 --- a/addons/spectator/functions/fnc_moduleSpectatorSettings.sqf +++ b/addons/spectator/functions/fnc_moduleSpectatorSettings.sqf @@ -19,8 +19,8 @@ params ["_logic", "_units", "_activated"]; if !(_activated) exitWith {}; -[_logic, QGVAR(enabledSystem), "spectatorSystem"] call EFUNC(common,readSettingFromModule); [_logic, QGVAR(filterUnits), "unitsFilter"] call EFUNC(common,readSettingFromModule); [_logic, QGVAR(filterSides), "sidesFilter"] call EFUNC(common,readSettingFromModule); [_logic, QGVAR(restrictModes), "cameraModes"] call EFUNC(common,readSettingFromModule); [_logic, QGVAR(restrictVisions), "visionModes"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(unitIcons), "unitIcons"] call EFUNC(common,readSettingFromModule); diff --git a/addons/spectator/functions/fnc_toggleInterface.sqf b/addons/spectator/functions/fnc_toggleInterface.sqf index 4230040762..609c7cd757 100644 --- a/addons/spectator/functions/fnc_toggleInterface.sqf +++ b/addons/spectator/functions/fnc_toggleInterface.sqf @@ -24,7 +24,7 @@ params ["_display", ["_toggleComp",false], ["_toggleHelp",false], ["_toggleInterface",false], ["_toggleMap",false], ["_toggleTool",false], ["_toggleUnit",false]]; -private ["_comp","_display","_help","_map","_tool","_unit"]; +private ["_comp","_help","_map","_tool","_unit"]; _comp = _display displayCtrl IDC_COMP; _help = _display displayCtrl IDC_HELP; _map = _display displayCtrl IDC_MAP; @@ -75,15 +75,15 @@ if (GVAR(showMap)) then { }; }; -// Only run PFHs for toolbar and compass when respective control is shown, otherwise kill +// Only run PFHs when respective control is shown, otherwise kill if (ctrlShown _comp) then { - if (isNil QGVAR(compHandler)) then { GVAR(compHandler) = [FUNC(handleCompass), 0] call CBA_fnc_addPerFrameHandler; }; + if (isNil QGVAR(compHandler)) then { GVAR(compHandler) = [FUNC(handleCompass), 0, _display] call CBA_fnc_addPerFrameHandler; }; } else { GVAR(compHandler) = nil; }; if (ctrlShown _tool) then { - if (isNil QGVAR(toolHandler)) then { GVAR(toolHandler) = [FUNC(handleToolbar), 0] call CBA_fnc_addPerFrameHandler; }; + if (isNil QGVAR(toolHandler)) then { GVAR(toolHandler) = [FUNC(handleToolbar), 0, _display] call CBA_fnc_addPerFrameHandler; }; } else { GVAR(toolHandler) = nil; }; diff --git a/addons/spectator/functions/fnc_transitionCamera.sqf b/addons/spectator/functions/fnc_transitionCamera.sqf index a6a5d710ca..c498f77a3f 100644 --- a/addons/spectator/functions/fnc_transitionCamera.sqf +++ b/addons/spectator/functions/fnc_transitionCamera.sqf @@ -75,6 +75,11 @@ if (_newMode == 0) then { // Free // Handle camera movement if (isNil QGVAR(camHandler)) then { GVAR(camHandler) = [FUNC(handleCamera), 0] call CBA_fnc_addPerFrameHandler; }; + + // Handle unit icons + if (GVAR(unitIcons)) then { + if (isNil QGVAR(iconHandler)) then { GVAR(iconHandler) = [FUNC(handleIcons), 0] call CBA_fnc_addPerFrameHandler; }; + }; } else { // When null unit is given choose random if (isNull _newUnit) then { @@ -102,6 +107,7 @@ if (_newMode == 0) then { // Free // Terminate camera view GVAR(camera) cameraEffect ["terminate", "back"]; GVAR(camHandler) = nil; + GVAR(iconHandler) = nil; cameraEffectEnableHUD true; }; diff --git a/addons/spectator/stringtable.xml b/addons/spectator/stringtable.xml index cbfad243d7..840e4338e1 100644 --- a/addons/spectator/stringtable.xml +++ b/addons/spectator/stringtable.xml @@ -7,12 +7,6 @@ Configure how the spectator system will operate by default. - - Spectator System - - - Enter spectator mode upon respawn. - Unit filter @@ -79,6 +73,12 @@ Thermal imaging + + Unit icons + + + Render icons above spectatable units. +