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.
This commit is contained in:
@@ -200,7 +200,8 @@ public sealed class RadarControl : Control
|
|||||||
foreach (var grid in _mapManager.FindGridsIntersecting(mapPosition.MapId,
|
foreach (var grid in _mapManager.FindGridsIntersecting(mapPosition.MapId,
|
||||||
new Box2(mapPosition.Position - MaxRadarRange, mapPosition.Position + MaxRadarRange)))
|
new Box2(mapPosition.Position - MaxRadarRange, mapPosition.Position + MaxRadarRange)))
|
||||||
{
|
{
|
||||||
if (grid.GridEntityId == ourGridId) continue;
|
if (grid.GridEntityId == ourGridId)
|
||||||
|
continue;
|
||||||
|
|
||||||
var gridBody = bodyQuery.GetComponent(grid.GridEntityId);
|
var gridBody = bodyQuery.GetComponent(grid.GridEntityId);
|
||||||
if (gridBody.Mass < 10f)
|
if (gridBody.Mass < 10f)
|
||||||
@@ -222,6 +223,7 @@ public sealed class RadarControl : Control
|
|||||||
|
|
||||||
if (ShowIFF)
|
if (ShowIFF)
|
||||||
{
|
{
|
||||||
|
var gridBounds = grid.LocalAABB;
|
||||||
Label label;
|
Label label;
|
||||||
|
|
||||||
if (!_iffControls.TryGetValue(grid.GridEntityId, out var control))
|
if (!_iffControls.TryGetValue(grid.GridEntityId, out var control))
|
||||||
@@ -232,34 +234,32 @@ public sealed class RadarControl : Control
|
|||||||
FontColorOverride = Color.Aquamarine,
|
FontColorOverride = Color.Aquamarine,
|
||||||
};
|
};
|
||||||
|
|
||||||
control = new PanelContainer()
|
_iffControls[grid.GridEntityId] = label;
|
||||||
{
|
AddChild(label);
|
||||||
HorizontalAlignment = HAlignment.Center,
|
}
|
||||||
VerticalAlignment = VAlignment.Center,
|
else
|
||||||
Children =
|
{
|
||||||
{
|
label = (Label) control;
|
||||||
label
|
|
||||||
},
|
|
||||||
StyleClasses = { StyleNano.StyleClassBorderedWindowPanel },
|
|
||||||
};
|
|
||||||
|
|
||||||
_iffControls[grid.GridEntityId] = control;
|
|
||||||
AddChild(control);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var gridCentre = matty.Transform(gridBody.LocalCenter);
|
var gridCentre = matty.Transform(gridBody.LocalCenter);
|
||||||
gridCentre.Y = -gridCentre.Y;
|
gridCentre.Y = -gridCentre.Y;
|
||||||
var distance = gridCentre.Length;
|
var distance = gridCentre.Length;
|
||||||
|
|
||||||
if (gridCentre.Length > RadarRange)
|
// y-offset the control to always render below the grid (vertically)
|
||||||
{
|
var yOffset = Math.Max(gridBounds.Height, gridBounds.Width) * MinimapScale / 1.8f / UIScale;
|
||||||
gridCentre = gridCentre.Normalized * RadarRange;
|
|
||||||
}
|
|
||||||
|
|
||||||
control.Visible = true;
|
// The actual position in the UI. We offset the matrix position to render it off by half its width
|
||||||
label = (Label) control.GetChild(0);
|
// 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}"));
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user