diff --git a/client/HbGpuCanvas.cs b/client/HbGpuCanvas.cs index 5813b8f..a647c75 100644 --- a/client/HbGpuCanvas.cs +++ b/client/HbGpuCanvas.cs @@ -1061,7 +1061,9 @@ layout(location = 4) flat in uvec2 v_clip_packed; layout(location = 0) out vec4 frag_color; void main() {{ - vec2 em_px = fwidth(v_em); + vec2 dx = dFdx(v_em); + vec2 dy = dFdy(v_em); + vec2 em_px = vec2(length(vec2(dx.x, dy.x)), length(vec2(dx.y, dy.y))); vec2 pixelsPerEm = 1.0 / max(em_px, vec2(1e-6)); float cov; diff --git a/client/Hud.cs b/client/Hud.cs index be2c4e1..41acd41 100644 --- a/client/Hud.cs +++ b/client/Hud.cs @@ -160,6 +160,7 @@ public partial class Hud : CanvasLayer private IClientArenaSession? _latestSession; private string? _cachedChassisName; private string _cachedChassisUpper = "CHASSIS"; + private bool _inputBlocked; private bool _dirtyEmit; private bool _emittedThisFrame; @@ -324,11 +325,17 @@ public partial class Hud : CanvasLayer _dirtyEmit = true; } + public void SetInputBlocked(bool blocked) + { + _inputBlocked = blocked; + } + public void SetMatchHudActive(bool active) { Visible = active; if (!active) { + _inputBlocked = false; if (_netPanel.Visible) { _netPanel.Visible = false; @@ -345,7 +352,7 @@ public partial class Hud : CanvasLayer public override void _Input(InputEvent @event) { - if (!Visible || _netPanel.Visible) + if (!Visible || _inputBlocked || _netPanel.Visible) { return; } @@ -757,10 +764,10 @@ public partial class Hud : CanvasLayer EmitOutcomeBanner(session, state, player, net); } - // 8. Optional [F9] Network panel corner brackets + // 8. Optional [F9] Network panel chrome + cyan brackets (drawn behind transparent _netPanel controls) if (_netPanel.Visible) { - _hbCanvas.DrawPanelFrame(_netPanel.GetGlobalRect(), new Color(0f, 0f, 0f, 0f), CyanCol, CyanCol, cornerLen: 14f, borderPx: 1.5f, drawBg: false); + _hbCanvas.DrawPanelFrame(_netPanel.GetGlobalRect(), BgDark, CyanCol, CyanCol, cornerLen: 14f, borderPx: 1.5f, drawBg: true); } _hbCanvas.EndFrameAndSubmit(); @@ -1534,13 +1541,16 @@ public partial class Hud : CanvasLayer _hbCanvas.DrawRectOutline(rowRect.Position.X, rowRect.Position.Y, rowRect.Size.X, rowRect.Size.Y, 1.0f, rowBorder); Color txtCol = selected ? OrangeCol : (mod.IsImperial ? GoldCol : TextLight); - HbGpuCommandWriter.PackClipRect(rowRect.Position.X + 3f, rowRect.Position.Y, rowRect.Size.X - 6f, rowRect.Size.Y, out uint cMin, out uint cMax); float nameX = rowRect.Position.X + 5f; + float maxTextW = rowRect.Size.X - 10f; if (mod.IsImperial) { - nameX += _hbCanvas.DrawText("* ", nameX, rowRect.Position.Y + 13f, 10f, GoldCol, wght: 700f, clipMinPacked: cMin, clipMaxPacked: cMax); + float starW = _hbCanvas.DrawText("* ", nameX, rowRect.Position.Y + 13f, 10f, GoldCol, wght: 700f); + nameX += starW; + maxTextW = MathF.Max(8f, maxTextW - starW); } - _hbCanvas.DrawText(mod.Name, nameX, rowRect.Position.Y + 13f, 10f, txtCol, wght: 450f, clipMinPacked: cMin, clipMaxPacked: cMax); + ReadOnlySpan displayName = TruncateWithEllipsis(mod.Name, maxTextW, 10f, 450f, _scratch); + _hbCanvas.DrawText(displayName, nameX, rowRect.Position.Y + 13f, 10f, txtCol, wght: 450f); Color fitBg = fitHovered ? new Color(0.22f, 0.28f, 0.20f, 0.96f) : BgInner; _hbCanvas.DrawRectFilled(fitRect.Position.X, fitRect.Position.Y, fitRect.Size.X, fitRect.Size.Y, fitBg); @@ -1711,7 +1721,18 @@ public partial class Hud : CanvasLayer // Pointing down chevron above ally head (+PI/2 in screen coords) _hbCanvas.DrawChevron(sp.X, sp.Y, 12f, MathF.PI * 0.5f, AlliedCol); float lw = _hbCanvas.MeasureTextWidth(label, 10.5f, wght: 550f); - _hbCanvas.DrawText(label, sp.X - lw * 0.5f, sp.Y - 10f, 10.5f, AlliedCol, wght: 550f); + float lx = Math.Clamp(sp.X - lw * 0.5f, 6f, MathF.Max(6f, viewSize.X - lw - 6f)); + float ly = sp.Y - 10f; + var aboveBox = new Rect2(lx - 1f, ly - 11f, lw + 2f, 13f); + if (IntersectsStaticHudPanel(aboveBox) || aboveBox.Position.Y < 2f) + { + ly = sp.Y + 19f; + } + var finalBox = new Rect2(lx - 1f, ly - 11f, lw + 2f, 13f); + if (!IntersectsStaticHudPanel(finalBox)) + { + _hbCanvas.DrawText(label, lx, ly, 10.5f, AlliedCol, wght: 550f); + } } else { @@ -1866,10 +1887,10 @@ public partial class Hud : CanvasLayer Vector2 boxCenter = new((minX + maxX) * 0.5f, (minY + maxY) * 0.5f); var rect = new Rect2(boxCenter.X - boxW * 0.5f, boxCenter.Y - boxH * 0.5f, boxW, boxH); - EmitTargetBox(rect, col, dist, hpRatio, isLockedOnLocal); + EmitTargetBox(rect, col, dist, hpRatio, isLockedOnLocal, viewSize); } - private void EmitTargetBox(Rect2 rect, Color col, float dist, float hpRatio, bool isLockedOnLocal) + private void EmitTargetBox(Rect2 rect, Color col, float dist, float hpRatio, bool isLockedOnLocal, Vector2 viewSize) { float x0 = rect.Position.X; float y0 = rect.Position.Y; @@ -1891,14 +1912,7 @@ public partial class Hud : CanvasLayer _hbCanvas.DrawTargetBracketCorner(x1, y1, arm, 2.0f, 2, strokeCol); _hbCanvas.DrawTargetBracketCorner(x0, y1, arm, 2.0f, 3, strokeCol); - // Thin HP bar right above top bracket - float barW = Math.Clamp(rect.Size.X, 22f, 64f); - float barX = (x0 + x1) * 0.5f - barW * 0.5f; - float barY = y0 - 7f; - _hbCanvas.DrawRectFilled(barX - 1f, barY - 1f, barW + 2f, 4f, shadowCol); - _hbCanvas.DrawRectFilled(barX, barY, barW * Math.Clamp(hpRatio, 0f, 1f), 2f, strokeCol); - - // Distance + LOCK tag above HP bar + // Format distance + LOCK tag SpanWriter sw = new(_scratch); sw.AppendFloat(dist, "F0"); sw.Append("m"); @@ -1908,10 +1922,102 @@ public partial class Hud : CanvasLayer } ReadOnlySpan label = sw.Span; float textW = _hbCanvas.MeasureTextWidth(label, 10.5f, wght: 600f); - float tx = (x0 + x1) * 0.5f - textW * 0.5f; - float ty = barY - 3f; - _hbCanvas.DrawText(label, tx + 1f, ty + 1f, 10.5f, ShadowCol, wght: 600f); - _hbCanvas.DrawText(label, tx, ty, 10.5f, strokeCol, wght: 600f); + + float barW = Math.Clamp(rect.Size.X, 22f, 64f); + float centerX = (x0 + x1) * 0.5f; + float barX = Math.Clamp(centerX - barW * 0.5f, 6f, MathF.Max(6f, viewSize.X - barW - 6f)); + float tx = Math.Clamp(centerX - textW * 0.5f, 6f, MathF.Max(6f, viewSize.X - textW - 6f)); + + // Prefer above-box; flip below-box if obstructed by static HUD panels (e.g. TopLeft/TopRight) or top edge + float aboveBarY = y0 - 7f; + float aboveTextY = aboveBarY - 3f; + Rect2 aboveBounds = MakeTagBounds(barX, aboveBarY, barW, tx, aboveTextY, textW, above: true); + + float belowBarY = y1 + 5f; + float belowTextY = belowBarY + 14f; + Rect2 belowBounds = MakeTagBounds(barX, belowBarY, barW, tx, belowTextY, textW, above: false); + + float chosenBarY; + float chosenTextY; + if (!IntersectsStaticHudPanel(aboveBounds) && aboveBounds.Position.Y >= 2f) + { + chosenBarY = aboveBarY; + chosenTextY = aboveTextY; + } + else if (!IntersectsStaticHudPanel(belowBounds) && belowBounds.End.Y <= viewSize.Y - 2f) + { + chosenBarY = belowBarY; + chosenTextY = belowTextY; + } + else + { + // Both top and bottom overlap static HUD panels: nudge horizontally out of top corner panels if possible, else omit unobstructed tag + float nudgedTx = tx; + float nudgedBarX = barX; + if (aboveBounds.Intersects(_topLeftRect)) + { + float shift = _topLeftRect.End.X + 8f - MathF.Min(tx, barX); + if (shift > 0f && MathF.Max(tx + textW, barX + barW) + shift < _topRightRect.Position.X - 8f) + { + nudgedTx += shift; + nudgedBarX += shift; + } + } + else if (aboveBounds.Intersects(_topRightRect)) + { + float shift = MathF.Max(tx + textW, barX + barW) - (_topRightRect.Position.X - 8f); + if (shift > 0f && MathF.Min(tx, barX) - shift > _topLeftRect.End.X + 8f) + { + nudgedTx -= shift; + nudgedBarX -= shift; + } + } + + Rect2 nudgedBounds = MakeTagBounds(nudgedBarX, aboveBarY, barW, nudgedTx, aboveTextY, textW, above: true); + if (!IntersectsStaticHudPanel(nudgedBounds) && nudgedBounds.Position.Y >= 2f) + { + barX = nudgedBarX; + tx = nudgedTx; + chosenBarY = aboveBarY; + chosenTextY = aboveTextY; + } + else + { + return; + } + } + + _hbCanvas.DrawRectFilled(barX - 1f, chosenBarY - 1f, barW + 2f, 4f, shadowCol); + _hbCanvas.DrawRectFilled(barX, chosenBarY, barW * Math.Clamp(hpRatio, 0f, 1f), 2f, strokeCol); + + _hbCanvas.DrawText(label, tx + 1f, chosenTextY + 1f, 10.5f, ShadowCol, wght: 600f); + _hbCanvas.DrawText(label, tx, chosenTextY, 10.5f, strokeCol, wght: 600f); + } + + private static Rect2 MakeTagBounds(float barX, float barY, float barW, float tx, float ty, float textW, bool above) + { + float left = MathF.Min(barX - 1f, tx - 1f); + float right = MathF.Max(barX + barW + 1f, tx + textW + 1f); + if (above) + { + float top = ty - 11f; + float bottom = barY + 3f; + return new Rect2(left, top, right - left, bottom - top); + } + else + { + float top = barY - 1f; + float bottom = ty + 3f; + return new Rect2(left, top, right - left, bottom - top); + } + } + + private bool IntersectsStaticHudPanel(Rect2 rect) + { + return rect.Intersects(_topLeftRect) + || rect.Intersects(_topRightRect) + || rect.Intersects(_bottomLeftRect) + || rect.Intersects(_chyronRect); } private void EmitOffscreenArrow(OffscreenMarker m, Vector2 viewSize, Vector2 center, float halfW, float halfH) @@ -2183,6 +2289,38 @@ public partial class Hud : CanvasLayer WrapTextInto(hint, 376f, 10.0f, 350f, _hintLines); } + private ReadOnlySpan TruncateWithEllipsis(string text, float maxWidthPx, float fontSizePx, float wght, char[] scratch) + { + if (string.IsNullOrEmpty(text) || _hbCanvas is null || _hbCanvas.MeasureTextWidth(text, fontSizePx, wght: wght) <= maxWidthPx) + { + return text; + } + + const string ellipsis = "..."; + int maxCopy = Math.Min(text.Length, scratch.Length - ellipsis.Length); + int bestLen = 0; + for (int len = 1; len <= maxCopy; len++) + { + scratch[len - 1] = text[len - 1]; + scratch[len] = '.'; + scratch[len + 1] = '.'; + scratch[len + 2] = '.'; + if (_hbCanvas.MeasureTextWidth(scratch.AsSpan(0, len + 3), fontSizePx, wght: wght) > maxWidthPx) + { + break; + } + bestLen = len; + } + for (int i = 0; i < bestLen; i++) + { + scratch[i] = text[i]; + } + scratch[bestLen] = '.'; + scratch[bestLen + 1] = '.'; + scratch[bestLen + 2] = '.'; + return scratch.AsSpan(0, bestLen + 3); + } + private void SyncBroadcastChyron(BroadcastFeed broadcast) { var lines = broadcast.Lines; @@ -2194,36 +2332,61 @@ public partial class Hud : CanvasLayer _lastBroadcastFeed = broadcast; _lastChyronVersion = broadcast.Version; - // Wrap recent messages cleanly to 548px so nothing overflows or clips mid-word - int startMsg = Math.Max(0, lines.Count - _chyronDisplayLines.Length); - int outIdx = 0; - for (int m = startMsg; m < lines.Count; m++) + // Evict by whole message from newest backwards so partial tail fragments of evicted messages never appear + int capacity = _chyronDisplayLines.Length; + int remaining = capacity; + int writeBack = capacity; + for (int m = lines.Count - 1; m >= 0 && remaining > 0; m--) { var line = lines[m]; bool isLatestMsg = m == lines.Count - 1; string formatted = $"[{line.Timestamp:00.0}s] {line.Text}"; WrapTextInto(formatted, 548f, isLatestMsg ? 11.5f : 10.8f, isLatestMsg ? 500f : 380f, _chyronWrapScratch); - for (int w = 0; w < _chyronWrapScratch.Count; w++) + + int msgLineCount = _chyronWrapScratch.Count; + if (msgLineCount == 0) { - if (outIdx < _chyronDisplayLines.Length) + continue; + } + + if (isLatestMsg && msgLineCount > remaining) + { + int skip = msgLineCount - remaining; + for (int w = msgLineCount - 1; w >= skip; w--) { - _chyronDisplayLines[outIdx] = _chyronWrapScratch[w]; - _chyronIsLatest[outIdx] = isLatestMsg; - outIdx++; - } - else - { - for (int s = 1; s < _chyronDisplayLines.Length; s++) - { - _chyronDisplayLines[s - 1] = _chyronDisplayLines[s]; - _chyronIsLatest[s - 1] = _chyronIsLatest[s]; - } - _chyronDisplayLines[^1] = _chyronWrapScratch[w]; - _chyronIsLatest[^1] = isLatestMsg; + writeBack--; + _chyronDisplayLines[writeBack] = _chyronWrapScratch[w]; + _chyronIsLatest[writeBack] = true; } + remaining = 0; + break; + } + + if (msgLineCount > remaining) + { + // Whole-message eviction: stop before emitting a partial tail of an older message + break; + } + + for (int w = msgLineCount - 1; w >= 0; w--) + { + writeBack--; + _chyronDisplayLines[writeBack] = _chyronWrapScratch[w]; + _chyronIsLatest[writeBack] = isLatestMsg; + } + remaining -= msgLineCount; + } + + int total = capacity - writeBack; + if (writeBack > 0 && total > 0) + { + for (int i = 0; i < total; i++) + { + _chyronDisplayLines[i] = _chyronDisplayLines[writeBack + i]; + _chyronIsLatest[i] = _chyronIsLatest[writeBack + i]; } } - _chyronLineCount = outIdx; + _chyronLineCount = total; } private void OnHardpointClicked(string hardpointId) @@ -2484,14 +2647,14 @@ public partial class Hud : CanvasLayer { var panelStyle = new StyleBoxFlat { - BgColor = BgDark, - BorderColor = BorderCol, + BgColor = new Color(0f, 0f, 0f, 0f), + BorderColor = new Color(0f, 0f, 0f, 0f), ContentMarginLeft = 10, ContentMarginRight = 10, ContentMarginTop = 8, ContentMarginBottom = 8 }; - panelStyle.SetBorderWidthAll(1); + panelStyle.SetBorderWidthAll(0); _netPanel = new PanelContainer { diff --git a/client/Main.cs b/client/Main.cs index 61a4cab..fff6c32 100644 --- a/client/Main.cs +++ b/client/Main.cs @@ -559,6 +559,7 @@ public partial class Main : Node3D switch (mode) { case ClientScreenMode.MainMenu: + _hud.SetInputBlocked(true); _hud.SetMatchHudActive(false); _serverBrowser.SetBrowserVisible(false); _lobbyScreen.SetLobbyVisible(false); @@ -568,6 +569,7 @@ public partial class Main : Node3D break; case ClientScreenMode.ServerBrowser: + _hud.SetInputBlocked(true); _hud.SetMatchHudActive(false); _mainMenu.SetOverlayKind(MainMenu.OverlayKind.Hidden); _lobbyScreen.SetLobbyVisible(false); @@ -578,6 +580,7 @@ public partial class Main : Node3D break; case ClientScreenMode.Lobby: + _hud.SetInputBlocked(true); _hud.SetMatchHudActive(false); _mainMenu.SetOverlayKind(MainMenu.OverlayKind.Hidden); _serverBrowser.SetBrowserVisible(false); @@ -592,6 +595,7 @@ public partial class Main : Node3D _lobbyScreen.SetLobbyVisible(false); _arena.Visible = true; _hud.SetMatchHudActive(true); + _hud.SetInputBlocked(false); break; case ClientScreenMode.PauseOverlay: @@ -599,6 +603,7 @@ public partial class Main : Node3D _lobbyScreen.SetLobbyVisible(false); _arena.Visible = true; _hud.SetMatchHudActive(true); + _hud.SetInputBlocked(true); _mainMenu.SetPauseContext(BuildPauseContextLine()); _mainMenu.SetOverlayKind(MainMenu.OverlayKind.PauseOverlay); break; diff --git a/client/tests/Smoke.cs b/client/tests/Smoke.cs index d9f7c3a..503730f 100644 --- a/client/tests/Smoke.cs +++ b/client/tests/Smoke.cs @@ -1151,7 +1151,7 @@ public partial class Smoke : Node $"Expected PomDecalPool to hold >= 1 active decal, got {_main.Arena.PomDecals.ActiveCount}"); _main.Hud.PushTestHitArc(localC.X + 20f, localC.Z + 10f, WeaponVisualClass.Explosive); - Check(_main.Hud.ActiveHitArcCount >= 1, "Expected CrosshairOverlay to accept incoming hit arc"); + Check(_main.Hud.ActiveHitArcCount >= 1, "Expected Hud HbGpuCanvas to accept incoming hit arc"); } // 11. Finding 1: Merged MultiMeshPartPool meshes preserve real non-white material albedos and intact COLOR_0.R AO