Files
tbd-station-14/Content.Client/Info/RulesPopup.xaml.cs
ShadowCommander be6cb75122 Add a wait time for the rules popup (#5823)
* Create new rules popup

* Implement accept and quit buttons

* Add rules accept timer

Forces the player to read the rules by making them wait.

Speed reading the rules took me just under 45 seconds which means it'll take longer than that if someone's reading this for the first time.

* Fix info rules header

* Change _rulesPopup to local variable
2021-12-24 17:32:33 -08:00

70 lines
1.5 KiB
C#

using System;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization;
using Robust.Shared.Timing;
namespace Content.Client.Info;
[GenerateTypedNameReferences]
public partial class RulesPopup : Control
{
private float _timer;
public float Timer
{
get => _timer;
set
{
WaitLabel.Text = Loc.GetString("ui-rules-wait", ("time", MathF.Floor(value)));
_timer = value;
}
}
public event Action? OnQuitPressed;
public event Action? OnAcceptPressed;
public RulesPopup()
{
RobustXamlLoader.Load(this);
AcceptButton.OnPressed += OnAcceptButtonPressed;
QuitButton.OnPressed += OnQuitButtonPressed;
}
private void OnQuitButtonPressed(BaseButton.ButtonEventArgs obj)
{
OnQuitPressed?.Invoke();
Dispose();
}
private void OnAcceptButtonPressed(BaseButton.ButtonEventArgs obj)
{
Parent?.RemoveChild(this);
OnAcceptPressed?.Invoke();
Dispose();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!AcceptButton.Disabled)
return;
if (Timer > 0.0)
{
if (Timer - args.DeltaSeconds < 0)
Timer = 0;
else
Timer -= args.DeltaSeconds;
}
else
{
AcceptButton.Disabled = false;
}
}
}