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:
ike709
2022-06-02 08:41:19 -05:00
committed by GitHub
parent 5b3a87180f
commit 5ae56c67e1
7 changed files with 122 additions and 14 deletions

View 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();
}
}

View File

@@ -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>

View File

@@ -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 =

View File

@@ -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;
public sealed class ServerAdminSoundSystem : SharedAdminSoundSystem
{
[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 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);
}
/// <summary>
/// Command that allows admins to play global sounds.
/// </summary>
[AdminCommand(AdminFlags.Fun)]
public sealed class PlayGlobalSound : IConsoleCommand
{
[Dependency] private IPlayerManager _playerManager = default!;
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 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);
}
}

View File

@@ -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;
}
}

View File

@@ -395,6 +395,13 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<bool> LobbyMusicEnabled =
CVarDef.Create("ambience.lobbymusicenabled", true, CVar.ARCHIVE | CVar.CLIENTONLY);
/*
* Admin sounds
*/
public static readonly CVarDef<bool> AdminSoundsEnabled =
CVarDef.Create("audio.adminsoundsenabled", true, CVar.ARCHIVE | CVar.CLIENTONLY);
/*
* HUD
*/

View File

@@ -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