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>
|
</BoxContainer>
|
||||||
<Control MinSize="0 8" />
|
<Control MinSize="0 8" />
|
||||||
<CheckBox Name="LobbyMusicCheckBox" Text="{Loc 'ui-options-lobby-music'}" />
|
<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="StationAmbienceCheckBox" Text="{Loc 'ui-options-station-ambience'}" />
|
||||||
<CheckBox Name="SpaceAmbienceCheckBox" Text="{Loc 'ui-options-space-ambience'}" />
|
<CheckBox Name="SpaceAmbienceCheckBox" Text="{Loc 'ui-options-space-ambience'}" />
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
|
|
||||||
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||||
|
AdminSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.AdminSoundsEnabled);
|
||||||
StationAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.StationAmbienceEnabled);
|
StationAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.StationAmbienceEnabled);
|
||||||
SpaceAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
|
SpaceAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
AmbienceVolumeSlider.OnValueChanged += OnAmbienceVolumeSliderChanged;
|
AmbienceVolumeSlider.OnValueChanged += OnAmbienceVolumeSliderChanged;
|
||||||
AmbienceSoundsSlider.OnValueChanged += OnAmbienceSoundsSliderChanged;
|
AmbienceSoundsSlider.OnValueChanged += OnAmbienceSoundsSliderChanged;
|
||||||
LobbyMusicCheckBox.OnToggled += OnLobbyMusicCheckToggled;
|
LobbyMusicCheckBox.OnToggled += OnLobbyMusicCheckToggled;
|
||||||
|
AdminSoundsCheckBox.OnToggled += OnAdminSoundsCheckToggled;
|
||||||
StationAmbienceCheckBox.OnToggled += OnStationAmbienceCheckToggled;
|
StationAmbienceCheckBox.OnToggled += OnStationAmbienceCheckToggled;
|
||||||
SpaceAmbienceCheckBox.OnToggled += OnSpaceAmbienceCheckToggled;
|
SpaceAmbienceCheckBox.OnToggled += OnSpaceAmbienceCheckToggled;
|
||||||
|
|
||||||
@@ -77,6 +79,11 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
UpdateChanges();
|
UpdateChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnAdminSoundsCheckToggled(BaseButton.ButtonEventArgs args)
|
||||||
|
{
|
||||||
|
UpdateChanges();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnStationAmbienceCheckToggled(BaseButton.ButtonEventArgs args)
|
private void OnStationAmbienceCheckToggled(BaseButton.ButtonEventArgs args)
|
||||||
{
|
{
|
||||||
UpdateChanges();
|
UpdateChanges();
|
||||||
@@ -94,6 +101,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
_cfg.SetCVar(CCVars.AmbienceVolume, LV100ToDB(AmbienceVolumeSlider.Value));
|
_cfg.SetCVar(CCVars.AmbienceVolume, LV100ToDB(AmbienceVolumeSlider.Value));
|
||||||
_cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);
|
_cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);
|
||||||
_cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed);
|
_cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed);
|
||||||
|
_cfg.SetCVar(CCVars.AdminSoundsEnabled, AdminSoundsCheckBox.Pressed);
|
||||||
_cfg.SetCVar(CCVars.StationAmbienceEnabled, StationAmbienceCheckBox.Pressed);
|
_cfg.SetCVar(CCVars.StationAmbienceEnabled, StationAmbienceCheckBox.Pressed);
|
||||||
_cfg.SetCVar(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCheckBox.Pressed);
|
_cfg.SetCVar(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCheckBox.Pressed);
|
||||||
_cfg.SaveToFile();
|
_cfg.SaveToFile();
|
||||||
@@ -112,6 +120,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
AmbienceVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume));
|
AmbienceVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume));
|
||||||
AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
|
AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
|
||||||
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||||
|
AdminSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.AdminSoundsEnabled);
|
||||||
StationAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.StationAmbienceEnabled);
|
StationAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.StationAmbienceEnabled);
|
||||||
SpaceAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
|
SpaceAmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
|
||||||
UpdateChanges();
|
UpdateChanges();
|
||||||
@@ -140,9 +149,10 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
Math.Abs(AmbienceVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume))) < 0.01f;
|
Math.Abs(AmbienceVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume))) < 0.01f;
|
||||||
var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
|
var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
|
||||||
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
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 isStationAmbienceSame = StationAmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.StationAmbienceEnabled);
|
||||||
var isSpaceAmbienceSame = SpaceAmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
|
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;
|
ApplyButton.Disabled = isEverythingSame;
|
||||||
ResetButton.Disabled = isEverythingSame;
|
ResetButton.Disabled = isEverythingSame;
|
||||||
MasterVolumeLabel.Text =
|
MasterVolumeLabel.Text =
|
||||||
|
|||||||
@@ -1,24 +1,41 @@
|
|||||||
|
using Content.Server.Administration;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
|
using Content.Shared.Audio;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
using Robust.Shared.Player;
|
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>
|
/// <summary>
|
||||||
/// Command that allows admins to play global sounds.
|
/// Command that allows admins to play global sounds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AdminCommand(AdminFlags.Fun)]
|
[AdminCommand(AdminFlags.Fun)]
|
||||||
public sealed class PlayGlobalSound : IConsoleCommand
|
public void PlayGlobalSoundCommand(IConsoleShell shell, string argStr, string[] args)
|
||||||
{
|
|
||||||
[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)
|
|
||||||
{
|
{
|
||||||
Filter filter;
|
Filter filter;
|
||||||
var audio = AudioParams.Default.WithVolume(-8);
|
var audio = AudioParams.Default.WithVolume(-8);
|
||||||
@@ -27,7 +44,7 @@ public sealed class PlayGlobalSound : IConsoleCommand
|
|||||||
{
|
{
|
||||||
// No arguments, show command help.
|
// No arguments, show command help.
|
||||||
case 0:
|
case 0:
|
||||||
shell.WriteLine(Help);
|
shell.WriteLine(Loc.GetString("play-global-sound-command-help"));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// No users, play sound for everyone.
|
// No users, play sound for everyone.
|
||||||
@@ -79,6 +96,6 @@ public sealed class PlayGlobalSound : IConsoleCommand
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundSystem.Play(filter, args[0], audio);
|
PlayGlobal(filter, args[0], audio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
21
Content.Shared/Audio/SharedAdminSoundSystem.cs
Normal file
21
Content.Shared/Audio/SharedAdminSoundSystem.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -395,6 +395,13 @@ namespace Content.Shared.CCVar
|
|||||||
public static readonly CVarDef<bool> LobbyMusicEnabled =
|
public static readonly CVarDef<bool> LobbyMusicEnabled =
|
||||||
CVarDef.Create("ambience.lobbymusicenabled", true, CVar.ARCHIVE | CVar.CLIENTONLY);
|
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
|
* HUD
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ ui-options-midi-volume = MIDI (Instrument) Volume:
|
|||||||
ui-options-ambience-volume = Ambience volume:
|
ui-options-ambience-volume = Ambience volume:
|
||||||
ui-options-ambience-max-sounds = Ambience simultaneous sounds:
|
ui-options-ambience-max-sounds = Ambience simultaneous sounds:
|
||||||
ui-options-lobby-music = Lobby & Round-end Music
|
ui-options-lobby-music = Lobby & Round-end Music
|
||||||
|
ui-options-admin-sounds = Play Admin Sounds
|
||||||
ui-options-station-ambience = Station Ambience
|
ui-options-station-ambience = Station Ambience
|
||||||
ui-options-space-ambience = Space Ambience
|
ui-options-space-ambience = Space Ambience
|
||||||
ui-options-volume-label = Volume
|
ui-options-volume-label = Volume
|
||||||
|
|||||||
Reference in New Issue
Block a user