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;
{
[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);
MinWidth = 75,
};
+ _nextAllowedPress[localButton] = TimeSpan.Zero;
+
localButton.OnPressed += _ =>
{
_chatManager.SendMessage($"{lawIdentifierPlaintext}: {lawDescriptionPlaintext}", ChatSelectChannel.Local);
+ _nextAllowedPress[localButton] = _timing.CurTime + PressCooldown;
};
LawAnnouncementButtons.AddChild(localButton);
MinWidth = 75,
};
+ _nextAllowedPress[radioChannelButton] = TimeSpan.Zero;
+
radioChannelButton.OnPressed += _ =>
{
switch (radioChannel)
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;
+ }
+ }
}