From 60b3c6c0f88bdc679a3594a3091ddfa84f4f5009 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sat, 18 Jul 2015 16:50:11 +0100 Subject: [PATCH] Improved camUnit handling --- .../spectator/functions/fnc_handleCamera.sqf | 8 --- .../spectator/functions/fnc_handleUnits.sqf | 59 ++++++++++--------- .../spectator/functions/fnc_updateCamera.sqf | 8 +-- .../spectator/functions/fnc_updateUnits.sqf | 1 + 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/addons/spectator/functions/fnc_handleCamera.sqf b/addons/spectator/functions/fnc_handleCamera.sqf index b7c5154eb7..bd80a0853a 100644 --- a/addons/spectator/functions/fnc_handleCamera.sqf +++ b/addons/spectator/functions/fnc_handleCamera.sqf @@ -59,13 +59,5 @@ switch (GVAR(camMode)) do { [GVAR(camera), GVAR(camTilt), GVAR(camBank)] call BIS_fnc_setPitchBank; }; case 1: { // Internal - // Update view when state of unit changes - if !( - (alive GVAR(camUnit)) && - {vehicle GVAR(camUnit) == GVAR(camUnit)} && - {GVAR(camUnit) in GVAR(unitList)} - ) then { - [] call FUNC(updateCamera); - }; }; }; diff --git a/addons/spectator/functions/fnc_handleUnits.sqf b/addons/spectator/functions/fnc_handleUnits.sqf index d129017ee4..abb0c70736 100644 --- a/addons/spectator/functions/fnc_handleUnits.sqf +++ b/addons/spectator/functions/fnc_handleUnits.sqf @@ -19,6 +19,10 @@ // Kill PFH when display is closed if (isNull (GETUVAR(GVAR(display),displayNull))) 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]; + // Fetch tree disableSerialization; _display = GETUVAR(GVAR(display),displayNull); @@ -33,37 +37,38 @@ tvClear _ctrl; // Update the tree from the unit list _cachedGrps = []; { - // Exclude any currently dead/disabled units - if ((alive _x) && (simulationEnabled _x) && !(_x getVariable [QGVAR(isSpectator), false])) then { - _grp = group _x; - _node = 0; - // If group already exists, find existing node - if !(_grp in _cachedGrps) then { - _side = [west,east,resistance,civilian,sideLogic] find (side _grp); - _node = _ctrl tvCount []; + _grp = group _x; + _node = 0; + // If group already exists, find existing node + if !(_grp in _cachedGrps) then { + _side = [west,east,resistance,civilian,sideLogic] find (side _grp); + _node = _ctrl tvCount []; - _ctrl tvAdd [[], groupID _grp]; - _ctrl tvSetValue [[_node], _side]; + _ctrl tvAdd [[], groupID _grp]; + _ctrl tvSetValue [[_node], _side]; - _cachedGrps pushBack _grp; - } else { - _node = _cachedGrps find _grp; - }; - - _index = _ctrl tvCount [_node]; - - _ctrl tvAdd [[_node], name _x]; - _ctrl tvSetData [[_node,_index], netID _x]; - - // Preserve the previous selection - if (_curSelData == (_ctrl tvData [_node,_index])) then { - _ctrl tvSetCurSel [_node,_index]; - }; - - _ctrl tvSort [[_node],false]; - _ctrl tvExpand [_node]; + _cachedGrps pushBack _grp; + } else { + _node = _cachedGrps find _grp; }; + + _index = _ctrl tvCount [_node]; + + _ctrl tvAdd [[_node], name _x]; + _ctrl tvSetData [[_node,_index], netID _x]; + + // Preserve the previous selection + if (_curSelData == (_ctrl tvData [_node,_index])) then { + _ctrl tvSetCurSel [_node,_index]; + }; + + _ctrl tvSort [[_node],false]; + _ctrl tvExpand [_node]; } forEach GVAR(unitList); +if ((tvCurSel _ctrl) isEqualTo []) then { + [0,objNull] call FUNC(updateCamera); +}; + // Sort group nodes by side _ctrl tvSortByValue [[],false]; diff --git a/addons/spectator/functions/fnc_updateCamera.sqf b/addons/spectator/functions/fnc_updateCamera.sqf index fc16e85d06..679fae56b7 100644 --- a/addons/spectator/functions/fnc_updateCamera.sqf +++ b/addons/spectator/functions/fnc_updateCamera.sqf @@ -11,19 +11,19 @@ if (_newMode != GVAR(camMode)) then { // When no units available to spectate, exit to freecam if (GVAR(unitList) isEqualTo []) then { GVAR(camMode) = 0; + GVAR(camUnit) = objNull; }; if (GVAR(camMode) == 0) then { // Free + // Preserve camUnit value for consistency when manually changing view GVAR(camera) cameraEffect ["internal", "back"]; - GVAR(camUnit) = GVAR(camera); - // HUD stuff showCinemaBorder false; cameraEffectEnableHUD false; } else { - // First ensure valid unit is selected - if !(_newUnit in GVAR(unitList)) then { + // When null unit is given choose random + if (isNull _newUnit) then { _newUnit = GVAR(unitList) select floor(random(count GVAR(unitList))); }; diff --git a/addons/spectator/functions/fnc_updateUnits.sqf b/addons/spectator/functions/fnc_updateUnits.sqf index eca97e6fcc..0f3b244d19 100644 --- a/addons/spectator/functions/fnc_updateUnits.sqf +++ b/addons/spectator/functions/fnc_updateUnits.sqf @@ -61,6 +61,7 @@ if (GVAR(filterSides) == 0) then { (alive _x) && {(_x isKindOf "CAManBase")} && {(side _x) in _sides} && // Side filter + {simulationEnabled _x} {!(_x getVariable [QGVAR(isSpectator), false])} // Who watches the watchmen? ) then { GVAR(unitList) pushBack _x;