Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Content.Client/Audio/ClientAdminSoundSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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);
_adminAudioEnabled = _cfg.GetCVar(CCVars.AdminSoundsEnabled);
}

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();
}
}
1 change: 1 addition & 0 deletions Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
12 changes: 11 additions & 1 deletion Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public AudioTab()
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);

Expand All @@ -32,6 +33,7 @@ public AudioTab()
AmbienceVolumeSlider.OnValueChanged += OnAmbienceVolumeSliderChanged;
AmbienceSoundsSlider.OnValueChanged += OnAmbienceSoundsSliderChanged;
LobbyMusicCheckBox.OnToggled += OnLobbyMusicCheckToggled;
AdminSoundsCheckBox.OnToggled += OnAdminSoundsCheckToggled;
StationAmbienceCheckBox.OnToggled += OnStationAmbienceCheckToggled;
SpaceAmbienceCheckBox.OnToggled += OnSpaceAmbienceCheckToggled;

Expand Down Expand Up @@ -77,6 +79,11 @@ private void OnLobbyMusicCheckToggled(BaseButton.ButtonEventArgs args)
UpdateChanges();
}

private void OnAdminSoundsCheckToggled(BaseButton.ButtonEventArgs args)
{
UpdateChanges();
}

private void OnStationAmbienceCheckToggled(BaseButton.ButtonEventArgs args)
{
UpdateChanges();
Expand All @@ -94,6 +101,7 @@ private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
_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();
Expand All @@ -112,6 +120,7 @@ private void Reset()
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();
Expand Down Expand Up @@ -140,9 +149,10 @@ private void UpdateChanges()
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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Command that allows admins to play global sounds.
/// </summary>
[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 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);
}

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)
/// <summary>
/// Command that allows admins to play global sounds.
/// </summary>
[AdminCommand(AdminFlags.Fun)]
public void PlayGlobalSoundCommand(IConsoleShell shell, string argStr, string[] args)
{
Filter filter;
var audio = AudioParams.Default.WithVolume(-8);
Expand All @@ -27,7 +44,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
{
// 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.
Expand Down Expand Up @@ -79,6 +96,6 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
break;
}

SoundSystem.Play(filter, args[0], audio);
PlayGlobal(filter, args[0], audio);
}
}
21 changes: 21 additions & 0 deletions Content.Shared/Audio/SharedAdminSoundSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
7 changes: 7 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ public static readonly CVarDef<bool>
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
*/
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down