From 35a573117b1edeeb79e130e9de5cc9334c8c153d Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Thu, 11 Aug 2022 03:48:32 +1000 Subject: [PATCH] Fancy IFF labels (#10475) My brain now worked enough to be able to do this since do_after overlay. I just avoided doing another matrix transformation and offset the control. --- Content.Client/Shuttles/UI/RadarControl.cs | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Content.Client/Shuttles/UI/RadarControl.cs b/Content.Client/Shuttles/UI/RadarControl.cs index 01bd88fc25..839e18a7e3 100644 --- a/Content.Client/Shuttles/UI/RadarControl.cs +++ b/Content.Client/Shuttles/UI/RadarControl.cs @@ -200,7 +200,8 @@ public sealed class RadarControl : Control foreach (var grid in _mapManager.FindGridsIntersecting(mapPosition.MapId, new Box2(mapPosition.Position - MaxRadarRange, mapPosition.Position + MaxRadarRange))) { - if (grid.GridEntityId == ourGridId) continue; + if (grid.GridEntityId == ourGridId) + continue; var gridBody = bodyQuery.GetComponent(grid.GridEntityId); if (gridBody.Mass < 10f) @@ -222,6 +223,7 @@ public sealed class RadarControl : Control if (ShowIFF) { + var gridBounds = grid.LocalAABB; Label label; if (!_iffControls.TryGetValue(grid.GridEntityId, out var control)) @@ -232,34 +234,32 @@ public sealed class RadarControl : Control FontColorOverride = Color.Aquamarine, }; - control = new PanelContainer() - { - HorizontalAlignment = HAlignment.Center, - VerticalAlignment = VAlignment.Center, - Children = - { - label - }, - StyleClasses = { StyleNano.StyleClassBorderedWindowPanel }, - }; - - _iffControls[grid.GridEntityId] = control; - AddChild(control); + _iffControls[grid.GridEntityId] = label; + AddChild(label); + } + else + { + label = (Label) control; } var gridCentre = matty.Transform(gridBody.LocalCenter); gridCentre.Y = -gridCentre.Y; var distance = gridCentre.Length; - if (gridCentre.Length > RadarRange) - { - gridCentre = gridCentre.Normalized * RadarRange; - } + // y-offset the control to always render below the grid (vertically) + var yOffset = Math.Max(gridBounds.Height, gridBounds.Width) * MinimapScale / 1.8f / UIScale; - control.Visible = true; - label = (Label) control.GetChild(0); + // 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) / UIScale - new Vector2(label.Width / 2f, -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, Width - label.Width), + Math.Clamp(uiPosition.Y, 10f, Height - label.Height)); + + label.Visible = true; label.Text = Loc.GetString("shuttle-console-iff-label", ("name", name), ("distance", $"{distance:0.0}")); - LayoutContainer.SetPosition(control, ScalePosition(gridCentre) / UIScale); + LayoutContainer.SetPosition(label, uiPosition); } else {