diff --git a/Content.Client/GameObjects/EntitySystems/AmbienceSystem.cs b/Content.Client/GameObjects/EntitySystems/AmbienceSystem.cs new file mode 100644 index 0000000000..a36549f4de --- /dev/null +++ b/Content.Client/GameObjects/EntitySystems/AmbienceSystem.cs @@ -0,0 +1,54 @@ +#nullable enable +using Content.Shared.Audio; +using JetBrains.Annotations; +using Robust.Client.GameObjects; +using Content.Shared; +using Robust.Shared.Audio; +using Robust.Shared.Configuration; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Prototypes; +using Robust.Shared.Random; + +namespace Content.Client.GameObjects.EntitySystems +{ + [UsedImplicitly] + public class AmbienceSystem : EntitySystem + { + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IRobustRandom _robustRandom = default!; + [Dependency] private readonly IConfigurationManager _configManager = default!; + + private AudioSystem _audioSystem = default!; + + private SoundCollectionPrototype _ambientCollection = default!; + + private AudioParams _ambientParams = new(-10f, 1, "Master", 0, 0, AudioMixTarget.Stereo, true, 0f); + + private IPlayingAudioStream? _ambientStream; + + public override void Initialize() + { + base.Initialize(); + + _audioSystem = EntitySystemManager.GetEntitySystem(); + _ambientCollection = _prototypeManager.Index("AmbienceBase"); + _configManager.OnValueChanged(CCVars.AmbienceBasicEnabled, HandleAmbience, true); + } + + private void HandleAmbience(bool ambienceEnabled) + { + if (ambienceEnabled) + { + var file = _robustRandom.Pick(_ambientCollection.PickFiles); + _ambientStream = _audioSystem.Play(file, _ambientParams); + } + else if (_ambientStream != null) + { + _ambientStream.Stop(); + _ambientStream = null; + } + } + } +} + diff --git a/Content.Client/UserInterface/OptionsMenu.Audio.cs b/Content.Client/UserInterface/OptionsMenu.Audio.cs index 2516d95430..c1b441ec12 100644 --- a/Content.Client/UserInterface/OptionsMenu.Audio.cs +++ b/Content.Client/UserInterface/OptionsMenu.Audio.cs @@ -1,4 +1,5 @@ -using Content.Client.UserInterface.Stylesheets; +using Content.Client.UserInterface.Stylesheets; +using Content.Shared; using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -19,6 +20,7 @@ namespace Content.Client.UserInterface private readonly Button ApplyButton; private readonly Label MasterVolumeLabel; private readonly Slider MasterVolumeSlider; + private readonly CheckBox AmbienceCheckBox; private readonly Button ResetButton; public AudioControl(IConfigurationManager cfg, IClydeAudio clydeAudio) @@ -63,6 +65,11 @@ namespace Content.Client.UserInterface } }); + // sets up ambience checkbox. i am sorry for not fixing the rest of this code. + AmbienceCheckBox = new CheckBox { Text = Loc.GetString("Ambient Hum") }; + contents.AddChild(AmbienceCheckBox); + AmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.AmbienceBasicEnabled); + ApplyButton = new Button { Text = Loc.GetString("Apply"), TextAlign = Label.AlignMode.Center, @@ -112,6 +119,7 @@ namespace Content.Client.UserInterface ApplyButton.OnPressed += OnApplyButtonPressed; ResetButton.OnPressed += OnResetButtonPressed; MasterVolumeSlider.OnValueChanged += OnMasterVolumeSliderChanged; + AmbienceCheckBox.OnToggled += OnAmbienceCheckToggled; AddChild(vBox); UpdateChanges(); @@ -122,6 +130,7 @@ namespace Content.Client.UserInterface ApplyButton.OnPressed -= OnApplyButtonPressed; ResetButton.OnPressed -= OnResetButtonPressed; MasterVolumeSlider.OnValueChanged -= OnMasterVolumeSliderChanged; + AmbienceCheckBox.OnToggled -= OnAmbienceCheckToggled; base.Dispose(disposing); } @@ -132,9 +141,15 @@ namespace Content.Client.UserInterface UpdateChanges(); } + private void OnAmbienceCheckToggled(BaseButton.ButtonEventArgs args) + { + UpdateChanges(); + } + private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args) { _cfg.SetCVar(CVars.AudioMasterVolume, MasterVolumeSlider.Value / 100.0f); + _cfg.SetCVar(CCVars.AmbienceBasicEnabled, AmbienceCheckBox.Pressed); _cfg.SaveToFile(); UpdateChanges(); } @@ -143,13 +158,15 @@ namespace Content.Client.UserInterface { MasterVolumeSlider.Value = _cfg.GetCVar(CVars.AudioMasterVolume) * 100.0f; MasterVolumeLabel.Text = string.Format(Loc.GetString("{0:0}%"), MasterVolumeSlider.Value); + AmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.AmbienceBasicEnabled); UpdateChanges(); } private void UpdateChanges() { var isMasterVolumeSame = System.Math.Abs(MasterVolumeSlider.Value - _cfg.GetCVar(CVars.AudioMasterVolume) * 100.0f) < 0.01f; - var isEverythingSame = isMasterVolumeSame; + var isAmbienceSame = AmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.AmbienceBasicEnabled); + var isEverythingSame = isMasterVolumeSame && isAmbienceSame; ApplyButton.Disabled = isEverythingSame; ResetButton.Disabled = isEverythingSame; } diff --git a/Content.Shared/CCVars.cs b/Content.Shared/CCVars.cs index 522b7c791f..816d91f022 100644 --- a/Content.Shared/CCVars.cs +++ b/Content.Shared/CCVars.cs @@ -166,6 +166,14 @@ namespace Content.Shared CVarDef.Create("parallax.debug", false, CVar.CLIENTONLY); + /* + * Ambience + */ + + public static readonly CVarDef AmbienceBasicEnabled = + CVarDef.Create("ambience.basicenabled", true, CVar.ARCHIVE | CVar.CLIENTONLY); + + /* * AI */ diff --git a/Resources/Audio/Ambience/license.txt b/Resources/Audio/Ambience/license.txt new file mode 100644 index 0000000000..671b6ca79c --- /dev/null +++ b/Resources/Audio/Ambience/license.txt @@ -0,0 +1 @@ +shipambience.ogg from /tg/station (commit https://github.com/tgstation/tgstation/blob/66a625e6df15eaa97e599248a2281c74238ce26e/sound/ambience/shipambience.ogg), which took it from CEV Eris (commit https://github.com/discordia-space/CEV-Eris/blob/e4e40d38424afe88c8a81cf0e3857d8af4ef077f/sound/ambience/shipambience.ogg). Licensed under CC-BY-SA. diff --git a/Resources/Audio/Ambience/shipambience.ogg b/Resources/Audio/Ambience/shipambience.ogg new file mode 100644 index 0000000000..51e090b02c Binary files /dev/null and b/Resources/Audio/Ambience/shipambience.ogg differ diff --git a/Resources/Prototypes/SoundCollections/ambience.yml b/Resources/Prototypes/SoundCollections/ambience.yml new file mode 100644 index 0000000000..cccce8d1e2 --- /dev/null +++ b/Resources/Prototypes/SoundCollections/ambience.yml @@ -0,0 +1,4 @@ +- type: soundCollection + id: AmbienceBase + files: + - /Audio/Ambience/shipambience.ogg