AnalysisConsoleMenu.xaml.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using Content.Client.Stylesheets;
  2. using Content.Client.UserInterface.Controls;
  3. using Content.Shared.Xenoarchaeology.Equipment;
  4. using Microsoft.VisualBasic;
  5. using Robust.Client.AutoGenerated;
  6. using Robust.Client.GameObjects;
  7. using Robust.Client.UserInterface.Controls;
  8. using Robust.Client.UserInterface.XAML;
  9. using Robust.Shared.Timing;
  10. using Robust.Shared.Utility;
  11. namespace Content.Client.Xenoarchaeology.Ui;
  12. [GenerateTypedNameReferences]
  13. public sealed partial class AnalysisConsoleMenu : FancyWindow
  14. {
  15. [Dependency] private readonly IEntityManager _ent = default!;
  16. [Dependency] private readonly IGameTiming _timing = default!;
  17. public event Action? OnServerSelectionButtonPressed;
  18. public event Action? OnScanButtonPressed;
  19. public event Action? OnPrintButtonPressed;
  20. public event Action? OnExtractButtonPressed;
  21. public event Action? OnUpBiasButtonPressed;
  22. public event Action? OnDownBiasButtonPressed;
  23. // For rendering the progress bar, updated from BUI state
  24. private TimeSpan? _startTime;
  25. private TimeSpan? _totalTime;
  26. private TimeSpan? _accumulatedRunTime;
  27. private bool _paused;
  28. public AnalysisConsoleMenu()
  29. {
  30. RobustXamlLoader.Load(this);
  31. IoCManager.InjectDependencies(this);
  32. ServerSelectionButton.OnPressed += _ => OnServerSelectionButtonPressed?.Invoke();
  33. ScanButton.OnPressed += _ => OnScanButtonPressed?.Invoke();
  34. PrintButton.OnPressed += _ => OnPrintButtonPressed?.Invoke();
  35. ExtractButton.OnPressed += _ => OnExtractButtonPressed?.Invoke();
  36. UpBiasButton.OnPressed += _ => OnUpBiasButtonPressed?.Invoke();
  37. DownBiasButton.OnPressed += _ => OnDownBiasButtonPressed?.Invoke();
  38. var buttonGroup = new ButtonGroup(false);
  39. UpBiasButton.Group = buttonGroup;
  40. DownBiasButton.Group = buttonGroup;
  41. }
  42. protected override void FrameUpdate(FrameEventArgs args)
  43. {
  44. base.FrameUpdate(args);
  45. if (_startTime is not { } start || _totalTime is not { } total || _accumulatedRunTime is not { } accumulated)
  46. return;
  47. var remaining = total - accumulated;
  48. if (!_paused)
  49. {
  50. // If the analyzer is running, its remaining time is further discounted by the time it's been running for.
  51. remaining += start - _timing.CurTime;
  52. }
  53. var secsText = Math.Max((int) remaining.TotalSeconds, 0);
  54. ProgressLabel.Text = Loc.GetString("analysis-console-progress-text",
  55. ("seconds", secsText));
  56. // 1.0 - div because we want it to tick up not down
  57. ProgressBar.Value = Math.Clamp(1.0f - (float) remaining.Divide(total), 0.0f, 1.0f);
  58. }
  59. public void SetButtonsDisabled(AnalysisConsoleUpdateState state)
  60. {
  61. ScanButton.Disabled = !state.CanScan;
  62. PrintButton.Disabled = !state.CanPrint;
  63. if (state.IsTraversalDown)
  64. DownBiasButton.Pressed = true;
  65. else
  66. UpBiasButton.Pressed = true;
  67. ExtractButton.Disabled = false;
  68. if (!state.ServerConnected)
  69. {
  70. ExtractButton.Disabled = true;
  71. ExtractButton.ToolTip = Loc.GetString("analysis-console-no-server-connected");
  72. }
  73. else if (!state.CanScan)
  74. {
  75. ExtractButton.Disabled = true;
  76. // CanScan can be false if either there's no analyzer connected or if there's
  77. // no entity on the scanner. The `Information` text will always tell the user
  78. // of the former case, but in the latter, it'll only show a message if a scan
  79. // has never been performed, so add a tooltip to indicate that the artifact
  80. // is gone.
  81. if (state.AnalyzerConnected)
  82. {
  83. ExtractButton.ToolTip = Loc.GetString("analysis-console-no-artifact-placed");
  84. }
  85. else
  86. {
  87. ExtractButton.ToolTip = null;
  88. }
  89. }
  90. else if (state.PointAmount <= 0)
  91. {
  92. ExtractButton.Disabled = true;
  93. ExtractButton.ToolTip = Loc.GetString("analysis-console-no-points-to-extract");
  94. }
  95. if (ExtractButton.Disabled)
  96. {
  97. ExtractButton.RemoveStyleClass("ButtonColorGreen");
  98. }
  99. else
  100. {
  101. ExtractButton.AddStyleClass("ButtonColorGreen");
  102. ExtractButton.ToolTip = null;
  103. }
  104. }
  105. private void UpdateArtifactIcon(EntityUid? uid)
  106. {
  107. if (uid == null)
  108. {
  109. ArtifactDisplay.Visible = false;
  110. return;
  111. }
  112. ArtifactDisplay.Visible = true;
  113. ArtifactDisplay.SetEntity(uid);
  114. }
  115. public void UpdateInformationDisplay(AnalysisConsoleUpdateState state)
  116. {
  117. var message = new FormattedMessage();
  118. if (state.Scanning)
  119. {
  120. if (state.Paused)
  121. {
  122. message.AddMarkupOrThrow(Loc.GetString("analysis-console-info-scanner-paused"));
  123. }
  124. else
  125. {
  126. message.AddMarkupOrThrow(Loc.GetString("analysis-console-info-scanner"));
  127. }
  128. Information.SetMessage(message);
  129. UpdateArtifactIcon(null); //set it to blank
  130. return;
  131. }
  132. UpdateArtifactIcon(_ent.GetEntity(state.Artifact));
  133. if (state.ScanReport == null)
  134. {
  135. if (!state.AnalyzerConnected) //no analyzer connected
  136. message.AddMarkupOrThrow(Loc.GetString("analysis-console-info-no-scanner"));
  137. else if (!state.CanScan) //no artifact
  138. message.AddMarkupOrThrow(Loc.GetString("analysis-console-info-no-artifact"));
  139. else if (state.Artifact == null) //ready to go
  140. message.AddMarkupOrThrow(Loc.GetString("analysis-console-info-ready"));
  141. }
  142. else
  143. {
  144. message.AddMessage(state.ScanReport);
  145. }
  146. Information.SetMessage(message);
  147. }
  148. public void UpdateProgressBar(AnalysisConsoleUpdateState state)
  149. {
  150. ProgressBar.Visible = state.Scanning;
  151. ProgressLabel.Visible = state.Scanning;
  152. _startTime = state.StartTime;
  153. _totalTime = state.TotalTime;
  154. _accumulatedRunTime = state.AccumulatedRunTime;
  155. _paused = state.Paused;
  156. }
  157. }