Add cooldown to buttons in borg's laws UI (#31490)
This commit is contained in:
@@ -9,6 +9,7 @@ using Robust.Client.UserInterface;
|
|||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Client.Silicons.Laws.Ui;
|
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 IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
[Dependency] private readonly EntityManager _entityManager = 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)
|
public LawDisplay(EntityUid uid, SiliconLaw law, HashSet<string>? radioChannels)
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
@@ -47,9 +53,12 @@ public sealed partial class LawDisplay : Control
|
|||||||
MinWidth = 75,
|
MinWidth = 75,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_nextAllowedPress[localButton] = TimeSpan.Zero;
|
||||||
|
|
||||||
localButton.OnPressed += _ =>
|
localButton.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
_chatManager.SendMessage($"{lawIdentifierPlaintext}: {lawDescriptionPlaintext}", ChatSelectChannel.Local);
|
_chatManager.SendMessage($"{lawIdentifierPlaintext}: {lawDescriptionPlaintext}", ChatSelectChannel.Local);
|
||||||
|
_nextAllowedPress[localButton] = _timing.CurTime + PressCooldown;
|
||||||
};
|
};
|
||||||
|
|
||||||
LawAnnouncementButtons.AddChild(localButton);
|
LawAnnouncementButtons.AddChild(localButton);
|
||||||
@@ -71,6 +80,8 @@ public sealed partial class LawDisplay : Control
|
|||||||
MinWidth = 75,
|
MinWidth = 75,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_nextAllowedPress[radioChannelButton] = TimeSpan.Zero;
|
||||||
|
|
||||||
radioChannelButton.OnPressed += _ =>
|
radioChannelButton.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
switch (radioChannel)
|
switch (radioChannel)
|
||||||
@@ -80,9 +91,21 @@ public sealed partial class LawDisplay : Control
|
|||||||
default:
|
default:
|
||||||
_chatManager.SendMessage($"{SharedChatSystem.RadioChannelPrefix}{radioChannelProto.KeyCode} {lawIdentifierPlaintext}: {lawDescriptionPlaintext}", ChatSelectChannel.Radio); break;
|
_chatManager.SendMessage($"{SharedChatSystem.RadioChannelPrefix}{radioChannelProto.KeyCode} {lawIdentifierPlaintext}: {lawDescriptionPlaintext}", ChatSelectChannel.Radio); break;
|
||||||
}
|
}
|
||||||
|
_nextAllowedPress[radioChannelButton] = _timing.CurTime + PressCooldown;
|
||||||
};
|
};
|
||||||
|
|
||||||
LawAnnouncementButtons.AddChild(radioChannelButton);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user