Adds the ability to not play admin sounds (#8242)
Co-authored-by: ike709 <ike709@github.com> Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
51
Content.Client/Audio/ClientAdminSoundSystem.cs
Normal file
51
Content.Client/Audio/ClientAdminSoundSystem.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Client.Audio;
|
||||
|
||||
public sealed class ClientAdminSoundSystem : SharedAdminSoundSystem
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
private bool _adminAudioEnabled = true;
|
||||
private List<IPlayingAudioStream?> _adminAudio = new(1);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<AdminSoundEvent>(PlayAdminSound);
|
||||
_cfg.OnValueChanged(CCVars.AdminSoundsEnabled, ToggleAdminSound, true);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
foreach (var stream in _adminAudio)
|
||||
{
|
||||
stream?.Stop();
|
||||
}
|
||||
_adminAudio.Clear();
|
||||
}
|
||||
|
||||
private void PlayAdminSound(AdminSoundEvent soundEvent)
|
||||
{
|
||||
if(!_adminAudioEnabled) return;
|
||||
|
||||
var stream = SoundSystem.Play(Filter.Local(), soundEvent.Filename, soundEvent.AudioParams);
|
||||
_adminAudio.Add(stream);
|
||||
}
|
||||
|
||||
private void ToggleAdminSound(bool enabled)
|
||||
{
|
||||
_adminAudioEnabled = enabled;
|
||||
if (_adminAudioEnabled) return;
|
||||
foreach (var stream in _adminAudio)
|
||||
{
|
||||
stream?.Stop();
|
||||
}
|
||||
_adminAudio.Clear();
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@
|
||||
</BoxContainer>
|
||||
<Control MinSize="0 8" />
|
||||
<CheckBox Name="LobbyMusicCheckBox" Text="{Loc 'ui-options-lobby-music'}" />
|
||||
<CheckBox Name="AdminSoundsCheckBox" Text="{Loc 'ui-options-admin-sounds'}" />
|
||||
<CheckBox Name="StationAmbienceCheckBox" Text="{Loc 'ui-options-station-ambience'}" />
|
||||
<CheckBox Name="SpaceAmbienceCheckBox" Text="{Loc 'ui-options-space-ambience'}" />
|
||||
</BoxContainer>
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||
AdminSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.AdminSoundsEnabled);
|
||||
StationAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.StationAmbienceEnabled);
|
||||
SpaceAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
|
||||
|
||||
@@ -32,6 +33,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
AmbienceVolumeSlider.OnValueChanged += OnAmbienceVolumeSliderChanged;
|
||||
AmbienceSoundsSlider.OnValueChanged += OnAmbienceSoundsSliderChanged;
|
||||
LobbyMusicCheckBox.OnToggled += OnLobbyMusicCheckToggled;
|
||||
AdminSoundsCheckBox.OnToggled += OnAdminSoundsCheckToggled;
|
||||
StationAmbienceCheckBox.OnToggled += OnStationAmbienceCheckToggled;
|
||||
SpaceAmbienceCheckBox.OnToggled += OnSpaceAmbienceCheckToggled;
|
||||
|
||||
@@ -77,6 +79,11 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
UpdateChanges();
|
||||
}
|
||||
|
||||
private void OnAdminSoundsCheckToggled(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
UpdateChanges();
|
||||
}
|
||||
|
||||
private void OnStationAmbienceCheckToggled(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
UpdateChanges();
|
||||
@@ -94,6 +101,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
_cfg.SetCVar(CCVars.AmbienceVolume, LV100ToDB(AmbienceVolumeSlider.Value));
|
||||
_cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);
|
||||
_cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.AdminSoundsEnabled, AdminSoundsCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.StationAmbienceEnabled, StationAmbienceCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCheckBox.Pressed);
|
||||
_cfg.SaveToFile();
|
||||
@@ -112,6 +120,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
AmbienceVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume));
|
||||
AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
|
||||
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||
AdminSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.AdminSoundsEnabled);
|
||||
StationAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.StationAmbienceEnabled);
|
||||
SpaceAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
|
||||
UpdateChanges();
|
||||
@@ -140,9 +149,10 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
Math.Abs(AmbienceVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume))) < 0.01f;
|
||||
var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
|
||||
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||
var isAdminSoundsSame = AdminSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.AdminSoundsEnabled);
|
||||
var isStationAmbienceSame = StationAmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.StationAmbienceEnabled);
|
||||
var isSpaceAmbienceSame = SpaceAmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
|
||||
var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbientVolumeSame && isAmbientSoundsSame && isLobbySame && isStationAmbienceSame && isSpaceAmbienceSame;
|
||||
var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbientVolumeSame && isAmbientSoundsSame && isLobbySame && isAdminSoundsSame && isStationAmbienceSame && isSpaceAmbienceSame;
|
||||
ApplyButton.Disabled = isEverythingSame;
|
||||
ResetButton.Disabled = isEverythingSame;
|
||||
MasterVolumeLabel.Text =
|
||||
|
||||
Reference in New Issue
Block a user