Add FTL destinations (#9685)
This commit is contained in:
@@ -22,10 +22,19 @@ public sealed class ShuttleConsoleBoundUserInterface : BoundUserInterface
|
||||
_window.UndockPressed += OnUndockPressed;
|
||||
_window.StartAutodockPressed += OnAutodockPressed;
|
||||
_window.StopAutodockPressed += OnStopAutodockPressed;
|
||||
_window.DestinationPressed += OnDestinationPressed;
|
||||
_window.OpenCentered();
|
||||
_window.OnClose += OnClose;
|
||||
}
|
||||
|
||||
private void OnDestinationPressed(EntityUid obj)
|
||||
{
|
||||
SendMessage(new ShuttleConsoleDestinationMessage()
|
||||
{
|
||||
Destination = obj,
|
||||
});
|
||||
}
|
||||
|
||||
private void OnClose()
|
||||
{
|
||||
Close();
|
||||
|
||||
@@ -35,6 +35,11 @@ public sealed class RadarControl : Control
|
||||
private float _radarMaxRange = 256f;
|
||||
public float RadarRange { get; private set; } = 256f;
|
||||
|
||||
/// <summary>
|
||||
/// Controls the maximum distance that IFF labels will display.
|
||||
/// </summary>
|
||||
public float MaxRadarRange { get; private set; } = 256f * 10f;
|
||||
|
||||
private int MidPoint => SizeFull / 2;
|
||||
private int SizeFull => (int) ((MinimapRadius + MinimapMargin) * 2 * UIScale);
|
||||
private int ScaledMinimapRadius => (int) (MinimapRadius * UIScale);
|
||||
@@ -182,7 +187,7 @@ public sealed class RadarControl : Control
|
||||
|
||||
// Draw other grids... differently
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(mapPosition.MapId,
|
||||
new Box2(mapPosition.Position - RadarRange, mapPosition.Position + RadarRange)))
|
||||
new Box2(mapPosition.Position - MaxRadarRange, mapPosition.Position + MaxRadarRange)))
|
||||
{
|
||||
if (grid.GridEntityId == ourGridId) continue;
|
||||
|
||||
@@ -206,19 +211,25 @@ public sealed class RadarControl : Control
|
||||
|
||||
if (ShowIFF)
|
||||
{
|
||||
Label label;
|
||||
|
||||
if (!_iffControls.TryGetValue(grid.GridEntityId, out var control))
|
||||
{
|
||||
var label = new Label()
|
||||
label = new Label()
|
||||
{
|
||||
HorizontalAlignment = HAlignment.Left,
|
||||
FontColorOverride = Color.Aquamarine,
|
||||
};
|
||||
|
||||
control = new PanelContainer()
|
||||
{
|
||||
HorizontalAlignment = HAlignment.Left,
|
||||
VerticalAlignment = VAlignment.Top,
|
||||
Children = { label },
|
||||
StyleClasses = { StyleNano.StyleClassTooltipPanel },
|
||||
HorizontalAlignment = HAlignment.Center,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
Children =
|
||||
{
|
||||
label
|
||||
},
|
||||
StyleClasses = { StyleNano.StyleClassBorderedWindowPanel },
|
||||
};
|
||||
|
||||
_iffControls[grid.GridEntityId] = control;
|
||||
@@ -227,20 +238,17 @@ public sealed class RadarControl : Control
|
||||
|
||||
var gridCentre = matty.Transform(gridBody.LocalCenter);
|
||||
gridCentre.Y = -gridCentre.Y;
|
||||
var distance = gridCentre.Length;
|
||||
|
||||
// TODO: When we get IFF or whatever we can show controls at a further distance; for now
|
||||
// we don't do that because it would immediately reveal nukies.
|
||||
if (gridCentre.Length < RadarRange)
|
||||
if (gridCentre.Length > RadarRange)
|
||||
{
|
||||
control.Visible = true;
|
||||
var label = (Label) control.GetChild(0);
|
||||
label.Text = Loc.GetString("shuttle-console-iff-label", ("name", name), ("distance", $"{gridCentre.Length:0.0}"));
|
||||
LayoutContainer.SetPosition(control, ScalePosition(gridCentre) / UIScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Visible = false;
|
||||
gridCentre = gridCentre.Normalized * RadarRange;
|
||||
}
|
||||
|
||||
control.Visible = true;
|
||||
label = (Label) control.GetChild(0);
|
||||
label.Text = Loc.GetString("shuttle-console-iff-label", ("name", name), ("distance", $"{distance:0.0}"));
|
||||
LayoutContainer.SetPosition(control, ScalePosition(gridCentre) / UIScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
xmlns:ui1="clr-namespace:Content.Client.HUD.UI"
|
||||
Title="{Loc 'shuttle-console-window-title'}">
|
||||
<GridContainer Columns="3"
|
||||
HorizontalAlignment="Stretch">
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="5 5 5 5">
|
||||
<BoxContainer Name="LeftDisplay"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
@@ -19,6 +20,14 @@
|
||||
Orientation="Vertical">
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<ui1:StripeBack>
|
||||
<Label Name="HyperspaceLabel" Text="{Loc 'shuttle-console-hyperspace-label'}" HorizontalAlignment="Center"/>
|
||||
</ui1:StripeBack>
|
||||
<BoxContainer Name="HyperspaceDestinations"
|
||||
Orientation="Vertical">
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<PanelContainer>
|
||||
<ui:RadarControl Name="RadarScreen"
|
||||
@@ -29,7 +38,7 @@
|
||||
</PanelContainer>
|
||||
<BoxContainer Name="RightDisplay"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
HorizontalAlignment="Right"
|
||||
MinWidth="256"
|
||||
Align="Center"
|
||||
Orientation="Vertical">
|
||||
@@ -40,6 +49,14 @@
|
||||
<GridContainer Columns="2"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Top">
|
||||
<Label Text="{Loc 'shuttle-console-ftl-state'}"/>
|
||||
<Label Name="FTLState"
|
||||
Text="{Loc 'ftl-shuttle-console-available'}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<Label Text="{Loc 'shuttle-console-ftl-timer'}"/>
|
||||
<Label Name="FTLTimer"
|
||||
Text="0.0"
|
||||
HorizontalAlignment="Right"/>
|
||||
<Label Text="{Loc 'shuttle-console-max-radar'}"/>
|
||||
<Label Name="MaxRadarRange"
|
||||
Text="0.0"
|
||||
|
||||
@@ -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