From 152cf3388b889ffb54fc801b8d515f815828fd0a Mon Sep 17 00:00:00 2001 From: Hreno Date: Wed, 4 Dec 2024 11:16:41 +0100 Subject: [PATCH] Add cooldown to buttons in borg's laws UI (#31490) --- .../Silicons/Laws/Ui/LawDisplay.xaml.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs b/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs index 4e412df858..bb0dba2f57 100644 --- a/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs +++ b/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs @@ -9,6 +9,7 @@ using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; using Robust.Shared.Prototypes; +using Robust.Shared.Timing; using Robust.Shared.Utility; namespace Content.Client.Silicons.Laws.Ui; @@ -18,8 +19,13 @@ public sealed partial class LawDisplay : Control { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IChatManager _chatManager = default!; + [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly EntityManager _entityManager = default!; + private static readonly TimeSpan PressCooldown = TimeSpan.FromSeconds(3); + + private readonly Dictionary _nextAllowedPress = new(); + public LawDisplay(EntityUid uid, SiliconLaw law, HashSet? radioChannels) { RobustXamlLoader.Load(this); @@ -47,9 +53,12 @@ public sealed partial class LawDisplay : Control MinWidth = 75, }; + _nextAllowedPress[localButton] = TimeSpan.Zero; + localButton.OnPressed += _ => { _chatManager.SendMessage($"{lawIdentifierPlaintext}: {lawDescriptionPlaintext}", ChatSelectChannel.Local); + _nextAllowedPress[localButton] = _timing.CurTime + PressCooldown; }; LawAnnouncementButtons.AddChild(localButton); @@ -71,6 +80,8 @@ public sealed partial class LawDisplay : Control MinWidth = 75, }; + _nextAllowedPress[radioChannelButton] = TimeSpan.Zero; + radioChannelButton.OnPressed += _ => { switch (radioChannel) @@ -80,9 +91,21 @@ public sealed partial class LawDisplay : Control default: _chatManager.SendMessage($"{SharedChatSystem.RadioChannelPrefix}{radioChannelProto.KeyCode} {lawIdentifierPlaintext}: {lawDescriptionPlaintext}", ChatSelectChannel.Radio); break; } + _nextAllowedPress[radioChannelButton] = _timing.CurTime + PressCooldown; }; LawAnnouncementButtons.AddChild(radioChannelButton); } } + + protected override void FrameUpdate(FrameEventArgs args) + { + base.FrameUpdate(args); + + var curTime = _timing.CurTime; + foreach (var (button, nextPress) in _nextAllowedPress) + { + button.Disabled = curTime < nextPress; + } + } }