Station maps (#13027)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Shuttles.BUIStates;
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using JetBrains.Annotations;
|
||||
@@ -13,7 +14,6 @@ using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Shuttles.UI;
|
||||
@@ -21,13 +21,11 @@ namespace Content.Client.Shuttles.UI;
|
||||
/// <summary>
|
||||
/// Displays nearby grids inside of a control.
|
||||
/// </summary>
|
||||
public sealed class RadarControl : Control
|
||||
public sealed class RadarControl : MapGridControl
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
private const float ScrollSensitivity = 8f;
|
||||
private const float GridLinesDistance = 32f;
|
||||
|
||||
/// <summary>
|
||||
@@ -37,26 +35,6 @@ public sealed class RadarControl : Control
|
||||
|
||||
private Angle? _rotation;
|
||||
|
||||
private float _radarMinRange = SharedRadarConsoleSystem.DefaultMinRange;
|
||||
private float _radarMaxRange = SharedRadarConsoleSystem.DefaultMaxRange;
|
||||
public float RadarRange { get; private set; } = SharedRadarConsoleSystem.DefaultMinRange;
|
||||
|
||||
/// <summary>
|
||||
/// We'll lerp between the radarrange and actual range
|
||||
/// </summary>
|
||||
private float _actualRadarRange = SharedRadarConsoleSystem.DefaultMinRange;
|
||||
|
||||
/// <summary>
|
||||
/// Controls the maximum distance that IFF labels will display.
|
||||
/// </summary>
|
||||
public float MaxRadarRange { get; private set; } = 256f * 10f;
|
||||
|
||||
private int MinimapRadius => (int) Math.Min(Size.X, Size.Y) / 2;
|
||||
private Vector2 MidPoint => (Size / 2) * UIScale;
|
||||
private int SizeFull => (int) (MinimapRadius * 2 * UIScale);
|
||||
private int ScaledMinimapRadius => (int) (MinimapRadius * UIScale);
|
||||
private float MinimapScale => RadarRange != 0 ? ScaledMinimapRadius / RadarRange : 0f;
|
||||
|
||||
/// <summary>
|
||||
/// Shows a label on each radar object.
|
||||
/// </summary>
|
||||
@@ -79,11 +57,9 @@ public sealed class RadarControl : Control
|
||||
/// </summary>
|
||||
public Action<EntityCoordinates>? OnRadarClick;
|
||||
|
||||
public RadarControl()
|
||||
public RadarControl() : base(64f, 256f, 256f)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
MinSize = (SizeFull, SizeFull);
|
||||
RectClipContent = true;
|
||||
|
||||
}
|
||||
|
||||
public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
|
||||
@@ -92,25 +68,6 @@ public sealed class RadarControl : Control
|
||||
_rotation = angle;
|
||||
}
|
||||
|
||||
public void UpdateState(RadarConsoleBoundInterfaceState ls)
|
||||
{
|
||||
_radarMaxRange = ls.MaxRange;
|
||||
|
||||
if (_radarMaxRange < _radarMinRange)
|
||||
_radarMinRange = _radarMaxRange;
|
||||
|
||||
_actualRadarRange = Math.Clamp(_actualRadarRange, _radarMinRange, _radarMaxRange);
|
||||
|
||||
_docks.Clear();
|
||||
|
||||
foreach (var state in ls.Docks)
|
||||
{
|
||||
var coordinates = state.Coordinates;
|
||||
var grid = _docks.GetOrNew(coordinates.EntityId);
|
||||
grid.Add(state);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void KeyBindUp(GUIBoundKeyEventArgs args)
|
||||
{
|
||||
base.KeyBindUp(args);
|
||||
@@ -148,32 +105,38 @@ public sealed class RadarControl : Control
|
||||
return coords;
|
||||
}
|
||||
|
||||
protected override void MouseWheel(GUIMouseWheelEventArgs args)
|
||||
public void UpdateState(RadarConsoleBoundInterfaceState ls)
|
||||
{
|
||||
base.MouseWheel(args);
|
||||
AddRadarRange(-args.Delta.Y * 1f / ScrollSensitivity * RadarRange);
|
||||
}
|
||||
WorldMaxRange = ls.MaxRange;
|
||||
|
||||
public void AddRadarRange(float value)
|
||||
{
|
||||
_actualRadarRange = Math.Clamp(_actualRadarRange + value, _radarMinRange, _radarMaxRange);
|
||||
if (WorldMaxRange < WorldRange)
|
||||
{
|
||||
ActualRadarRange = WorldMaxRange;
|
||||
}
|
||||
|
||||
if (WorldMaxRange < WorldMinRange)
|
||||
WorldMinRange = WorldMaxRange;
|
||||
|
||||
ActualRadarRange = Math.Clamp(ActualRadarRange, WorldMinRange, WorldMaxRange);
|
||||
|
||||
_docks.Clear();
|
||||
|
||||
foreach (var state in ls.Docks)
|
||||
{
|
||||
var coordinates = state.Coordinates;
|
||||
var grid = _docks.GetOrNew(coordinates.EntityId);
|
||||
grid.Add(state);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
if (!_actualRadarRange.Equals(RadarRange))
|
||||
{
|
||||
var diff = _actualRadarRange - RadarRange;
|
||||
var lerpRate = 10f;
|
||||
|
||||
RadarRange += (float) Math.Clamp(diff, -lerpRate * MathF.Abs(diff) * _timing.FrameTime.TotalSeconds, lerpRate * MathF.Abs(diff) * _timing.FrameTime.TotalSeconds);
|
||||
OnRadarRangeChanged?.Invoke(RadarRange);
|
||||
}
|
||||
base.Draw(handle);
|
||||
|
||||
var fakeAA = new Color(0.08f, 0.08f, 0.08f);
|
||||
|
||||
handle.DrawCircle((MidPoint.X, MidPoint.Y), ScaledMinimapRadius + 1, fakeAA);
|
||||
handle.DrawCircle((MidPoint.X, MidPoint.Y), ScaledMinimapRadius, Color.Black);
|
||||
handle.DrawCircle((MidPoint, MidPoint), ScaledMinimapRadius + 1, fakeAA);
|
||||
handle.DrawCircle((MidPoint, MidPoint), ScaledMinimapRadius, Color.Black);
|
||||
|
||||
// No data
|
||||
if (_coordinates == null || _rotation == null)
|
||||
@@ -184,18 +147,18 @@ public sealed class RadarControl : Control
|
||||
|
||||
var gridLines = new Color(0.08f, 0.08f, 0.08f);
|
||||
var gridLinesRadial = 8;
|
||||
var gridLinesEquatorial = (int) Math.Floor(RadarRange / GridLinesDistance);
|
||||
var gridLinesEquatorial = (int) Math.Floor(WorldRange / GridLinesDistance);
|
||||
|
||||
for (var i = 1; i < gridLinesEquatorial + 1; i++)
|
||||
{
|
||||
handle.DrawCircle((MidPoint.X, MidPoint.Y), GridLinesDistance * MinimapScale * i, gridLines, false);
|
||||
handle.DrawCircle((MidPoint, MidPoint), GridLinesDistance * MinimapScale * i, gridLines, false);
|
||||
}
|
||||
|
||||
for (var i = 0; i < gridLinesRadial; i++)
|
||||
{
|
||||
Angle angle = (Math.PI / gridLinesRadial) * i;
|
||||
var aExtent = angle.ToVec() * ScaledMinimapRadius;
|
||||
handle.DrawLine((MidPoint.X, MidPoint.Y) - aExtent, (MidPoint.X, MidPoint.Y) + aExtent, gridLines);
|
||||
handle.DrawLine((MidPoint, MidPoint) - aExtent, (MidPoint, MidPoint) + aExtent, gridLines);
|
||||
}
|
||||
|
||||
var metaQuery = _entManager.GetEntityQuery<MetaDataComponent>();
|
||||
@@ -368,7 +331,7 @@ public sealed class RadarControl : Control
|
||||
var position = state.Coordinates.Position;
|
||||
var uiPosition = matrix.Transform(position);
|
||||
|
||||
if (uiPosition.Length > RadarRange - DockScale) continue;
|
||||
if (uiPosition.Length > WorldRange - DockScale) continue;
|
||||
|
||||
var color = HighlightedDock == ent ? state.HighlightedColor : state.Color;
|
||||
|
||||
@@ -446,7 +409,7 @@ public sealed class RadarControl : Control
|
||||
var adjustedStart = matrix.Transform(start);
|
||||
var adjustedEnd = matrix.Transform(end);
|
||||
|
||||
if (adjustedStart.Length > RadarRange || adjustedEnd.Length > RadarRange)
|
||||
if (adjustedStart.Length > ActualRadarRange || adjustedEnd.Length > ActualRadarRange)
|
||||
continue;
|
||||
|
||||
start = ScalePosition(new Vector2(adjustedStart.X, -adjustedStart.Y));
|
||||
|
||||
Reference in New Issue
Block a user