|
| 1 | +using Content.Client.UserInterface.Controls; |
| 2 | +using Content.Shared._Emberfall.CCVar; |
| 3 | +using Robust.Client.AutoGenerated; |
| 4 | +using Robust.Client.UserInterface.Controls; |
| 5 | +using Robust.Client.UserInterface.XAML; |
| 6 | +using Robust.Shared.Configuration; |
| 7 | +using Robust.Shared.Timing; |
| 8 | +using Robust.Shared.Utility; |
| 9 | + |
| 10 | +namespace Content.Client._Emberfall.RoundEnd; |
| 11 | + |
| 12 | +[GenerateTypedNameReferences] |
| 13 | +public sealed partial class NoEorgPopup : FancyWindow |
| 14 | +{ |
| 15 | + [Dependency] private readonly IConfigurationManager _cfg = default!; |
| 16 | + |
| 17 | + private float _remainingTime; |
| 18 | + private bool _initialSkipState; |
| 19 | + |
| 20 | + public NoEorgPopup() |
| 21 | + { |
| 22 | + IoCManager.InjectDependencies(this); |
| 23 | + RobustXamlLoader.Load(this); |
| 24 | + |
| 25 | + InitializeUI(); |
| 26 | + InitializeEvents(); |
| 27 | + ResetTimer(); |
| 28 | + } |
| 29 | + |
| 30 | + private void InitializeUI() |
| 31 | + { |
| 32 | + TitleLabel.Text = Loc.GetString("no-eorg-popup-label"); |
| 33 | + MessageLabel.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("no-eorg-popup-message"))); |
| 34 | + RuleLabel.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("no-eorg-popup-rule"))); |
| 35 | + RuleTextLabel.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("no-eorg-popup-rule-text"))); |
| 36 | + |
| 37 | + _initialSkipState = |
| 38 | + _cfg.GetCVar(ECCVars.SkipRoundEndNoEorgPopup); // Store the initial CVar value to compare against |
| 39 | + SkipCheckBox.Pressed = _initialSkipState; |
| 40 | + NoEorgCloseButton.Disabled = true; |
| 41 | + |
| 42 | + UpdateCloseButtonText(); |
| 43 | + } |
| 44 | + |
| 45 | + private void InitializeEvents() |
| 46 | + { |
| 47 | + OnClose += SaveSkipState; // Only change the CVar once the close button is pressed |
| 48 | + NoEorgCloseButton.OnPressed += OnClosePressed; |
| 49 | + } |
| 50 | + |
| 51 | + private void ResetTimer() |
| 52 | + { |
| 53 | + _remainingTime = _cfg.GetCVar(ECCVars.RoundEndNoEorgPopupTime); // Set how long to show the popup for |
| 54 | + UpdateCloseButtonText(); |
| 55 | + } |
| 56 | + |
| 57 | + private void SaveSkipState() |
| 58 | + { |
| 59 | + if (SkipCheckBox.Pressed == _initialSkipState) |
| 60 | + return; |
| 61 | + |
| 62 | + _cfg.SetCVar(ECCVars.SkipRoundEndNoEorgPopup, SkipCheckBox.Pressed); |
| 63 | + _cfg.SaveToFile(); |
| 64 | + } |
| 65 | + |
| 66 | + private void OnClosePressed(BaseButton.ButtonEventArgs args) |
| 67 | + { |
| 68 | + Close(); |
| 69 | + } |
| 70 | + |
| 71 | + private void UpdateCloseButtonText() |
| 72 | + { |
| 73 | + var isWaiting = _remainingTime > 0f; |
| 74 | + NoEorgCloseButton.Text = isWaiting |
| 75 | + ? Loc.GetString("no-eorg-popup-close-button-wait", ("time", (int)MathF.Ceiling(_remainingTime))) |
| 76 | + : Loc.GetString("no-eorg-popup-close-button"); |
| 77 | + NoEorgCloseButton.Disabled = isWaiting; |
| 78 | + } |
| 79 | + |
| 80 | + protected override void FrameUpdate(FrameEventArgs args) |
| 81 | + { |
| 82 | + base.FrameUpdate(args); |
| 83 | + |
| 84 | + if (!NoEorgCloseButton.Disabled) |
| 85 | + return; |
| 86 | + |
| 87 | + _remainingTime = MathF.Max(0f, _remainingTime - args.DeltaSeconds); |
| 88 | + UpdateCloseButtonText(); |
| 89 | + } |
| 90 | +} |
0 commit comments