Add cargo shuttle (#8686)
This commit is contained in:
@@ -31,6 +31,9 @@ public class DockingControl : Control
|
||||
public EntityUid? ViewedDock;
|
||||
public EntityUid? GridEntity;
|
||||
|
||||
public EntityCoordinates? Coordinates;
|
||||
public Angle? Angle;
|
||||
|
||||
/// <summary>
|
||||
/// Stored by GridID then by docks
|
||||
/// </summary>
|
||||
@@ -69,11 +72,12 @@ public class DockingControl : Control
|
||||
handle.DrawLine((MidPoint, MidPoint) - aExtent, (MidPoint, MidPoint) + aExtent, gridLines);
|
||||
}
|
||||
|
||||
if (!_entManager.TryGetComponent<TransformComponent>(ViewedDock, out var xform) ||
|
||||
if (Coordinates == null ||
|
||||
Angle == null ||
|
||||
!_entManager.TryGetComponent<TransformComponent>(GridEntity, out var gridXform)) return;
|
||||
|
||||
var rotation = Matrix3.CreateRotation(xform.LocalRotation);
|
||||
var matrix = Matrix3.CreateTranslation(-xform.LocalPosition);
|
||||
var rotation = Matrix3.CreateRotation(Angle.Value);
|
||||
var matrix = Matrix3.CreateTranslation(-Coordinates.Value.Position);
|
||||
|
||||
// Draw the fixtures around the dock before drawing it
|
||||
if (_entManager.TryGetComponent<FixturesComponent>(GridEntity, out var fixtures))
|
||||
@@ -128,7 +132,7 @@ public class DockingControl : Control
|
||||
ScalePosition(rotation.Transform(new Vector2(0.5f, -0.5f)))), Color.Green);
|
||||
|
||||
// Draw nearby grids
|
||||
var worldPos = gridXform.WorldMatrix.Transform(xform.LocalPosition);
|
||||
var worldPos = gridXform.WorldMatrix.Transform(Coordinates.Value.Position);
|
||||
var gridInvMatrix = gridXform.InvWorldMatrix;
|
||||
Matrix3.Multiply(in gridInvMatrix, in matrix, out var invMatrix);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Client.UserInterface;
|
||||
using Content.Shared.Shuttles.BUIStates;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Client.Shuttles.UI;
|
||||
|
||||
@@ -19,4 +20,9 @@ public sealed partial class RadarConsoleWindow : FancyWindow,
|
||||
{
|
||||
RadarScreen.UpdateState(scc);
|
||||
}
|
||||
|
||||
public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
|
||||
{
|
||||
RadarScreen.SetMatrix(coordinates, angle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,11 @@ public sealed class RadarControl : Control
|
||||
private const float GridLinesDistance = 32f;
|
||||
|
||||
/// <summary>
|
||||
/// Entity used to transform all of the radar objects.
|
||||
/// Used to transform all of the radar objects. Typically is a shuttle console parented to a grid.
|
||||
/// </summary>
|
||||
private EntityUid? _entity;
|
||||
private EntityCoordinates? _coordinates;
|
||||
|
||||
private Angle? _rotation;
|
||||
|
||||
private float _radarMinRange = 64f;
|
||||
private float _radarMaxRange = 256f;
|
||||
@@ -61,6 +63,12 @@ public sealed class RadarControl : Control
|
||||
MinSize = (SizeFull, SizeFull);
|
||||
}
|
||||
|
||||
public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
|
||||
{
|
||||
_coordinates = coordinates;
|
||||
_rotation = angle;
|
||||
}
|
||||
|
||||
public void UpdateState(RadarConsoleBoundInterfaceState ls)
|
||||
{
|
||||
_radarMaxRange = ls.MaxRange;
|
||||
@@ -74,7 +82,6 @@ public sealed class RadarControl : Control
|
||||
if (_radarMaxRange < _radarMinRange)
|
||||
_radarMinRange = _radarMaxRange;
|
||||
|
||||
_entity = ls.Entity;
|
||||
_docks.Clear();
|
||||
|
||||
foreach (var state in ls.Docks)
|
||||
@@ -109,7 +116,7 @@ public sealed class RadarControl : Control
|
||||
handle.DrawCircle((MidPoint, MidPoint), ScaledMinimapRadius, Color.Black);
|
||||
|
||||
// No data
|
||||
if (_entity == null)
|
||||
if (_coordinates == null || _rotation == null)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
@@ -135,8 +142,8 @@ public sealed class RadarControl : Control
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
var fixturesQuery = _entManager.GetEntityQuery<FixturesComponent>();
|
||||
var bodyQuery = _entManager.GetEntityQuery<PhysicsComponent>();
|
||||
var xform = xformQuery.GetComponent(_entity.Value);
|
||||
var mapPosition = xform.MapPosition;
|
||||
|
||||
var mapPosition = _coordinates.Value.ToMap(_entManager);
|
||||
|
||||
if (mapPosition.MapId == MapId.Nullspace)
|
||||
{
|
||||
@@ -144,28 +151,30 @@ public sealed class RadarControl : Control
|
||||
return;
|
||||
}
|
||||
|
||||
// Can also use ourGridBody.LocalCenter
|
||||
var offset = xform.Coordinates.Position;
|
||||
var offsetMatrix = Matrix3.CreateTranslation(-offset);
|
||||
var offset = _coordinates.Value.Position;
|
||||
Matrix3 matrix;
|
||||
|
||||
// Draw our grid in detail
|
||||
var ourGridId = xform.GridUid;
|
||||
var ourGridId = _coordinates.Value.GetGridUid(_entManager);
|
||||
if (ourGridId != null)
|
||||
{
|
||||
matrix = xform.InvWorldMatrix;
|
||||
var offsetMatrix = Matrix3.CreateInverseTransform(offset.X, offset.Y, (float) _rotation.Value.Theta);
|
||||
var ourGridFixtures = fixturesQuery.GetComponent(ourGridId.Value);
|
||||
// Draw our grid; use non-filled boxes so it doesn't look awful.
|
||||
DrawGrid(handle, offsetMatrix, ourGridFixtures, Color.Yellow);
|
||||
|
||||
DrawDocks(handle, ourGridId.Value, offsetMatrix);
|
||||
|
||||
var ourGridMatrix = xformQuery.GetComponent(ourGridId.Value).InvWorldMatrix;
|
||||
|
||||
Matrix3.Multiply(in ourGridMatrix, in offsetMatrix, out matrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
matrix = Matrix3.CreateTranslation(-offset);
|
||||
}
|
||||
|
||||
var invertedPosition = xform.Coordinates.Position - offset;
|
||||
var invertedPosition = _coordinates.Value.Position - offset;
|
||||
invertedPosition.Y = -invertedPosition.Y;
|
||||
// Don't need to transform the InvWorldMatrix again as it's already offset to its position.
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.Utility;
|
||||
|
||||
namespace Content.Client.Shuttles.UI;
|
||||
@@ -17,10 +18,7 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
{
|
||||
private readonly IEntityManager _entManager;
|
||||
|
||||
/// <summary>
|
||||
/// EntityUid of the open console.
|
||||
/// </summary>
|
||||
private EntityUid? _entity;
|
||||
private EntityUid? _shuttleUid;
|
||||
|
||||
/// <summary>
|
||||
/// Currently selected dock button for camera.
|
||||
@@ -84,9 +82,14 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
UndockPressed?.Invoke(DockingScreen.ViewedDock.Value);
|
||||
}
|
||||
|
||||
public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
|
||||
{
|
||||
_shuttleUid = coordinates?.EntityId;
|
||||
RadarScreen.SetMatrix(coordinates, angle);
|
||||
}
|
||||
|
||||
public void UpdateState(ShuttleConsoleBoundInterfaceState scc)
|
||||
{
|
||||
_entity = scc.Entity;
|
||||
UpdateDocks(scc.Docks);
|
||||
RadarScreen.UpdateState(scc);
|
||||
MaxRadarRange.Text = $"{scc.MaxRange:0}";
|
||||
@@ -110,21 +113,16 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
DockPorts.DisposeAllChildren();
|
||||
DockingScreen.Docks = _docks;
|
||||
|
||||
if (!_entManager.TryGetComponent<TransformComponent>(_entity, out var xform)
|
||||
|| !xform.GridUid.HasValue)
|
||||
{
|
||||
// TODO: Show Placeholder
|
||||
return;
|
||||
}
|
||||
|
||||
if (_docks.TryGetValue(xform.GridUid.Value, out var gridDocks))
|
||||
// TODO: Show Placeholder
|
||||
if (_shuttleUid != null && _docks.TryGetValue(_shuttleUid.Value, out var gridDocks))
|
||||
{
|
||||
var index = 1;
|
||||
|
||||
foreach (var state in gridDocks)
|
||||
{
|
||||
var ent = state.Entity;
|
||||
var pressed = ent == DockingScreen.ViewedDock;
|
||||
var pressed = state.Entity == DockingScreen.ViewedDock;
|
||||
|
||||
string suffix;
|
||||
|
||||
if (state.Connected)
|
||||
@@ -143,21 +141,26 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
Pressed = pressed,
|
||||
};
|
||||
|
||||
button.OnMouseEntered += args => OnDockMouseEntered(args, ent);
|
||||
button.OnMouseExited += args => OnDockMouseExited(args, ent);
|
||||
button.OnToggled += args => OnDockToggled(args, ent);
|
||||
if (pressed)
|
||||
{
|
||||
_selectedDock = button;
|
||||
}
|
||||
|
||||
button.OnMouseEntered += args => OnDockMouseEntered(args, state);
|
||||
button.OnMouseExited += args => OnDockMouseExited(args, state);
|
||||
button.OnToggled += args => OnDockToggled(args, state);
|
||||
DockPorts.AddChild(button);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDockMouseEntered(GUIMouseHoverEventArgs obj, EntityUid uid)
|
||||
private void OnDockMouseEntered(GUIMouseHoverEventArgs obj, DockingInterfaceState state)
|
||||
{
|
||||
RadarScreen.HighlightedDock = uid;
|
||||
RadarScreen.HighlightedDock = state.Entity;
|
||||
}
|
||||
|
||||
private void OnDockMouseExited(GUIMouseHoverEventArgs obj, EntityUid uid)
|
||||
private void OnDockMouseExited(GUIMouseHoverEventArgs obj, DockingInterfaceState state)
|
||||
{
|
||||
RadarScreen.HighlightedDock = null;
|
||||
}
|
||||
@@ -165,10 +168,18 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
/// <summary>
|
||||
/// Shows a docking camera instead of radar screen.
|
||||
/// </summary>
|
||||
private void OnDockToggled(BaseButton.ButtonEventArgs obj, EntityUid ent)
|
||||
private void OnDockToggled(BaseButton.ButtonEventArgs obj, DockingInterfaceState state)
|
||||
{
|
||||
var ent = state.Entity;
|
||||
|
||||
if (_selectedDock != null)
|
||||
{
|
||||
// If it got untoggled via other means then we'll stop viewing the old dock.
|
||||
if (DockingScreen.ViewedDock != null && DockingScreen.ViewedDock != state.Entity)
|
||||
{
|
||||
StopAutodockPressed?.Invoke(DockingScreen.ViewedDock.Value);
|
||||
}
|
||||
|
||||
_selectedDock.Pressed = false;
|
||||
_selectedDock = null;
|
||||
}
|
||||
@@ -187,15 +198,23 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
}
|
||||
else
|
||||
{
|
||||
// DebugTools.Assert(DockingScreen.ViewedDock == null);
|
||||
_entManager.TryGetComponent<TransformComponent>(_entity, out var xform);
|
||||
if (_shuttleUid != null)
|
||||
{
|
||||
DockingScreen.Coordinates = state.Coordinates;
|
||||
DockingScreen.Angle = state.Angle;
|
||||
}
|
||||
else
|
||||
{
|
||||
DockingScreen.Coordinates = null;
|
||||
DockingScreen.Angle = null;
|
||||
}
|
||||
|
||||
UndockButton.Disabled = false;
|
||||
RadarScreen.Visible = false;
|
||||
DockingScreen.Visible = true;
|
||||
DockingScreen.ViewedDock = ent;
|
||||
StartAutodockPressed?.Invoke(ent);
|
||||
DockingScreen.GridEntity = xform?.GridUid;
|
||||
DockingScreen.GridEntity = _shuttleUid;
|
||||
_selectedDock = obj.Button;
|
||||
}
|
||||
}
|
||||
@@ -215,9 +234,8 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow,
|
||||
{
|
||||
base.Draw(handle);
|
||||
|
||||
if (!_entManager.TryGetComponent<TransformComponent>(_entity, out var entXform) ||
|
||||
!_entManager.TryGetComponent<PhysicsComponent>(entXform.GridUid, out var gridBody) ||
|
||||
!_entManager.TryGetComponent<TransformComponent>(entXform.GridUid, out var gridXform))
|
||||
if (!_entManager.TryGetComponent<PhysicsComponent>(_shuttleUid, out var gridBody) ||
|
||||
!_entManager.TryGetComponent<TransformComponent>(_shuttleUid, out var gridXform))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user