Coordinates under IFF Label on Mass Scanners and Shuttle Consoles (#31501)

* adds coord label beneath iff label

* fixed wrong coordinate system being used

* changes the clamping on the label UI to instead normalise the UI's distance vector from the centre of the screen, fixes corner-hugging

* cleaned up if-statement by moving the calc ahead of it

* fixed clamping, fixed parenting issue, added draw cull on coord label

---------

Co-authored-by: archrbx <punk.gear5260@fastmail.com>
This commit is contained in:
ArchRBX
2024-09-19 02:25:47 +01:00
committed by GitHub
parent 0c5a053ae4
commit 1c3cfeeb35

View File

@@ -199,7 +199,9 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
var gridMatrix = _transform.GetWorldMatrix(gUid); var gridMatrix = _transform.GetWorldMatrix(gUid);
var matty = Matrix3x2.Multiply(gridMatrix, ourWorldMatrixInvert); var matty = Matrix3x2.Multiply(gridMatrix, ourWorldMatrixInvert);
var color = _shuttles.GetIFFColor(grid, self: false, iff);
var labelColor = _shuttles.GetIFFColor(grid, self: false, iff);
var coordColor = new Color(labelColor.R * 0.8f, labelColor.G * 0.8f, labelColor.B * 0.8f, 0.5f);
// Others default: // Others default:
// Color.FromHex("#FFC000FF") // Color.FromHex("#FFC000FF")
@@ -213,25 +215,52 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
var gridCentre = Vector2.Transform(gridBody.LocalCenter, matty); var gridCentre = Vector2.Transform(gridBody.LocalCenter, matty);
gridCentre.Y = -gridCentre.Y; gridCentre.Y = -gridCentre.Y;
var distance = gridCentre.Length(); var distance = gridCentre.Length();
var labelText = Loc.GetString("shuttle-console-iff-label", ("name", labelName), var labelText = Loc.GetString("shuttle-console-iff-label", ("name", labelName),
("distance", $"{distance:0.0}")); ("distance", $"{distance:0.0}"));
var mapCoords = _transform.GetWorldPosition(gUid);
var coordsText = $"({mapCoords.X:0.0}, {mapCoords.Y:0.0})";
// yes 1.0 scale is intended here. // yes 1.0 scale is intended here.
var labelDimensions = handle.GetDimensions(Font, labelText, 1f); var labelDimensions = handle.GetDimensions(Font, labelText, 1f);
var coordsDimensions = handle.GetDimensions(Font, coordsText, 0.7f);
// y-offset the control to always render below the grid (vertically) // y-offset the control to always render below the grid (vertically)
var yOffset = Math.Max(gridBounds.Height, gridBounds.Width) * MinimapScale / 1.8f; var yOffset = Math.Max(gridBounds.Height, gridBounds.Width) * MinimapScale / 1.8f;
// The actual position in the UI. We offset the matrix position to render it off by half its width // The actual position in the UI. We centre the label by offsetting the matrix position
// plus by the offset. // by half the label's width, plus the y-offset
var uiPosition = ScalePosition(gridCentre)- new Vector2(labelDimensions.X / 2f, -yOffset); var gridScaledPosition = ScalePosition(gridCentre) - new Vector2(0, -yOffset);
// Look this is uggo so feel free to cleanup. We just need to clamp the UI position to within the viewport. // Normalize the grid position if it exceeds the viewport bounds
uiPosition = new Vector2(Math.Clamp(uiPosition.X, 0f, PixelWidth - labelDimensions.X ), // normalizing it instead of clamping it preserves the direction of the vector and prevents corner-hugging
Math.Clamp(uiPosition.Y, 0f, PixelHeight - labelDimensions.Y)); var gridOffset = gridScaledPosition / PixelSize - new Vector2(0.5f, 0.5f);
var offsetMax = Math.Max(Math.Abs(gridOffset.X), Math.Abs(gridOffset.Y)) * 2f;
if (offsetMax > 1)
{
gridOffset = new Vector2(gridOffset.X / offsetMax, gridOffset.Y / offsetMax);
handle.DrawString(Font, uiPosition, labelText, color); gridScaledPosition = (gridOffset + new Vector2(0.5f, 0.5f)) * PixelSize;
}
var labelUiPosition = gridScaledPosition - new Vector2(labelDimensions.X / 2f, 0);
var coordUiPosition = gridScaledPosition - new Vector2(coordsDimensions.X / 2f, -labelDimensions.Y);
// clamp the IFF label's UI position to within the viewport extents so it hugs the edges of the viewport
// coord label intentionally isn't clamped so we don't get ugly clutter at the edges
var controlExtents = PixelSize - new Vector2(labelDimensions.X, labelDimensions.Y); //new Vector2(labelDimensions.X * 2f, labelDimensions.Y);
labelUiPosition = Vector2.Clamp(labelUiPosition, Vector2.Zero, controlExtents);
// draw IFF label
handle.DrawString(Font, labelUiPosition, labelText, labelColor);
// only draw coords label if close enough
if (offsetMax < 1)
{
handle.DrawString(Font, coordUiPosition, coordsText, 0.7f, coordColor);
}
} }
// Detailed view // Detailed view
@@ -241,7 +270,7 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
if (!gridAABB.Intersects(viewAABB)) if (!gridAABB.Intersects(viewAABB))
continue; continue;
DrawGrid(handle, matty, grid, color); DrawGrid(handle, matty, grid, labelColor);
DrawDocks(handle, gUid, matty); DrawDocks(handle, gUid, matty);
} }
} }