From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Fri, 29 Dec 2023 04:43:36 +0000 (+1100) Subject: Add UI click sounds (#22410) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=4023134cf0536d36dd1d685189e8b1ee6c004d81;p=space-station-14.git Add UI click sounds (#22410) * Add UI click sounds * tweaks * Significant cleanup * Audio options and numerous fixes * Fix the remaining UI elements * new click sound --------- Co-authored-by: Kara --- diff --git a/Content.Client/Audio/AudioUIController.cs b/Content.Client/Audio/AudioUIController.cs new file mode 100644 index 0000000000..ef903672fd --- /dev/null +++ b/Content.Client/Audio/AudioUIController.cs @@ -0,0 +1,98 @@ +using Content.Shared.CCVar; +using Robust.Client.Audio; +using Robust.Client.ResourceManagement; +using Robust.Client.UserInterface.Controllers; +using Robust.Shared.Audio.Sources; +using Robust.Shared.Configuration; + +namespace Content.Client.Audio; + +public sealed class AudioUIController : UIController +{ + [Dependency] private readonly IAudioManager _audioManager = default!; + [Dependency] private readonly IConfigurationManager _configManager = default!; + [Dependency] private readonly IResourceCache _cache = default!; + + private float _interfaceGain; + private IAudioSource? _clickSource; + private IAudioSource? _hoverSource; + + private const float ClickGain = 0.25f; + private const float HoverGain = 0.05f; + + public override void Initialize() + { + base.Initialize(); + + /* + * This exists to load UI sounds outside of the game sim. + */ + + // No unsub coz never shuts down until program exit. + _configManager.OnValueChanged(CCVars.UIClickSound, SetClickSound, true); + _configManager.OnValueChanged(CCVars.UIHoverSound, SetHoverSound, true); + + _configManager.OnValueChanged(CCVars.InterfaceVolume, SetInterfaceVolume, true); + } + + private void SetInterfaceVolume(float obj) + { + _interfaceGain = obj; + + if (_clickSource != null) + { + _clickSource.Gain = ClickGain * _interfaceGain; + } + + if (_hoverSource != null) + { + _hoverSource.Gain = HoverGain * _interfaceGain; + } + } + + private void SetClickSound(string value) + { + if (!string.IsNullOrEmpty(value)) + { + var resource = _cache.GetResource(value); + var source = + _audioManager.CreateAudioSource(resource); + + if (source != null) + { + source.Gain = ClickGain * _interfaceGain; + source.Global = true; + } + + _clickSource = source; + UIManager.SetClickSound(source); + } + else + { + UIManager.SetClickSound(null); + } + } + + private void SetHoverSound(string value) + { + if (!string.IsNullOrEmpty(value)) + { + var hoverResource = _cache.GetResource(value); + var hoverSource = + _audioManager.CreateAudioSource(hoverResource); + + if (hoverSource != null) + { + hoverSource.Gain = HoverGain * _interfaceGain; + hoverSource.Global = true; + } + + _hoverSource = hoverSource; + UIManager.SetHoverSound(hoverSource); + } + else + { + UIManager.SetHoverSound(null); + } + } +} diff --git a/Content.Client/Audio/ContentAudioSystem.cs b/Content.Client/Audio/ContentAudioSystem.cs index 603b1086d8..b5d2d4bcdc 100644 --- a/Content.Client/Audio/ContentAudioSystem.cs +++ b/Content.Client/Audio/ContentAudioSystem.cs @@ -1,15 +1,18 @@ using Content.Shared.Audio; -using Content.Shared.CCVar; using Content.Shared.GameTicking; -using Robust.Client.GameObjects; -using Robust.Shared; -using Robust.Shared.Audio; +using Robust.Client.Audio; +using Robust.Client.ResourceManagement; +using Robust.Client.UserInterface; using AudioComponent = Robust.Shared.Audio.Components.AudioComponent; namespace Content.Client.Audio; public sealed partial class ContentAudioSystem : SharedContentAudioSystem { + [Dependency] private readonly IAudioManager _audioManager = default!; + [Dependency] private readonly IResourceCache _cache = default!; + [Dependency] private readonly IUserInterfaceManager _uiManager = default!; + // Need how much volume to change per tick and just remove it when it drops below "0" private readonly Dictionary _fadingOut = new(); @@ -32,6 +35,7 @@ public sealed partial class ContentAudioSystem : SharedContentAudioSystem public const float AmbienceMultiplier = 3f; public const float AmbientMusicMultiplier = 3f; public const float LobbyMultiplier = 3f; + public const float InterfaceMultiplier = 2f; public override void Initialize() { diff --git a/Content.Client/Construction/UI/ConstructionMenuPresenter.cs b/Content.Client/Construction/UI/ConstructionMenuPresenter.cs index 28cf3ba16c..9a09436176 100644 --- a/Content.Client/Construction/UI/ConstructionMenuPresenter.cs +++ b/Content.Client/Construction/UI/ConstructionMenuPresenter.cs @@ -394,7 +394,7 @@ namespace Content.Client.Construction.UI if (IsAtFront) { WindowOpen = false; - _uiManager.GetActiveUIWidget().CraftingButton.Pressed = false; // This does not call CraftingButtonToggled + _uiManager.GetActiveUIWidget().CraftingButton.SetClickPressed(false); // This does not call CraftingButtonToggled } else _constructionView.MoveToFront(); @@ -402,7 +402,7 @@ namespace Content.Client.Construction.UI else { WindowOpen = true; - _uiManager.GetActiveUIWidget().CraftingButton.Pressed = true; // This does not call CraftingButtonToggled + _uiManager.GetActiveUIWidget().CraftingButton.SetClickPressed(true); // This does not call CraftingButtonToggled } } diff --git a/Content.Client/Options/UI/Tabs/AudioTab.xaml b/Content.Client/Options/UI/Tabs/AudioTab.xaml index 528b0ac136..e54b0dc34e 100644 --- a/Content.Client/Options/UI/Tabs/AudioTab.xaml +++ b/Content.Client/Options/UI/Tabs/AudioTab.xaml @@ -74,6 +74,19 @@