Refactor FTL time tracking code to fix a UI bug (#26538)
The FTL UI on the shuttle console would reset the FTL progress bar every time you open it. This is because the server only sends "time until completion", not a start/end time. The FTL code now uses a separate start/end time so the exact same progress bar can be preserved. For convenience, I made a StartEndTime record struct that stores the actual tuple. This is now used by the code and has some helpers.
This commit is contained in:
committed by
GitHub
parent
72c6a14d59
commit
3b791459c7
@@ -5,6 +5,7 @@ using Content.Shared.Shuttles.BUIStates;
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Content.Shared.Shuttles.Systems;
|
||||
using Content.Shared.Shuttles.UI.MapObjects;
|
||||
using Content.Shared.Timing;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
@@ -38,16 +39,11 @@ public sealed partial class MapScreen : BoxContainer
|
||||
private EntityUid? _shuttleEntity;
|
||||
|
||||
private FTLState _state;
|
||||
private float _ftlDuration;
|
||||
private StartEndTime _ftlTime;
|
||||
|
||||
private List<ShuttleBeaconObject> _beacons = new();
|
||||
private List<ShuttleExclusionObject> _exclusions = new();
|
||||
|
||||
/// <summary>
|
||||
/// When the next FTL state change happens.
|
||||
/// </summary>
|
||||
private TimeSpan _nextFtlTime;
|
||||
|
||||
private TimeSpan _nextPing;
|
||||
private TimeSpan _pingCooldown = TimeSpan.FromSeconds(3);
|
||||
private TimeSpan _nextMapDequeue;
|
||||
@@ -114,8 +110,7 @@ public sealed partial class MapScreen : BoxContainer
|
||||
_beacons = state.Destinations;
|
||||
_exclusions = state.Exclusions;
|
||||
_state = state.FTLState;
|
||||
_ftlDuration = state.FTLDuration;
|
||||
_nextFtlTime = _timing.CurTime + TimeSpan.FromSeconds(_ftlDuration);
|
||||
_ftlTime = state.FTLTime;
|
||||
MapRadar.InFtl = true;
|
||||
MapFTLState.Text = Loc.GetString($"shuttle-console-ftl-state-{_state.ToString()}");
|
||||
|
||||
@@ -511,20 +506,8 @@ public sealed partial class MapScreen : BoxContainer
|
||||
MapRebuildButton.Disabled = false;
|
||||
}
|
||||
|
||||
var ftlDiff = (float) (_nextFtlTime - _timing.CurTime).TotalSeconds;
|
||||
|
||||
float ftlRatio;
|
||||
|
||||
if (_ftlDuration.Equals(0f))
|
||||
{
|
||||
ftlRatio = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
ftlRatio = Math.Clamp(1f - (ftlDiff / _ftlDuration), 0f, 1f);
|
||||
}
|
||||
|
||||
FTLBar.Value = ftlRatio;
|
||||
var progress = _ftlTime.ProgressAt(curTime);
|
||||
FTLBar.Value = float.IsFinite(progress) ? progress : 1;
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
|
||||
Reference in New Issue
Block a user