using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.XAML;
+using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.Xenoarchaeology.Ui;
public sealed partial class AnalysisConsoleMenu : FancyWindow
{
[Dependency] private readonly IEntityManager _ent = default!;
+ [Dependency] private readonly IGameTiming _timing = default!;
+
public event Action? OnServerSelectionButtonPressed;
public event Action? OnScanButtonPressed;
public event Action? OnPrintButtonPressed;
public event Action? OnExtractButtonPressed;
+ // For rendering the progress bar, updated from BUI state
+ private TimeSpan? _startTime;
+ private TimeSpan? _totalTime;
+
public AnalysisConsoleMenu()
{
RobustXamlLoader.Load(this);
ExtractButton.OnPressed += _ => OnExtractButtonPressed?.Invoke();
}
+ protected override void FrameUpdate(FrameEventArgs args)
+ {
+ base.FrameUpdate(args);
+
+ if (_startTime is not { } start || _totalTime is not { } total)
+ return;
+
+ var remaining = start + total - _timing.CurTime;
+ var secsText = Math.Max((int) remaining.TotalSeconds, 0);
+
+ ProgressLabel.Text = Loc.GetString("analysis-console-progress-text",
+ ("seconds", secsText));
+
+ // 1.0 - div because we want it to tick up not down
+ ProgressBar.Value = Math.Clamp(1.0f - (float) remaining.Divide(total), 0.0f, 1.0f);
+ }
+
public void SetButtonsDisabled(AnalysisConsoleScanUpdateState state)
{
ScanButton.Disabled = !state.CanScan;
ArtifactDisplay.Visible = false;
return;
}
- ArtifactDisplay.Visible = true;
+ ArtifactDisplay.Visible = true;
ArtifactDisplay.SetEntity(uid);
}
ProgressBar.Visible = state.Scanning;
ProgressLabel.Visible = state.Scanning;
- if (!state.Scanning)
- return;
-
- ProgressLabel.Text = Loc.GetString("analysis-console-progress-text",
- ("seconds", (int) state.TotalTime.TotalSeconds - (int) state.TimeRemaining.TotalSeconds));
- ProgressBar.Value = (float) state.TimeRemaining.Divide(state.TotalTime);
+ _startTime = state.StartTime;
+ _totalTime = state.TotalTime;
}
}
var query = EntityQueryEnumerator<ActiveArtifactAnalyzerComponent, ArtifactAnalyzerComponent>();
while (query.MoveNext(out var uid, out var active, out var scan))
{
- if (scan.Console != null)
- UpdateUserInterface(scan.Console.Value);
-
if (_timing.CurTime - active.StartTime < scan.AnalysisDuration * scan.AnalysisDurationMulitplier)
continue;
EntityUid? artifact = null;
FormattedMessage? msg = null;
- var totalTime = TimeSpan.Zero;
+ TimeSpan? totalTime = null;
var canScan = false;
var canPrint = false;
var points = 0;
var serverConnected = TryComp<ResearchClientComponent>(uid, out var client) && client.ConnectedToServer;
var scanning = TryComp<ActiveArtifactAnalyzerComponent>(component.AnalyzerEntity, out var active);
- var remaining = active != null ? _timing.CurTime - active.StartTime : TimeSpan.Zero;
var state = new AnalysisConsoleScanUpdateState(GetNetEntity(artifact), analyzerConnected, serverConnected,
- canScan, canPrint, msg, scanning, remaining, totalTime, points);
+ canScan, canPrint, msg, scanning, active?.StartTime, totalTime, points);
var bui = _ui.GetUi(uid, ArtifactAnalzyerUiKey.Key);
_ui.SetUiState(bui, state);
var activeArtifact = EnsureComp<ActiveScannedArtifactComponent>(ent.Value);
activeArtifact.Scanner = component.AnalyzerEntity.Value;
+ UpdateUserInterface(uid, component);
}
private void OnPrintButton(EntityUid uid, AnalysisConsoleComponent component, AnalysisConsolePrintButtonPressedMessage args)
public bool Scanning;
- public TimeSpan TimeRemaining;
+ public TimeSpan? StartTime;
- public TimeSpan TotalTime;
+ public TimeSpan? TotalTime;
public int PointAmount;
public AnalysisConsoleScanUpdateState(NetEntity? artifact, bool analyzerConnected, bool serverConnected, bool canScan, bool canPrint,
- FormattedMessage? scanReport, bool scanning, TimeSpan timeRemaining, TimeSpan totalTime, int pointAmount)
+ FormattedMessage? scanReport, bool scanning, TimeSpan? startTime, TimeSpan? totalTime, int pointAmount)
{
Artifact = artifact;
AnalyzerConnected = analyzerConnected;
ScanReport = scanReport;
Scanning = scanning;
- TimeRemaining = timeRemaining;
+ StartTime = startTime;
TotalTime = totalTime;
PointAmount = pointAmount;