From 5578bcc6f861a2211e9f2678d4132ae50f2a303d Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sat, 11 May 2024 11:21:06 +1000 Subject: [PATCH] Fix votes using an audio entity (#27871) * Fix votes using an audio entity Just retains a source around and uses that. I think the audio limit is like 256 sources on the lower end so this is like whatever to persist. * Restart * weh --- Content.Client/Voting/VoteManager.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Content.Client/Voting/VoteManager.cs b/Content.Client/Voting/VoteManager.cs index 63c706c86b..a7c799b58f 100644 --- a/Content.Client/Voting/VoteManager.cs +++ b/Content.Client/Voting/VoteManager.cs @@ -6,12 +6,15 @@ using Robust.Client; using Robust.Client.Audio; using Robust.Client.Console; using Robust.Client.GameObjects; +using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; using Robust.Shared.IoC; using Robust.Shared.Network; using Robust.Shared.Timing; using Robust.Shared.Player; using Robust.Shared.Audio; +using Robust.Shared.Audio.Sources; +using Robust.Shared.ContentPack; namespace Content.Client.Voting @@ -31,16 +34,20 @@ namespace Content.Client.Voting public sealed class VoteManager : IVoteManager { + [Dependency] private readonly IAudioManager _audio = default!; + [Dependency] private readonly IBaseClient _client = default!; + [Dependency] private readonly IClientConsoleHost _console = default!; [Dependency] private readonly IClientNetManager _netManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; - [Dependency] private readonly IClientConsoleHost _console = default!; - [Dependency] private readonly IBaseClient _client = default!; + [Dependency] private readonly IResourceCache _res = default!; private readonly Dictionary _standardVoteTimeouts = new(); private readonly Dictionary _votes = new(); private readonly Dictionary _votePopups = new(); private Control? _popupContainer; + private IAudioSource? _voteSource; + public bool CanCallVote { get; private set; } public event Action? CanCallVoteChanged; @@ -49,6 +56,14 @@ namespace Content.Client.Voting public void Initialize() { + const string sound = "/Audio/Effects/voteding.ogg"; + _voteSource = _audio.CreateAudioSource(_res.GetResource(sound)); + + if (_voteSource != null) + { + _voteSource.Global = true; + } + _netManager.RegisterNetMessage(ReceiveVoteData); _netManager.RegisterNetMessage(ReceiveVoteCanCall); @@ -125,9 +140,8 @@ namespace Content.Client.Voting return; } + _voteSource?.Restart(); @new = true; - IoCManager.Resolve().GetEntitySystem() - .PlayGlobal("/Audio/Effects/voteding.ogg", Filter.Local(), false); // Refresh var container = _popupContainer; -- 2.51.2