From 5ae56c67e10631bd2c653eec8773efd74ce47978 Mon Sep 17 00:00:00 2001 From: ike709 Date: Thu, 2 Jun 2022 08:41:19 -0500 Subject: [PATCH] Adds the ability to not play admin sounds (#8242) Co-authored-by: ike709 Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> --- .../Audio/ClientAdminSoundSystem.cs | 51 +++++++++++++++++++ .../EscapeMenu/UI/Tabs/AudioTab.xaml | 1 + .../EscapeMenu/UI/Tabs/AudioTab.xaml.cs | 12 ++++- .../ServerAdminSoundSystem.cs} | 43 +++++++++++----- .../Audio/SharedAdminSoundSystem.cs | 21 ++++++++ Content.Shared/CCVar/CCVars.cs | 7 +++ .../en-US/escape-menu/ui/options-menu.ftl | 1 + 7 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 Content.Client/Audio/ClientAdminSoundSystem.cs rename Content.Server/{Administration/Commands/PlayGlobalSound.cs => Audio/ServerAdminSoundSystem.cs} (62%) create mode 100644 Content.Shared/Audio/SharedAdminSoundSystem.cs diff --git a/Content.Client/Audio/ClientAdminSoundSystem.cs b/Content.Client/Audio/ClientAdminSoundSystem.cs new file mode 100644 index 0000000000..ce1477a35f --- /dev/null +++ b/Content.Client/Audio/ClientAdminSoundSystem.cs @@ -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 _adminAudio = new(1); + + public override void Initialize() + { + base.Initialize(); + SubscribeNetworkEvent(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(); + } +} diff --git a/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml b/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml index ddeff7f2f6..5487cdbe64 100644 --- a/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml +++ b/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml @@ -63,6 +63,7 @@ + diff --git a/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs b/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs index 696c8bf083..aca123a424 100644 --- a/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs +++ b/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs @@ -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 = diff --git a/Content.Server/Administration/Commands/PlayGlobalSound.cs b/Content.Server/Audio/ServerAdminSoundSystem.cs similarity index 62% rename from Content.Server/Administration/Commands/PlayGlobalSound.cs rename to Content.Server/Audio/ServerAdminSoundSystem.cs index 7813d8c906..8d34692ed4 100644 --- a/Content.Server/Administration/Commands/PlayGlobalSound.cs +++ b/Content.Server/Audio/ServerAdminSoundSystem.cs @@ -1,24 +1,41 @@ +using Content.Server.Administration; using Content.Shared.Administration; +using Content.Shared.Audio; using Robust.Server.Player; using Robust.Shared.Audio; using Robust.Shared.Console; using Robust.Shared.Player; -namespace Content.Server.Administration.Commands; +namespace Content.Server.Audio; -/// -/// Command that allows admins to play global sounds. -/// -[AdminCommand(AdminFlags.Fun)] -public sealed class PlayGlobalSound : IConsoleCommand +public sealed class ServerAdminSoundSystem : SharedAdminSoundSystem { - [Dependency] private IPlayerManager _playerManager = default!; + [Dependency] private readonly IConsoleHost _conHost = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + public override void Initialize() + { + base.Initialize(); + _conHost.RegisterCommand("playglobalsound", Loc.GetString("play-global-sound-command-description"), Loc.GetString("play-global-sound-command-help"), PlayGlobalSoundCommand); + } - public string Command => "playglobalsound"; - public string Description => Loc.GetString("play-global-sound-command-description"); - public string Help => Loc.GetString("play-global-sound-command-help"); - public void Execute(IConsoleShell shell, string argStr, string[] args) + public override void Shutdown() + { + base.Shutdown(); + _conHost.UnregisterCommand("playglobalsound"); + } + + private void PlayGlobal(Filter playerFilter, string filename, AudioParams? audioParams = null) + { + var msg = new AdminSoundEvent(filename, audioParams); + RaiseNetworkEvent(msg, playerFilter); + } + + /// + /// Command that allows admins to play global sounds. + /// + [AdminCommand(AdminFlags.Fun)] + public void PlayGlobalSoundCommand(IConsoleShell shell, string argStr, string[] args) { Filter filter; var audio = AudioParams.Default.WithVolume(-8); @@ -27,7 +44,7 @@ public sealed class PlayGlobalSound : IConsoleCommand { // No arguments, show command help. case 0: - shell.WriteLine(Help); + shell.WriteLine(Loc.GetString("play-global-sound-command-help")); return; // No users, play sound for everyone. @@ -79,6 +96,6 @@ public sealed class PlayGlobalSound : IConsoleCommand break; } - SoundSystem.Play(filter, args[0], audio); + PlayGlobal(filter, args[0], audio); } } diff --git a/Content.Shared/Audio/SharedAdminSoundSystem.cs b/Content.Shared/Audio/SharedAdminSoundSystem.cs new file mode 100644 index 0000000000..f26558e690 --- /dev/null +++ b/Content.Shared/Audio/SharedAdminSoundSystem.cs @@ -0,0 +1,21 @@ +using Robust.Shared.Audio; +using Robust.Shared.Serialization; + +namespace Content.Shared.Audio; + + +public abstract class SharedAdminSoundSystem : EntitySystem +{ +} + +[Serializable, NetSerializable] +public sealed class AdminSoundEvent : EntityEventArgs +{ + public string Filename; + public AudioParams? AudioParams; + public AdminSoundEvent(string filename, AudioParams? audioParams = null) + { + Filename = filename; + AudioParams = audioParams; + } +} diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index d28e6f5533..e76a1fe40c 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -395,6 +395,13 @@ namespace Content.Shared.CCVar public static readonly CVarDef LobbyMusicEnabled = CVarDef.Create("ambience.lobbymusicenabled", true, CVar.ARCHIVE | CVar.CLIENTONLY); + /* + * Admin sounds + */ + + public static readonly CVarDef AdminSoundsEnabled = + CVarDef.Create("audio.adminsoundsenabled", true, CVar.ARCHIVE | CVar.CLIENTONLY); + /* * HUD */ diff --git a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl index 61a739877f..5547628b2c 100644 --- a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl +++ b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl @@ -16,6 +16,7 @@ ui-options-midi-volume = MIDI (Instrument) Volume: ui-options-ambience-volume = Ambience volume: ui-options-ambience-max-sounds = Ambience simultaneous sounds: ui-options-lobby-music = Lobby & Round-end Music +ui-options-admin-sounds = Play Admin Sounds ui-options-station-ambience = Station Ambience ui-options-space-ambience = Space Ambience ui-options-volume-label = Volume