Skip to content

Commit

Permalink
Display dock names on the radar console
Browse files Browse the repository at this point in the history
  • Loading branch information
Partmedia committed Jul 20, 2023
1 parent e7c769d commit 8aed973
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
34 changes: 29 additions & 5 deletions Content.Client/Shuttles/UI/RadarControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ protected override void Draw(DrawingHandleScreen handle)
mapPosition.Position,
xform.WorldRotation + _rotation.Value);

var shown = new HashSet<EntityUid>();

// Draw our grid in detail
var ourGridId = _coordinates.Value.GetGridUid(_entManager);
if (_entManager.TryGetComponent<MapGridComponent>(ourGridId, out var ourGrid) &&
Expand All @@ -188,7 +190,7 @@ protected override void Draw(DrawingHandleScreen handle)
Matrix3.Multiply(in ourGridMatrix, in offsetMatrix, out var matrix);

DrawGrid(handle, matrix, ourGrid, Color.MediumSpringGreen, true);
DrawDocks(handle, ourGridId.Value, matrix);
DrawDocks(handle, ourGridId.Value, matrix, shown);
}

var invertedPosition = _coordinates.Value.Position - offset;
Expand All @@ -198,8 +200,6 @@ protected override void Draw(DrawingHandleScreen handle)
// Draw radar position on the station
handle.DrawCircle(ScalePosition(invertedPosition), 5f, Color.Lime);

var shown = new HashSet<EntityUid>();

// Draw other grids... differently
foreach (var grid in _mapManager.FindGridsIntersecting(mapPosition.MapId,
new Box2(mapPosition.Position - MaxRadarRange, mapPosition.Position + MaxRadarRange)))
Expand Down Expand Up @@ -288,7 +288,7 @@ protected override void Draw(DrawingHandleScreen handle)
// Detailed view
DrawGrid(handle, matty, grid, color, true);

DrawDocks(handle, grid.Owner, matty);
DrawDocks(handle, grid.Owner, matty, shown);
}

foreach (var (ent, _) in _iffControls)
Expand All @@ -315,7 +315,7 @@ private void ClearLabel(EntityUid uid)
_iffControls.Remove(uid);
}

private void DrawDocks(DrawingHandleScreen handle, EntityUid uid, Matrix3 matrix)
private void DrawDocks(DrawingHandleScreen handle, EntityUid uid, Matrix3 matrix, HashSet<EntityUid> shown)
{
if (!ShowDocks)
return;
Expand All @@ -324,6 +324,9 @@ private void DrawDocks(DrawingHandleScreen handle, EntityUid uid, Matrix3 matrix

if (_docks.TryGetValue(uid, out var docks))
{
// Keep track of which logical docks we've already drawn labels on, to prevent
// duplicating labels for each group of docks.
var labeled = new HashSet<string>();
foreach (var state in docks)
{
var ent = state.Entity;
Expand Down Expand Up @@ -353,6 +356,27 @@ private void DrawDocks(DrawingHandleScreen handle, EntityUid uid, Matrix3 matrix

handle.DrawPrimitives(DrawPrimitiveTopology.TriangleFan, verts, color.WithAlpha(0.8f));
handle.DrawPrimitives(DrawPrimitiveTopology.LineStrip, verts, color);

// draw dock label
if (state.Name != null && !labeled.Contains(state.Name))
{
labeled.Add(state.Name);
Label label;
if (!_iffControls.TryGetValue(ent, out var control))
{
label = new Label();
_iffControls[ent] = label;
AddChild(label);
}
else
{
label = (Label) control;
}
shown.Add(ent);
label.Visible = true;
label.Text = state.Name;
LayoutContainer.SetPosition(label, ScalePosition(uiPosition));
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private void UpdateDocks(List<DockingInterfaceState> docks)
// We also need to make up some pseudonumber as well for these.
_docks.Clear();

docks.Sort(new DockComparer());
foreach (var dock in docks)
{
var grid = _docks.GetOrNew(dock.Coordinates.EntityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ public sealed class DockingInterfaceState
public Color HighlightedColor;
}

public class DockComparer: IComparer<DockingInterfaceState>
{
public int Compare(DockingInterfaceState a, DockingInterfaceState b)
{
if (a.Name != null && b.Name != null)
return a.Name.CompareTo(b.Name);
else if (a.Name != null) // a has a name but b doesn't
return 1;
else // neither are named, compare by Uid
return a.Entity.CompareTo(b.Entity);
}
}

[Serializable, NetSerializable]
public enum RadarConsoleUiKey : byte
{
Expand Down

0 comments on commit 8aed973

Please sign in to comment.