WarDeclaratorWindow.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using Content.Client.Stylesheets;
  2. using Content.Client.UserInterface.Controls;
  3. using Content.Shared.NukeOps;
  4. using Robust.Client.AutoGenerated;
  5. using Robust.Client.UserInterface.XAML;
  6. using Robust.Shared.Timing;
  7. using Robust.Shared.Utility;
  8. namespace Content.Client.NukeOps;
  9. [GenerateTypedNameReferences]
  10. public sealed partial class WarDeclaratorWindow : FancyWindow
  11. {
  12. [Dependency] private readonly IGameTiming _gameTiming = default!;
  13. [Dependency] private readonly ILocalizationManager _localizationManager = default!;
  14. public event Action<string>? OnActivated;
  15. private TimeSpan _endTime;
  16. private TimeSpan _shuttleDisabledTime;
  17. private WarConditionStatus _status;
  18. public WarDeclaratorWindow()
  19. {
  20. RobustXamlLoader.Load(this);
  21. IoCManager.InjectDependencies(this);
  22. WarButton.OnPressed += (_) => OnActivated?.Invoke(Rope.Collapse(MessageEdit.TextRope));
  23. MessageEdit.Placeholder = new Rope.Leaf(_localizationManager.GetString("war-declarator-message-placeholder"));
  24. }
  25. protected override void FrameUpdate(FrameEventArgs args)
  26. {
  27. UpdateTimer();
  28. }
  29. public void UpdateState(WarDeclaratorBoundUserInterfaceState state)
  30. {
  31. if (state.Status == null)
  32. return;
  33. WarButton.Disabled = state.Status == WarConditionStatus.WarReady;
  34. _endTime = state.EndTime;
  35. _shuttleDisabledTime = state.ShuttleDisabledTime;
  36. _status = state.Status.Value;
  37. UpdateStatus(state.Status.Value);
  38. }
  39. private void UpdateStatus(WarConditionStatus status)
  40. {
  41. switch (status)
  42. {
  43. case WarConditionStatus.WarReady:
  44. WarButton.Disabled = true;
  45. StatusLabel.Text = Loc.GetString("war-declarator-boost-declared");
  46. UpdateTimer();
  47. StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateLow);
  48. break;
  49. case WarConditionStatus.YesWar:
  50. WarButton.Text = Loc.GetString("war-declarator-ui-war-button");
  51. StatusLabel.Text = Loc.GetString("war-declarator-boost-possible");
  52. UpdateTimer();
  53. StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateGood);
  54. break;
  55. case WarConditionStatus.NoWarSmallCrew:
  56. StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
  57. InfoLabel.Text = Loc.GetString("war-declarator-conditions-small-crew");
  58. StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
  59. break;
  60. case WarConditionStatus.NoWarShuttleDeparted:
  61. StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
  62. InfoLabel.Text = Loc.GetString("war-declarator-conditions-left-outpost");
  63. StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
  64. break;
  65. case WarConditionStatus.NoWarTimeout:
  66. StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
  67. InfoLabel.Text = Loc.GetString("war-declarator-conditions-time-out");
  68. StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
  69. break;
  70. case WarConditionStatus.NoWarUnknown:
  71. StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
  72. InfoLabel.Text = Loc.GetString("war-declarator-conditions-unknown");
  73. StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
  74. break;
  75. default:
  76. StatusLabel.Text = Loc.GetString("war-declarator-boost-impossible");
  77. InfoLabel.Text = Loc.GetString("war-declarator-conditions-unknown");
  78. StatusLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
  79. break;
  80. }
  81. }
  82. private void UpdateTimer()
  83. {
  84. switch(_status)
  85. {
  86. case WarConditionStatus.YesWar:
  87. var timeLeft = _endTime.Subtract(_gameTiming.CurTime);
  88. if (timeLeft > TimeSpan.Zero)
  89. InfoLabel.Text = Loc.GetString("war-declarator-boost-timer", ("time", timeLeft.ToString("mm\\:ss")));
  90. else
  91. UpdateStatus(WarConditionStatus.NoWarTimeout);
  92. break;
  93. case WarConditionStatus.WarReady:
  94. var time = _shuttleDisabledTime.Subtract(_gameTiming.CurTime);
  95. if (time > TimeSpan.Zero)
  96. InfoLabel.Text = Loc.GetString("war-declarator-boost-timer", ("time", time.ToString("mm\\:ss")));
  97. else
  98. InfoLabel.Text = Loc.GetString("war-declarator-conditions-ready");
  99. break;
  100. default:
  101. return;
  102. }
  103. }
  104. }