]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add cooldown to buttons in borg's laws UI (#31490)
authorHreno <hrenor@gmail.com>
Wed, 4 Dec 2024 10:16:41 +0000 (11:16 +0100)
committerGitHub <noreply@github.com>
Wed, 4 Dec 2024 10:16:41 +0000 (21:16 +1100)
Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs

index 4e412df85813a5a1fca6f1b2b8d9643b302f635e..bb0dba2f57d94309fddcb9b5462359a1313324a6 100644 (file)
@@ -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<Button, TimeSpan> _nextAllowedPress = new();
+
     public LawDisplay(EntityUid uid, SiliconLaw law, HashSet<string>? 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;
+        }
+    }
 }