Skip to content

Commit

Permalink
Add FTL destinations (#9685)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Jul 15, 2022
1 parent 5e1d019 commit 1251b3a
Show file tree
Hide file tree
Showing 34 changed files with 9,132 additions and 226 deletions.
2 changes: 0 additions & 2 deletions Content.Client/Nutrition/Components/HungerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public override void HandleComponentState(ComponentState? curState, ComponentSta
}

_currentHungerThreshold = hunger.CurrentThreshold;

EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(Owner);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ protected override void Open()
_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();
Expand Down
42 changes: 25 additions & 17 deletions Content.Client/Shuttles/UI/RadarControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -182,7 +187,7 @@ protected override void Draw(DrawingHandleScreen handle)

// 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;

Expand All @@ -206,19 +211,25 @@ protected override void Draw(DrawingHandleScreen handle)

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;
Expand All @@ -227,20 +238,17 @@ protected override void Draw(DrawingHandleScreen handle)

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)
{
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
if (gridCentre.Length > RadarRange)
{
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
{
Expand Down
21 changes: 19 additions & 2 deletions Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -29,7 +38,7 @@
</PanelContainer>
<BoxContainer Name="RightDisplay"
VerticalAlignment="Top"
HorizontalAlignment="Left"
HorizontalAlignment="Right"
MinWidth="256"
Align="Center"
Orientation="Vertical">
Expand All @@ -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"
Expand Down
96 changes: 93 additions & 3 deletions Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
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;
Expand All @@ -17,6 +19,7 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
IComputerWindow<ShuttleConsoleBoundInterfaceState>
{
private readonly IEntityManager _entManager;
private readonly IGameTiming _timing;

private EntityUid? _shuttleUid;

Expand All @@ -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;
Expand Down Expand Up @@ -91,11 +103,84 @@ public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
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)
Expand All @@ -113,8 +198,6 @@ private void UpdateDocks(List<DockingInterfaceState> docks)
DockPorts.DisposeAllChildren();
DockingScreen.Docks = _docks;


// TODO: Show Placeholder
if (_shuttleUid != null && _docks.TryGetValue(_shuttleUid.Value, out var gridDocks))
{
var index = 1;
Expand Down Expand Up @@ -241,6 +324,13 @@ protected override void Draw(DrawingHandleScreen handle)
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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Content.Shared.Cargo;
using Content.Shared.Cargo.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server.Cargo.Components;

Expand All @@ -22,7 +24,7 @@ public sealed class StationCargoOrderDatabaseComponent : Component
/// </summary>
public int Index;

[ViewVariables, DataField("cargoShuttleProto")]
[ViewVariables, DataField("cargoShuttleProto", customTypeSerializer:typeof(PrototypeIdSerializer<CargoShuttlePrototype>))]
public string? CargoShuttleProto = "CargoShuttle";

/// <summary>
Expand Down
Loading

0 comments on commit 1251b3a

Please sign in to comment.