Optimize artifact analyzer UI state sending (#22949)
* Remove n rename cruft old shit * Artifact analyzer UI updating optimization * Revert "Remove n rename cruft old shit" This reverts commit 8789338fb20f77d79c5b0e40719896efe0103fcc.
This commit is contained in:
@@ -61,6 +61,7 @@ public sealed class AnalysisConsoleBoundUserInterface : BoundUserInterface
|
||||
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
_consoleMenu?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Shared.Xenoarchaeology.Equipment;
|
||||
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;
|
||||
@@ -12,11 +13,17 @@ 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);
|
||||
@@ -28,6 +35,23 @@ public sealed partial class AnalysisConsoleMenu : FancyWindow
|
||||
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;
|
||||
@@ -54,8 +78,8 @@ public sealed partial class AnalysisConsoleMenu : FancyWindow
|
||||
ArtifactDisplay.Visible = false;
|
||||
return;
|
||||
}
|
||||
ArtifactDisplay.Visible = true;
|
||||
|
||||
ArtifactDisplay.Visible = true;
|
||||
ArtifactDisplay.SetEntity(uid);
|
||||
}
|
||||
|
||||
@@ -95,12 +119,8 @@ public sealed partial class AnalysisConsoleMenu : FancyWindow
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,9 +79,6 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
|
||||
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;
|
||||
|
||||
@@ -191,7 +188,7 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
|
||||
|
||||
EntityUid? artifact = null;
|
||||
FormattedMessage? msg = null;
|
||||
var totalTime = TimeSpan.Zero;
|
||||
TimeSpan? totalTime = null;
|
||||
var canScan = false;
|
||||
var canPrint = false;
|
||||
var points = 0;
|
||||
@@ -212,10 +209,9 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
|
||||
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);
|
||||
@@ -256,6 +252,7 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
|
||||
|
||||
var activeArtifact = EnsureComp<ActiveScannedArtifactComponent>(ent.Value);
|
||||
activeArtifact.Scanner = component.AnalyzerEntity.Value;
|
||||
UpdateUserInterface(uid, component);
|
||||
}
|
||||
|
||||
private void OnPrintButton(EntityUid uid, AnalysisConsoleComponent component, AnalysisConsolePrintButtonPressedMessage args)
|
||||
|
||||
@@ -46,14 +46,14 @@ public sealed class AnalysisConsoleScanUpdateState : BoundUserInterfaceState
|
||||
|
||||
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;
|
||||
@@ -64,7 +64,7 @@ public sealed class AnalysisConsoleScanUpdateState : BoundUserInterfaceState
|
||||
ScanReport = scanReport;
|
||||
|
||||
Scanning = scanning;
|
||||
TimeRemaining = timeRemaining;
|
||||
StartTime = startTime;
|
||||
TotalTime = totalTime;
|
||||
|
||||
PointAmount = pointAmount;
|
||||
|
||||
Reference in New Issue
Block a user