]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Coordinates under IFF Label on Mass Scanners and Shuttle Consoles (#31501)
authorArchRBX <5040911+ArchRBX@users.noreply.github.com>
Thu, 19 Sep 2024 01:25:47 +0000 (02:25 +0100)
committerGitHub <noreply@github.com>
Thu, 19 Sep 2024 01:25:47 +0000 (11:25 +1000)
* 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>
Content.Client/Shuttles/UI/ShuttleNavControl.xaml.cs

index 64ead32586d27e201b6b4679ebfe6b5f9eb0378e..2674343e059144414d1fa4362b14de305ba9aa38 100644 (file)
@@ -199,7 +199,9 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
 
             var gridMatrix = _transform.GetWorldMatrix(gUid);
             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:
             // Color.FromHex("#FFC000FF")
@@ -213,25 +215,52 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
 
                 var gridCentre = Vector2.Transform(gridBody.LocalCenter, matty);
                 gridCentre.Y = -gridCentre.Y;
+
                 var distance = gridCentre.Length();
                 var labelText = Loc.GetString("shuttle-console-iff-label", ("name", labelName),
                     ("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.
                 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)
                 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
-                // plus by the offset.
-                var uiPosition = ScalePosition(gridCentre)- new Vector2(labelDimensions.X / 2f, -yOffset);
+                // The actual position in the UI. We centre the label by offsetting the matrix position 
+                // by half the label's width, plus the y-offset
+                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.
-                uiPosition = new Vector2(Math.Clamp(uiPosition.X, 0f, PixelWidth - labelDimensions.X ),
-                    Math.Clamp(uiPosition.Y, 0f, PixelHeight - labelDimensions.Y));
+                // Normalize the grid position if it exceeds the viewport bounds
+                // normalizing it instead of clamping it preserves the direction of the vector and prevents corner-hugging
+                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);
+
+                    gridScaledPosition = (gridOffset + new Vector2(0.5f, 0.5f)) * PixelSize;
+                }
 
-                handle.DrawString(Font, uiPosition, labelText, color);
+                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
@@ -241,7 +270,7 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
             if (!gridAABB.Intersects(viewAABB))
                 continue;
 
-            DrawGrid(handle, matty, grid, color);
+            DrawGrid(handle, matty, grid, labelColor);
             DrawDocks(handle, gUid, matty);
         }
     }