Skip to content

Commit

Permalink
"Fix" aghost mass scanner (#9438)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Jul 6, 2022
1 parent a324cd2 commit 0bbdd0c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ protected override void Open()
{
base.Open();
_window = new RadarConsoleWindow();
_window?.OpenCentered();
_window.OnClose += Close;
_window.OpenCentered();
}

protected override void Dispose(bool disposing)
Expand Down
23 changes: 10 additions & 13 deletions Content.Client/Shuttles/UI/RadarControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,33 +145,30 @@ protected override void Draw(DrawingHandleScreen handle)

var mapPosition = _coordinates.Value.ToMap(_entManager);

if (mapPosition.MapId == MapId.Nullspace)
if (mapPosition.MapId == MapId.Nullspace || !xformQuery.TryGetComponent(_coordinates.Value.EntityId, out var xform))
{
Clear();
return;
}

var offset = _coordinates.Value.Position;
Matrix3 matrix;
var offsetMatrix = Matrix3.CreateInverseTransform(
mapPosition.Position,
xform.WorldRotation - _rotation.Value);

// Draw our grid in detail
var ourGridId = _coordinates.Value.GetGridUid(_entManager);
if (ourGridId != null)
{
var offsetMatrix = Matrix3.CreateInverseTransform(offset.X, offset.Y, (float) _rotation.Value.Theta);
var ourGridMatrix = xformQuery.GetComponent(ourGridId.Value).WorldMatrix;
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);
Matrix3.Multiply(in ourGridMatrix, in offsetMatrix, out var matrix);

var ourGridMatrix = xformQuery.GetComponent(ourGridId.Value).InvWorldMatrix;
// Draw our grid; use non-filled boxes so it doesn't look awful.
DrawGrid(handle, matrix, ourGridFixtures, Color.Yellow);

Matrix3.Multiply(in ourGridMatrix, in offsetMatrix, out matrix);
}
else
{
matrix = Matrix3.CreateTranslation(-offset);
DrawDocks(handle, ourGridId.Value, matrix);
}

var invertedPosition = _coordinates.Value.Position - offset;
Expand Down Expand Up @@ -205,7 +202,7 @@ protected override void Draw(DrawingHandleScreen handle)
var gridXform = xformQuery.GetComponent(grid.GridEntityId);
var gridFixtures = fixturesQuery.GetComponent(grid.GridEntityId);
var gridMatrix = gridXform.WorldMatrix;
Matrix3.Multiply(in gridMatrix, in matrix, out var matty);
Matrix3.Multiply(in gridMatrix, in offsetMatrix, out var matty);

if (ShowIFF)
{
Expand Down
22 changes: 19 additions & 3 deletions Content.Server/Shuttles/Systems/RadarConsoleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.UserInterface;
using Content.Shared.Shuttles.BUIStates;
using Content.Shared.Shuttles.Components;
using Content.Shared.Shuttles.Systems;
Expand All @@ -24,13 +25,28 @@ private void OnRadarStartup(EntityUid uid, RadarConsoleComponent component, Comp
protected override void UpdateState(RadarConsoleComponent component)
{
var xform = Transform(component.Owner);

var onGrid = xform.ParentUid == xform.GridUid;
EntityCoordinates? coordinates = onGrid ? xform.Coordinates : null;
Angle? angle = onGrid ? xform.LocalRotation : null;

// Use ourself I guess.
if (TryComp<IntrinsicUIComponent>(component.Owner, out var intrinsic))
{
foreach (var uiKey in intrinsic.UIs)
{
if (uiKey.Key?.Equals(RadarConsoleUiKey.Key) == true)
{
coordinates = new EntityCoordinates(component.Owner, Vector2.Zero);
angle = Angle.Zero;
break;
}
}
}

var radarState = new RadarConsoleBoundInterfaceState(
component.MaxRange,
onGrid ? xform.Coordinates : null,
onGrid ? xform.LocalRotation : null,
coordinates,
angle,
new List<DockingInterfaceState>());

_uiSystem.GetUiOrNull(component.Owner, RadarConsoleUiKey.Key)?.SetState(radarState);
Expand Down

0 comments on commit 0bbdd0c

Please sign in to comment.