Add FTL destinations (#9685)
This commit is contained in:
@@ -2,12 +2,14 @@ using Content.Client.Computer;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.Shuttles.BUIStates;
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Content.Shared.Shuttles.Systems;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Shuttles.UI;
|
||||
@@ -17,6 +19,7 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
IComputerWindow<ShuttleConsoleBoundInterfaceState>
|
||||
{
|
||||
private readonly IEntityManager _entManager;
|
||||
private readonly IGameTiming _timing;
|
||||
|
||||
private EntityUid? _shuttleUid;
|
||||
|
||||
@@ -28,17 +31,26 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
/// <summary>
|
||||
/// Stored by grid entityid then by states
|
||||
/// </summary>
|
||||
private Dictionary<EntityUid, List<DockingInterfaceState>> _docks = new();
|
||||
private readonly Dictionary<EntityUid, List<DockingInterfaceState>> _docks = new();
|
||||
|
||||
private readonly Dictionary<BaseButton, EntityUid> _destinations = new();
|
||||
|
||||
/// <summary>
|
||||
/// Next FTL state change.
|
||||
/// </summary>
|
||||
public TimeSpan FTLTime;
|
||||
|
||||
public Action<ShuttleMode>? ShuttleModePressed;
|
||||
public Action<EntityUid>? UndockPressed;
|
||||
public Action<EntityUid>? StartAutodockPressed;
|
||||
public Action<EntityUid>? StopAutodockPressed;
|
||||
public Action<EntityUid>? DestinationPressed;
|
||||
|
||||
public ShuttleConsoleWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
_entManager = IoCManager.Resolve<IEntityManager>();
|
||||
_timing = IoCManager.Resolve<IGameTiming>();
|
||||
|
||||
OnRadarRangeChange(RadarScreen.RadarRange);
|
||||
RadarScreen.OnRadarRangeChanged += OnRadarRangeChange;
|
||||
@@ -91,11 +103,84 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
public void UpdateState(ShuttleConsoleBoundInterfaceState scc)
|
||||
{
|
||||
UpdateDocks(scc.Docks);
|
||||
UpdateFTL(scc.Destinations, scc.FTLState, scc.FTLTime);
|
||||
RadarScreen.UpdateState(scc);
|
||||
MaxRadarRange.Text = $"{scc.MaxRange:0}";
|
||||
ShuttleModeDisplay.Pressed = scc.Mode == ShuttleMode.Strafing;
|
||||
}
|
||||
|
||||
private void UpdateFTL(List<(EntityUid Entity, string Destination, bool Enabled)> destinations, FTLState state, TimeSpan time)
|
||||
{
|
||||
HyperspaceDestinations.DisposeAllChildren();
|
||||
_destinations.Clear();
|
||||
|
||||
if (destinations.Count == 0)
|
||||
{
|
||||
HyperspaceDestinations.AddChild(new Label()
|
||||
{
|
||||
Text = Loc.GetString("shuttle-console-hyperspace-none"),
|
||||
HorizontalAlignment = HAlignment.Center,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
destinations.Sort((x, y) => string.Compare(x.Destination, y.Destination, StringComparison.Ordinal));
|
||||
|
||||
foreach (var destination in destinations)
|
||||
{
|
||||
var button = new Button()
|
||||
{
|
||||
Disabled = !destination.Enabled,
|
||||
Text = destination.Destination,
|
||||
};
|
||||
|
||||
_destinations[button] = destination.Entity;
|
||||
button.OnPressed += OnHyperspacePressed;
|
||||
HyperspaceDestinations.AddChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
string stateText;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case Shared.Shuttles.Systems.FTLState.Available:
|
||||
stateText = Loc.GetString("shuttle-console-ftl-available");
|
||||
break;
|
||||
case Shared.Shuttles.Systems.FTLState.Starting:
|
||||
stateText = Loc.GetString("shuttle-console-ftl-starting");
|
||||
break;
|
||||
case Shared.Shuttles.Systems.FTLState.Travelling:
|
||||
stateText = Loc.GetString("shuttle-console-ftl-travelling");
|
||||
break;
|
||||
case Shared.Shuttles.Systems.FTLState.Cooldown:
|
||||
stateText = Loc.GetString("shuttle-console-ftl-cooldown");
|
||||
break;
|
||||
case Shared.Shuttles.Systems.FTLState.Arriving:
|
||||
stateText = Loc.GetString("shuttle-console-ftl-arriving");
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(state), state, null);
|
||||
}
|
||||
|
||||
FTLState.Text = stateText;
|
||||
// Add a buffer due to lag or whatever
|
||||
time += TimeSpan.FromSeconds(0.3);
|
||||
FTLTime = time;
|
||||
FTLTimer.Text = GetFTLText();
|
||||
}
|
||||
|
||||
private string GetFTLText()
|
||||
{
|
||||
return $"{Math.Max(0, (FTLTime - _timing.CurTime).TotalSeconds):0.0}";
|
||||
}
|
||||
|
||||
private void OnHyperspacePressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
var ent = _destinations[obj.Button];
|
||||
DestinationPressed?.Invoke(ent);
|
||||
}
|
||||
|
||||
#region Docking
|
||||
|
||||
private void UpdateDocks(List<DockingInterfaceState> docks)
|
||||
@@ -113,8 +198,6 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
DockPorts.DisposeAllChildren();
|
||||
DockingScreen.Docks = _docks;
|
||||
|
||||
|
||||
// TODO: Show Placeholder
|
||||
if (_shuttleUid != null && _docks.TryGetValue(_shuttleUid.Value, out var gridDocks))
|
||||
{
|
||||
var index = 1;
|
||||
@@ -241,6 +324,13 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
return;
|
||||
}
|
||||
|
||||
if (_entManager.TryGetComponent<MetaDataComponent>(_shuttleUid, out var metadata) && metadata.EntityPaused)
|
||||
{
|
||||
FTLTime += _timing.FrameTime;
|
||||
}
|
||||
|
||||
FTLTimer.Text = GetFTLText();
|
||||
|
||||
var (_, worldRot, worldMatrix) = gridXform.GetWorldPositionRotationMatrix();
|
||||
var worldPos = worldMatrix.Transform(gridBody.LocalCenter);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user