mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Fix virtual spectator breaking if template active (#5466)
* Simplify virtual spectator code * Rename camTarget GVAR for linter * Fix respawn template breaking virtual spectators
This commit is contained in:
parent
1ab7a886e7
commit
2a9358ab03
@ -26,15 +26,13 @@ if (isServer) then {
|
|||||||
|
|
||||||
[QGVAR(stageSpectator), FUNC(stageSpectator)] call CBA_fnc_addEventHandler;
|
[QGVAR(stageSpectator), FUNC(stageSpectator)] call CBA_fnc_addEventHandler;
|
||||||
|
|
||||||
// Delay until local player (must not be ACE_Player) is fully initalized
|
// A virtual spectator cannot exist without an interface
|
||||||
[
|
if (hasInterface) then {
|
||||||
{ !isNil { player } && { !isNull player } },
|
// Local player (not ACE_Player) must be initalized to check
|
||||||
{
|
[
|
||||||
// Initalise virtual spectator players (must not be ACE_Player)
|
{ !isNull player },
|
||||||
[QGVAR(virtual),"initpost",{
|
{
|
||||||
if !(GVAR(isSet)) then {
|
if (player isKindOf QGVAR(virtual)) then { [true] call FUNC(setSpectator); };
|
||||||
if (player == (_this select 0)) then { [true] call FUNC(setSpectator) };
|
}
|
||||||
};
|
] call CBA_fnc_waitUntilAndExecute;
|
||||||
},false,[],true] call CBA_fnc_addClassEventHandler;
|
};
|
||||||
},[]
|
|
||||||
] call CBA_fnc_waitUntilAndExecute;
|
|
||||||
|
@ -28,7 +28,7 @@ if (_init) then {
|
|||||||
// Start tracking camera attributes if not pre-set by public function
|
// Start tracking camera attributes if not pre-set by public function
|
||||||
ISNILS(GVAR(camMode),MODE_FREE);
|
ISNILS(GVAR(camMode),MODE_FREE);
|
||||||
ISNILS(GVAR(camVision),VISION_NORM);
|
ISNILS(GVAR(camVision),VISION_NORM);
|
||||||
ISNILS(GVAR(camTarget),objNull);
|
ISNILS(GVAR(camFocus),objNull);
|
||||||
|
|
||||||
// Ticking related
|
// Ticking related
|
||||||
GVAR(camDeltaTime) = 0;
|
GVAR(camDeltaTime) = 0;
|
||||||
@ -79,7 +79,7 @@ if (_init) then {
|
|||||||
GVAR(camera) = _camera;
|
GVAR(camera) = _camera;
|
||||||
|
|
||||||
// Create dummy target used for follow camera
|
// Create dummy target used for follow camera
|
||||||
GVAR(camDummy) = "Logic" createVehicleLocal getPosASLVisual GVAR(camTarget);
|
GVAR(camDummy) = "Logic" createVehicleLocal getPosASLVisual GVAR(camFocus);
|
||||||
|
|
||||||
// Handle initial camera mode limitation
|
// Handle initial camera mode limitation
|
||||||
if !(GVAR(camMode) in GVAR(availableModes)) then {
|
if !(GVAR(camMode) in GVAR(availableModes)) then {
|
||||||
@ -87,7 +87,7 @@ if (_init) then {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// If inital camera mode is not free cam and no focus, find initial focus
|
// If inital camera mode is not free cam and no focus, find initial focus
|
||||||
if (GVAR(camMode) != MODE_FREE && isNull GVAR(camTarget)) then {
|
if (GVAR(camMode) != MODE_FREE && isNull GVAR(camFocus)) then {
|
||||||
[true] call FUNC(setFocus);
|
[true] call FUNC(setFocus);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ if (_init) then {
|
|||||||
// Stop tracking everything
|
// Stop tracking everything
|
||||||
GVAR(camMode) = nil;
|
GVAR(camMode) = nil;
|
||||||
GVAR(camVision) = nil;
|
GVAR(camVision) = nil;
|
||||||
GVAR(camTarget) = nil;
|
GVAR(camFocus) = nil;
|
||||||
GVAR(camDeltaTime) = nil;
|
GVAR(camDeltaTime) = nil;
|
||||||
GVAR(camLastTickTime) = nil;
|
GVAR(camLastTickTime) = nil;
|
||||||
GVAR(camHasTarget) = nil;
|
GVAR(camHasTarget) = nil;
|
||||||
|
@ -22,7 +22,7 @@ params ["_newMode"];
|
|||||||
|
|
||||||
private _oldMode = GVAR(camMode);
|
private _oldMode = GVAR(camMode);
|
||||||
private _modes = GVAR(availableModes);
|
private _modes = GVAR(availableModes);
|
||||||
private _focus = GVAR(camTarget);
|
private _focus = GVAR(camFocus);
|
||||||
|
|
||||||
// If new mode isn't available then keep current (unless current also isn't)
|
// If new mode isn't available then keep current (unless current also isn't)
|
||||||
if !(_newMode in _modes) then {
|
if !(_newMode in _modes) then {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
BEGIN_COUNTER(camTick);
|
BEGIN_COUNTER(camTick);
|
||||||
private _cameraMode = GVAR(camMode);
|
private _cameraMode = GVAR(camMode);
|
||||||
private _camTarget = GVAR(camTarget);
|
private _camTarget = GVAR(camFocus);
|
||||||
|
|
||||||
// UI mouse handler makes use of delta time between camera ticks
|
// UI mouse handler makes use of delta time between camera ticks
|
||||||
private _currentTime = diag_tickTime;
|
private _currentTime = diag_tickTime;
|
||||||
@ -56,7 +56,7 @@ if (_cameraMode != MODE_FREE) then {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Refresh the local variable
|
// Refresh the local variable
|
||||||
_camTarget = GVAR(camTarget);
|
_camTarget = GVAR(camFocus);
|
||||||
|
|
||||||
// Focus get in / out of vehicle state
|
// Focus get in / out of vehicle state
|
||||||
if !(isNull _camTarget) then {
|
if !(isNull _camTarget) then {
|
||||||
|
@ -17,12 +17,12 @@
|
|||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
if !(isNil QGVAR(camera)) then {
|
if !(isNil QGVAR(camera)) then {
|
||||||
[GVAR(camMode), GVAR(camTarget), GVAR(camVision), getPosATL GVAR(camera), getDirVisual GVAR(camera)]
|
[GVAR(camMode), GVAR(camFocus), GVAR(camVision), getPosATL GVAR(camera), getDirVisual GVAR(camera)]
|
||||||
} else {
|
} else {
|
||||||
// These values could be pre-set by function
|
// These values could be pre-set by function
|
||||||
[
|
[
|
||||||
GETMVAR(GVAR(camMode),0),
|
GETMVAR(GVAR(camMode),0),
|
||||||
GETMVAR(GVAR(camTarget),objNull),
|
GETMVAR(GVAR(camFocus),objNull),
|
||||||
GETMVAR(GVAR(camVision),-2),
|
GETMVAR(GVAR(camVision),-2),
|
||||||
GETMVAR(GVAR(camPos),[ARR_3(0,0,0)]),
|
GETMVAR(GVAR(camPos),[ARR_3(0,0,0)]),
|
||||||
GETMVAR(GVAR(camDir),0)
|
GETMVAR(GVAR(camDir),0)
|
||||||
|
@ -31,6 +31,9 @@ if (_respawn in [0,1,4,5]) exitWith {
|
|||||||
if (typeOf _newCorpse == "seagull") then { deleteVehicle _newCorpse; };
|
if (typeOf _newCorpse == "seagull") then { deleteVehicle _newCorpse; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Virtual spectators should be ignored by the template (otherwise they break)
|
||||||
|
if (_newCorpse isKindOf QGVAR(virtual)) exitWith {};
|
||||||
|
|
||||||
// If player died while already in spectator, ignore
|
// If player died while already in spectator, ignore
|
||||||
if (!GVAR(isSet) || {alive _newCorpse}) then {
|
if (!GVAR(isSet) || {alive _newCorpse}) then {
|
||||||
// Negligible respawn delay can result in entering spectator after respawn
|
// Negligible respawn delay can result in entering spectator after respawn
|
||||||
|
@ -55,7 +55,7 @@ if !(isNil QGVAR(camera)) then {
|
|||||||
|
|
||||||
if !(isNil "_mode") then {
|
if !(isNil "_mode") then {
|
||||||
// If mode not free and no focus, find focus
|
// If mode not free and no focus, find focus
|
||||||
if ((_mode != MODE_FREE) && {isNull GVAR(camTarget)}) then {
|
if ((_mode != MODE_FREE) && {isNull GVAR(camFocus)}) then {
|
||||||
[true] call FUNC(setFocus);
|
[true] call FUNC(setFocus);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ if !(isNil QGVAR(camera)) then {
|
|||||||
_focus = ([] call FUNC(getTargetEntities)) select 0;
|
_focus = ([] call FUNC(getTargetEntities)) select 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
GVAR(camTarget) = _focus;
|
GVAR(camFocus) = _focus;
|
||||||
};
|
};
|
||||||
|
|
||||||
if !(isNil "_mode") then {
|
if !(isNil "_mode") then {
|
||||||
|
@ -37,8 +37,8 @@ if (_newFocus isEqualType true) then {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_newFocus != GVAR(camTarget) && { !(isNull _newFocus && { isNull GVAR(camTarget) }) }) then {
|
if (_newFocus != GVAR(camFocus) && { !(isNull _newFocus && { isNull GVAR(camFocus) }) }) then {
|
||||||
GVAR(camTarget) = _newFocus;
|
GVAR(camFocus) = _newFocus;
|
||||||
|
|
||||||
if (isNull _newFocus) then {
|
if (isNull _newFocus) then {
|
||||||
if (GVAR(camMode) == MODE_FREE) then {
|
if (GVAR(camMode) == MODE_FREE) then {
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
params [["_set",true,[true]], ["_force",true,[true]], ["_hide",true,[true]]];
|
params [["_set",true,[true]], ["_force",true,[true]], ["_hide",true,[true]]];
|
||||||
|
TRACE_3("Params",_set,_force,_hide);
|
||||||
|
|
||||||
// Only clients can be spectators
|
// Only clients can be spectators
|
||||||
if !(hasInterface) exitWith {};
|
if !(hasInterface) exitWith {};
|
||||||
@ -33,10 +34,10 @@ GVAR(uiForced) = _force;
|
|||||||
// Exit if no change (everything above this may need to be ran again)
|
// Exit if no change (everything above this may need to be ran again)
|
||||||
if (_set isEqualTo GVAR(isSet)) exitWith {};
|
if (_set isEqualTo GVAR(isSet)) exitWith {};
|
||||||
|
|
||||||
// Delay if local player (must not be ACE_Player) is not fully initalized
|
// Delay if local player (must not be ACE_Player) does not exist
|
||||||
if (isNil { player } || { isNull player }) exitWith {
|
if (isNull player) exitWith {
|
||||||
[
|
[
|
||||||
{ !isNil { player } && { !isNull player } },
|
{ !isNull player },
|
||||||
FUNC(setSpectator),
|
FUNC(setSpectator),
|
||||||
_this
|
_this
|
||||||
] call CBA_fnc_waitUntilAndExecute;
|
] call CBA_fnc_waitUntilAndExecute;
|
||||||
@ -73,7 +74,7 @@ if (_set) then {
|
|||||||
EGVAR(nametags,showNamesForAI) = false;
|
EGVAR(nametags,showNamesForAI) = false;
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// Kill the display (ensure main display exists, handles edge case where spectator turned off before display exists)
|
// Kill the display (ensure main display exists, handles edge case where spectator turned off beforehand)
|
||||||
[{ !isNull MAIN_DISPLAY },{ [false] call FUNC(ui) }] call CBA_fnc_waitUntilAndExecute;
|
[{ !isNull MAIN_DISPLAY },{ [false] call FUNC(ui) }] call CBA_fnc_waitUntilAndExecute;
|
||||||
|
|
||||||
// This variable doesn't matter anymore
|
// This variable doesn't matter anymore
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
private _next = param [0, true];
|
private _next = param [0, true];
|
||||||
private _entities = [true] call FUNC(getTargetEntities);
|
private _entities = [true] call FUNC(getTargetEntities);
|
||||||
private _focus = GVAR(camTarget);
|
private _focus = GVAR(camFocus);
|
||||||
|
|
||||||
// No entities to switch to
|
// No entities to switch to
|
||||||
if ((_entities isEqualTo []) || (_entities isEqualTo [_focus])) exitWith {};
|
if ((_entities isEqualTo []) || (_entities isEqualTo [_focus])) exitWith {};
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#define HEIGHT_OFFSET 1.5
|
#define HEIGHT_OFFSET 1.5
|
||||||
|
|
||||||
BEGIN_COUNTER(updateCursor);
|
BEGIN_COUNTER(updateCursor);
|
||||||
private _camTarget = GVAR(camTarget);
|
private _camTarget = GVAR(camFocus);
|
||||||
private _camTargetVeh = vehicle _camTarget;
|
private _camTargetVeh = vehicle _camTarget;
|
||||||
private _cursorObject = objNull;
|
private _cursorObject = objNull;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ if !(isNull _object) then {
|
|||||||
|
|
||||||
_handled = true;
|
_handled = true;
|
||||||
} else {
|
} else {
|
||||||
if (_object != GVAR(camTarget)) then {
|
if (_object != GVAR(camFocus)) then {
|
||||||
[_object] call FUNC(setFocus);
|
[_object] call FUNC(setFocus);
|
||||||
|
|
||||||
_handled = true;
|
_handled = true;
|
||||||
|
@ -23,7 +23,7 @@ params ["", "", "_x", "_y"];
|
|||||||
|
|
||||||
if (isNull GVAR(uiMapHighlighted)) then {
|
if (isNull GVAR(uiMapHighlighted)) then {
|
||||||
// Give user feedback that camera is no longer focused
|
// Give user feedback that camera is no longer focused
|
||||||
if !(isNull GVAR(camTarget)) then {
|
if !(isNull GVAR(camFocus)) then {
|
||||||
playSound "ReadoutHideClick1";
|
playSound "ReadoutHideClick1";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ params ["", "_button"];
|
|||||||
// Left click
|
// Left click
|
||||||
if (_button == 0) exitWith {
|
if (_button == 0) exitWith {
|
||||||
if (isNull GVAR(cursorObject)) then {
|
if (isNull GVAR(cursorObject)) then {
|
||||||
if (GVAR(camMode) == MODE_FREE && { !isNull GVAR(camTarget) }) then {
|
if (GVAR(camMode) == MODE_FREE && { !isNull GVAR(camFocus) }) then {
|
||||||
playSound "ReadoutHideClick1";
|
playSound "ReadoutHideClick1";
|
||||||
[objNull] call FUNC(setFocus);
|
[objNull] call FUNC(setFocus);
|
||||||
};
|
};
|
||||||
@ -45,7 +45,7 @@ if (_button == 0) exitWith {
|
|||||||
|
|
||||||
// Right click
|
// Right click
|
||||||
if (_button == 1) then {
|
if (_button == 1) then {
|
||||||
if (GVAR(camMode) == MODE_FREE && { !isNull GVAR(camTarget) } && { !isNull (attachedTo GVAR(camDummy)) }) then {
|
if (GVAR(camMode) == MODE_FREE && { !isNull GVAR(camFocus) } && { !isNull (attachedTo GVAR(camDummy)) }) then {
|
||||||
[] call FUNC(cam_resetTarget);
|
[] call FUNC(cam_resetTarget);
|
||||||
};
|
};
|
||||||
GVAR(holdingRMB) = true;
|
GVAR(holdingRMB) = true;
|
||||||
|
@ -26,7 +26,7 @@ if !(GVAR(uiHelpVisible)) exitWith {};
|
|||||||
|
|
||||||
private _cameraMode = GVAR(camMode);
|
private _cameraMode = GVAR(camMode);
|
||||||
private _availableModes = GVAR(availableModes);
|
private _availableModes = GVAR(availableModes);
|
||||||
private _hasTarget = !isNull GVAR(camTarget);
|
private _hasTarget = !isNull GVAR(camFocus);
|
||||||
|
|
||||||
private _controls = [];
|
private _controls = [];
|
||||||
|
|
||||||
|
@ -16,4 +16,4 @@
|
|||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
CTRL_LIST tvSetCurSel ([[GVAR(camTarget)] call BIS_fnc_objectVar] call FUNC(ui_getTreeDataIndex));
|
CTRL_LIST tvSetCurSel ([[GVAR(camFocus)] call BIS_fnc_objectVar] call FUNC(ui_getTreeDataIndex));
|
||||||
|
@ -22,9 +22,9 @@
|
|||||||
#define IMG_UNARMED "" // TODO: Find suitable unarmed icon
|
#define IMG_UNARMED "" // TODO: Find suitable unarmed icon
|
||||||
|
|
||||||
// Hide if no target or widget is toggled off
|
// Hide if no target or widget is toggled off
|
||||||
if (!GVAR(uiWidgetVisible) || {isNull GVAR(camTarget)}) exitWith {CTRL_WIDGET ctrlShow false};
|
if (!GVAR(uiWidgetVisible) || {isNull GVAR(camFocus)}) exitWith {CTRL_WIDGET ctrlShow false};
|
||||||
|
|
||||||
private _focus = GVAR(camTarget);
|
private _focus = GVAR(camFocus);
|
||||||
|
|
||||||
private _name = ([_focus] call EFUNC(common,getName)) select [0, NAME_MAX_CHARACTERS];
|
private _name = ([_focus] call EFUNC(common,getName)) select [0, NAME_MAX_CHARACTERS];
|
||||||
if !(isPlayer _focus) then { _name = format ["%1: %2", localize "str_player_ai", _name]; };
|
if !(isPlayer _focus) then { _name = format ["%1: %2", localize "str_player_ai", _name]; };
|
||||||
|
@ -49,7 +49,7 @@ if (_newModes isEqualTo []) then {
|
|||||||
// Update camera in case of change
|
// Update camera in case of change
|
||||||
if !(isNil QGVAR(camera)) then {
|
if !(isNil QGVAR(camera)) then {
|
||||||
// If mode was free and no longer available, find a focus
|
// If mode was free and no longer available, find a focus
|
||||||
if (!(MODE_FREE in _newModes) && {GVAR(camMode) == MODE_FREE} && {isNull GVAR(camTarget)}) then {
|
if (!(MODE_FREE in _newModes) && {GVAR(camMode) == MODE_FREE} && {isNull GVAR(camFocus)}) then {
|
||||||
[true] call FUNC(setFocus);
|
[true] call FUNC(setFocus);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user