Fix ambient audio nags (#10698)
This commit is contained in:
@@ -14,6 +14,8 @@ using Robust.Shared.Prototypes;
|
|||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Robust.Client.GameObjects;
|
||||||
|
using Robust.Client.ResourceManagement;
|
||||||
using Timer = Robust.Shared.Timing.Timer;
|
using Timer = Robust.Shared.Timing.Timer;
|
||||||
|
|
||||||
namespace Content.Client.Audio
|
namespace Content.Client.Audio
|
||||||
@@ -44,7 +46,7 @@ namespace Content.Client.Audio
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// What the ambience has been set to.
|
/// What the ambience has been set to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private SoundCollectionPrototype _currentCollection = default!;
|
private SoundCollectionPrototype? _currentCollection;
|
||||||
private CancellationTokenSource _timerCancelTokenSource = new();
|
private CancellationTokenSource _timerCancelTokenSource = new();
|
||||||
|
|
||||||
private SoundCollectionPrototype _spaceAmbience = default!;
|
private SoundCollectionPrototype _spaceAmbience = default!;
|
||||||
@@ -58,12 +60,22 @@ namespace Content.Client.Audio
|
|||||||
_spaceAmbience = _prototypeManager.Index<SoundCollectionPrototype>("SpaceAmbienceBase");
|
_spaceAmbience = _prototypeManager.Index<SoundCollectionPrototype>("SpaceAmbienceBase");
|
||||||
_currentCollection = _stationAmbience;
|
_currentCollection = _stationAmbience;
|
||||||
|
|
||||||
|
// TOOD: Ideally audio loading streamed better / we have more robust audio but this is quite annoying
|
||||||
|
var cache = IoCManager.Resolve<IResourceCache>();
|
||||||
|
|
||||||
|
foreach (var audio in _spaceAmbience.PickFiles)
|
||||||
|
{
|
||||||
|
cache.GetResource<AudioResource>(audio.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
_configManager.OnValueChanged(CCVars.AmbienceVolume, AmbienceCVarChanged);
|
_configManager.OnValueChanged(CCVars.AmbienceVolume, AmbienceCVarChanged);
|
||||||
_configManager.OnValueChanged(CCVars.LobbyMusicEnabled, LobbyMusicCVarChanged);
|
_configManager.OnValueChanged(CCVars.LobbyMusicEnabled, LobbyMusicCVarChanged);
|
||||||
_configManager.OnValueChanged(CCVars.StationAmbienceEnabled, StationAmbienceCVarChanged);
|
_configManager.OnValueChanged(CCVars.StationAmbienceEnabled, StationAmbienceCVarChanged);
|
||||||
_configManager.OnValueChanged(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCVarChanged);
|
_configManager.OnValueChanged(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCVarChanged);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttached);
|
||||||
SubscribeLocalEvent<EntParentChangedMessage>(EntParentChanged);
|
SubscribeLocalEvent<EntParentChangedMessage>(EntParentChanged);
|
||||||
|
SubscribeLocalEvent<PlayerDetachedEvent>(OnPlayerDetached);
|
||||||
|
|
||||||
_stateManager.OnStateChanged += StateManagerOnStateChanged;
|
_stateManager.OnStateChanged += StateManagerOnStateChanged;
|
||||||
|
|
||||||
@@ -73,10 +85,28 @@ namespace Content.Client.Audio
|
|||||||
_gameTicker.LobbyStatusUpdated += LobbySongReceived;
|
_gameTicker.LobbyStatusUpdated += LobbySongReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPlayerAttached(PlayerAttachedEvent ev)
|
||||||
|
{
|
||||||
|
if (!TryComp<TransformComponent>(ev.Entity, out var xform))
|
||||||
|
return;
|
||||||
|
|
||||||
|
CheckAmbience(xform);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPlayerDetached(PlayerDetachedEvent ev)
|
||||||
|
{
|
||||||
|
EndAmbience();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
{
|
{
|
||||||
base.Shutdown();
|
base.Shutdown();
|
||||||
|
|
||||||
|
_configManager.UnsubValueChanged(CCVars.AmbienceVolume, AmbienceCVarChanged);
|
||||||
|
_configManager.UnsubValueChanged(CCVars.LobbyMusicEnabled, LobbyMusicCVarChanged);
|
||||||
|
_configManager.UnsubValueChanged(CCVars.StationAmbienceEnabled, StationAmbienceCVarChanged);
|
||||||
|
_configManager.UnsubValueChanged(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCVarChanged);
|
||||||
|
|
||||||
_stateManager.OnStateChanged -= StateManagerOnStateChanged;
|
_stateManager.OnStateChanged -= StateManagerOnStateChanged;
|
||||||
|
|
||||||
_client.PlayerJoinedServer -= OnJoin;
|
_client.PlayerJoinedServer -= OnJoin;
|
||||||
@@ -88,15 +118,12 @@ namespace Content.Client.Audio
|
|||||||
EndLobbyMusic();
|
EndLobbyMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EntParentChanged(ref EntParentChangedMessage message)
|
private void CheckAmbience(TransformComponent xform)
|
||||||
{
|
{
|
||||||
if(_playMan.LocalPlayer is null || _playMan.LocalPlayer.ControlledEntity != message.Entity ||
|
if (xform.GridUid != null)
|
||||||
!_timing.IsFirstTimePredicted) return;
|
|
||||||
|
|
||||||
// Check if we traversed to grid.
|
|
||||||
if (message.Transform.GridUid != null)
|
|
||||||
{
|
{
|
||||||
if (_currentCollection == _stationAmbience) return;
|
if (_currentCollection == _stationAmbience)
|
||||||
|
return;
|
||||||
ChangeAmbience(_stationAmbience);
|
ChangeAmbience(_stationAmbience);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -105,6 +132,15 @@ namespace Content.Client.Audio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EntParentChanged(ref EntParentChangedMessage message)
|
||||||
|
{
|
||||||
|
if(_playMan.LocalPlayer is null || _playMan.LocalPlayer.ControlledEntity != message.Entity ||
|
||||||
|
!_timing.IsFirstTimePredicted) return;
|
||||||
|
|
||||||
|
// Check if we traversed to grid.
|
||||||
|
CheckAmbience(message.Transform);
|
||||||
|
}
|
||||||
|
|
||||||
private void ChangeAmbience(SoundCollectionPrototype newAmbience)
|
private void ChangeAmbience(SoundCollectionPrototype newAmbience)
|
||||||
{
|
{
|
||||||
if (_currentCollection == newAmbience) return;
|
if (_currentCollection == newAmbience) return;
|
||||||
@@ -172,7 +208,8 @@ namespace Content.Client.Audio
|
|||||||
private void StartAmbience()
|
private void StartAmbience()
|
||||||
{
|
{
|
||||||
EndAmbience();
|
EndAmbience();
|
||||||
if (!CanPlayCollection(_currentCollection)) return;
|
if (_currentCollection == null || !CanPlayCollection(_currentCollection))
|
||||||
|
return;
|
||||||
_playingCollection = _currentCollection;
|
_playingCollection = _currentCollection;
|
||||||
var file = _robustRandom.Pick(_currentCollection.PickFiles).ToString();
|
var file = _robustRandom.Pick(_currentCollection.PickFiles).ToString();
|
||||||
_ambientStream = SoundSystem.Play(file, Filter.Local(), _ambientParams.WithVolume(_ambientParams.Volume + _configManager.GetCVar(CCVars.AmbienceVolume)));
|
_ambientStream = SoundSystem.Play(file, Filter.Local(), _ambientParams.WithVolume(_ambientParams.Volume + _configManager.GetCVar(CCVars.AmbienceVolume)));
|
||||||
@@ -197,6 +234,9 @@ namespace Content.Client.Audio
|
|||||||
|
|
||||||
private void StationAmbienceCVarChanged(bool enabled)
|
private void StationAmbienceCVarChanged(bool enabled)
|
||||||
{
|
{
|
||||||
|
if (_currentCollection == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (enabled && _stateManager.CurrentState is GameScreen && _currentCollection.ID == _stationAmbience.ID)
|
if (enabled && _stateManager.CurrentState is GameScreen && _currentCollection.ID == _stationAmbience.ID)
|
||||||
{
|
{
|
||||||
StartAmbience();
|
StartAmbience();
|
||||||
@@ -209,6 +249,9 @@ namespace Content.Client.Audio
|
|||||||
|
|
||||||
private void SpaceAmbienceCVarChanged(bool enabled)
|
private void SpaceAmbienceCVarChanged(bool enabled)
|
||||||
{
|
{
|
||||||
|
if (_currentCollection == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (enabled && _stateManager.CurrentState is GameScreen && _currentCollection.ID == _spaceAmbience.ID)
|
if (enabled && _stateManager.CurrentState is GameScreen && _currentCollection.ID == _spaceAmbience.ID)
|
||||||
{
|
{
|
||||||
StartAmbience();
|
StartAmbience();
|
||||||
|
|||||||
Reference in New Issue
Block a user