OfferingWindow.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using Content.Client.Computer;
  2. using Content.Client.UserInterface.Controls;
  3. using Content.Shared.Shuttles.BUIStates;
  4. using Robust.Client.AutoGenerated;
  5. using Robust.Client.Graphics;
  6. using Robust.Client.UserInterface.XAML;
  7. using Robust.Shared.Timing;
  8. namespace Content.Client.Salvage.UI;
  9. /// <summary>
  10. /// Generic window for offering multiple selections with a timer.
  11. /// </summary>
  12. [GenerateTypedNameReferences]
  13. public sealed partial class OfferingWindow : FancyWindow,
  14. IComputerWindow<EmergencyConsoleBoundUserInterfaceState>
  15. {
  16. [Dependency] private readonly IGameTiming _timing = default!;
  17. public bool Claimed;
  18. public TimeSpan NextOffer;
  19. private TimeSpan? _progression;
  20. /// <summary>
  21. /// Time between NextOffers
  22. /// </summary>
  23. public TimeSpan Cooldown;
  24. /// <summary>
  25. /// Time between Progressions
  26. /// </summary>
  27. public TimeSpan ProgressionCooldown;
  28. /// <summary>
  29. /// Secondary timer used for tracking active progress.
  30. /// </summary>
  31. public TimeSpan? Progression
  32. {
  33. get => _progression;
  34. set
  35. {
  36. if (_progression == value)
  37. return;
  38. _progression = value;
  39. if (value == null)
  40. {
  41. ProgressionBox.Visible = false;
  42. }
  43. else
  44. {
  45. ProgressionBox.Visible = true;
  46. }
  47. }
  48. }
  49. public OfferingWindow()
  50. {
  51. RobustXamlLoader.Load(this);
  52. IoCManager.InjectDependencies(this);
  53. ProgressionBar.ForegroundStyleBoxOverride = new StyleBoxFlat(Color.FromHex("#C74EBD"));
  54. }
  55. public void AddOption(OfferingWindowOption option)
  56. {
  57. Container.AddChild(option);
  58. }
  59. public void ClearOptions()
  60. {
  61. Container.DisposeAllChildren();
  62. }
  63. protected override void FrameUpdate(FrameEventArgs args)
  64. {
  65. base.FrameUpdate(args);
  66. if (_progression != null)
  67. {
  68. var remaining = _progression.Value - _timing.CurTime;
  69. if (remaining < TimeSpan.Zero)
  70. {
  71. ProgressionBar.Value = 1f;
  72. ProgressionText.Text = "00:00";
  73. }
  74. else
  75. {
  76. ProgressionBar.Value = 1f - (float) (remaining / ProgressionCooldown);
  77. ProgressionText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";
  78. }
  79. }
  80. if (Claimed)
  81. {
  82. NextOfferBar.Value = 1f;
  83. NextOfferText.Text = "00:00";
  84. }
  85. else
  86. {
  87. var remaining = NextOffer - _timing.CurTime;
  88. if (remaining < TimeSpan.Zero)
  89. {
  90. NextOfferBar.Value = 1f;
  91. NextOfferText.Text = "00:00";
  92. }
  93. else
  94. {
  95. NextOfferBar.Value = 1f - (float) (remaining / Cooldown);
  96. NextOfferText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";
  97. }
  98. }
  99. }
  100. }