Files
OldThink/Content.Client/Audio/AudioUIController.cs

107 lines
3.0 KiB
C#
Raw Permalink Normal View History

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))
{
Черри пики 7 (#592) * Remake gasp popup to emote (#27736) * fix * Silence ringtones on admin PDAs (#29801) * Silence ringtones on invisible PDAs * Revert "Silence ringtones on invisible PDAs" This reverts commit afc1041f31eebe82e83630a856a8856b877a9826. * Literally just this * Add an admin announcement for news article publishing * Fix invalid UI hover/click sounds breaking client (#30067) fixes #29561 * Display the administrator's title in ahelp and ahelp relay (#30075) * Adding the admin prefix to the ahelp * Updating the admin prefix * The second update of the admin prefix * Configuration correction * fix * Fix servers ambience sound (#30091) * Fix servers ambience * I'm silly * Clean up * Add pen clicking sound (#30531) * Add pen clicking sound * switch to OnUse and reduce distance a little * Fix exploding pen clicking (#30533) * fix pens * added a bunch more fox noises (#27578) * fuck it we ball * added recommended copyright information * revised copyright license * revised copyright license x2 * finalized the fops # reduced the number of audio clips # adjusted the volume of all fox sounds to be consistent with each other * added new sounds to the overall fox parent mob because we forgot oopsie --------- Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Co-authored-by: to4no_fix <156101927+chavonadelal@users.noreply.github.com> Co-authored-by: Winkarst <74284083+Winkarst-cpu@users.noreply.github.com> Co-authored-by: themias <89101928+themias@users.noreply.github.com> Co-authored-by: nao fujiwara <awkwarddryad@gmail.com>
2024-08-09 02:37:34 +03:00
var resource = GetSoundOrFallback(value, CCVars.UIClickSound.DefaultValue);
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))
{
Черри пики 7 (#592) * Remake gasp popup to emote (#27736) * fix * Silence ringtones on admin PDAs (#29801) * Silence ringtones on invisible PDAs * Revert "Silence ringtones on invisible PDAs" This reverts commit afc1041f31eebe82e83630a856a8856b877a9826. * Literally just this * Add an admin announcement for news article publishing * Fix invalid UI hover/click sounds breaking client (#30067) fixes #29561 * Display the administrator's title in ahelp and ahelp relay (#30075) * Adding the admin prefix to the ahelp * Updating the admin prefix * The second update of the admin prefix * Configuration correction * fix * Fix servers ambience sound (#30091) * Fix servers ambience * I'm silly * Clean up * Add pen clicking sound (#30531) * Add pen clicking sound * switch to OnUse and reduce distance a little * Fix exploding pen clicking (#30533) * fix pens * added a bunch more fox noises (#27578) * fuck it we ball * added recommended copyright information * revised copyright license * revised copyright license x2 * finalized the fops # reduced the number of audio clips # adjusted the volume of all fox sounds to be consistent with each other * added new sounds to the overall fox parent mob because we forgot oopsie --------- Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Co-authored-by: to4no_fix <156101927+chavonadelal@users.noreply.github.com> Co-authored-by: Winkarst <74284083+Winkarst-cpu@users.noreply.github.com> Co-authored-by: themias <89101928+themias@users.noreply.github.com> Co-authored-by: nao fujiwara <awkwarddryad@gmail.com>
2024-08-09 02:37:34 +03:00
var hoverResource = GetSoundOrFallback(value, CCVars.UIHoverSound.DefaultValue);
var hoverSource =
_audioManager.CreateAudioSource(hoverResource);
if (hoverSource != null)
{
hoverSource.Gain = HoverGain * _interfaceGain;
hoverSource.Global = true;
}
_hoverSource = hoverSource;
UIManager.SetHoverSound(hoverSource);
}
else
{
UIManager.SetHoverSound(null);
}
}
Черри пики 7 (#592) * Remake gasp popup to emote (#27736) * fix * Silence ringtones on admin PDAs (#29801) * Silence ringtones on invisible PDAs * Revert "Silence ringtones on invisible PDAs" This reverts commit afc1041f31eebe82e83630a856a8856b877a9826. * Literally just this * Add an admin announcement for news article publishing * Fix invalid UI hover/click sounds breaking client (#30067) fixes #29561 * Display the administrator's title in ahelp and ahelp relay (#30075) * Adding the admin prefix to the ahelp * Updating the admin prefix * The second update of the admin prefix * Configuration correction * fix * Fix servers ambience sound (#30091) * Fix servers ambience * I'm silly * Clean up * Add pen clicking sound (#30531) * Add pen clicking sound * switch to OnUse and reduce distance a little * Fix exploding pen clicking (#30533) * fix pens * added a bunch more fox noises (#27578) * fuck it we ball * added recommended copyright information * revised copyright license * revised copyright license x2 * finalized the fops # reduced the number of audio clips # adjusted the volume of all fox sounds to be consistent with each other * added new sounds to the overall fox parent mob because we forgot oopsie --------- Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Co-authored-by: to4no_fix <156101927+chavonadelal@users.noreply.github.com> Co-authored-by: Winkarst <74284083+Winkarst-cpu@users.noreply.github.com> Co-authored-by: themias <89101928+themias@users.noreply.github.com> Co-authored-by: nao fujiwara <awkwarddryad@gmail.com>
2024-08-09 02:37:34 +03:00
private AudioResource GetSoundOrFallback(string path, string fallback)
{
if (!_cache.TryGetResource(path, out AudioResource? resource))
return _cache.GetResource<AudioResource>(fallback);
return resource;
}
}