WIP pre-reboot checkpoint: Cut 14b HbGpuCanvas HUD + 4 Cut 14a scars
This commit is contained in:
parent
8310246f89
commit
93df511b60
10 changed files with 2630 additions and 2079 deletions
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.HbGpu;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
|
|
@ -38,8 +39,14 @@ public partial class InventoryGridControl : Control
|
|||
private static Shader? _sharedShader;
|
||||
|
||||
private readonly TextureRect _gridSurface;
|
||||
private readonly LabelsOverlay _labelsOverlay;
|
||||
private readonly ShaderMaterial _material;
|
||||
private HbGpuCanvas? _standaloneCanvas;
|
||||
|
||||
private readonly Dictionary<string, string> _lastEmittedTags = new(StringComparer.Ordinal);
|
||||
private readonly char[] _tagScratch = new char[32];
|
||||
private int _overlayEmitCount;
|
||||
private float _standaloneTime;
|
||||
private bool _standaloneDirty = true;
|
||||
|
||||
private Image? _dataImage;
|
||||
private ImageTexture? _dataTex;
|
||||
|
|
@ -83,17 +90,10 @@ public partial class InventoryGridControl : Control
|
|||
_gridSurface.SetAnchorsPreset(LayoutPreset.FullRect);
|
||||
AddChild(_gridSurface);
|
||||
|
||||
_labelsOverlay = new LabelsOverlay(this)
|
||||
{
|
||||
Name = "GridLabelsOverlay",
|
||||
MouseFilter = MouseFilterEnum.Ignore
|
||||
};
|
||||
_labelsOverlay.SetAnchorsPreset(LayoutPreset.FullRect);
|
||||
AddChild(_labelsOverlay);
|
||||
|
||||
MouseExited += OnMouseExited;
|
||||
}
|
||||
|
||||
public bool ExternalHbGpuOwner { get; set; }
|
||||
public ShaderMaterial ShaderMaterial => _material;
|
||||
public Control ShaderSurface => _gridSurface;
|
||||
public ChassisGrid? Grid => _grid;
|
||||
|
|
@ -103,9 +103,24 @@ public partial class InventoryGridControl : Control
|
|||
? _hardpointLookup[c.X, c.Y]
|
||||
: null;
|
||||
|
||||
internal int LabelsDrawCount => _labelsOverlay.DrawCount;
|
||||
internal string? GetLastDrawnLabel(string hardpointId) =>
|
||||
_labelsOverlay.LastDrawnTags.TryGetValue(hardpointId, out string? tag) ? tag : null;
|
||||
internal int OverlayEmitCount => _overlayEmitCount;
|
||||
internal HbGpuCanvas? StandaloneCanvas => _standaloneCanvas;
|
||||
internal string? GetLastEmittedLabel(string hardpointId) =>
|
||||
_lastEmittedTags.TryGetValue(hardpointId, out string? tag) ? tag : null;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (!ExternalHbGpuOwner && _standaloneCanvas is null)
|
||||
{
|
||||
_standaloneCanvas = new HbGpuCanvas
|
||||
{
|
||||
Name = "StandaloneHbGpuCanvas",
|
||||
MouseFilter = MouseFilterEnum.Ignore
|
||||
};
|
||||
_standaloneCanvas.SetAnchorsPreset(LayoutPreset.FullRect);
|
||||
AddChild(_standaloneCanvas);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<int, int>? CellClicked;
|
||||
public event Action<string>? HardpointClicked;
|
||||
|
|
@ -116,13 +131,14 @@ public partial class InventoryGridControl : Control
|
|||
if (what == NotificationResized)
|
||||
{
|
||||
SyncRectUniform();
|
||||
_labelsOverlay.QueueRedraw();
|
||||
_standaloneDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
float dt = (float)delta;
|
||||
_standaloneTime += MathF.Max(0f, dt);
|
||||
|
||||
bool anyPulse = false;
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
|
|
@ -141,6 +157,19 @@ public partial class InventoryGridControl : Control
|
|||
{
|
||||
PackDataTexture(_grid);
|
||||
FlushTextures();
|
||||
_standaloneDirty = true;
|
||||
}
|
||||
|
||||
if (!ExternalHbGpuOwner && _standaloneCanvas is not null && _grid is not null)
|
||||
{
|
||||
bool hasCompatiblePulse = _selectedCargoIndex >= 0 && _selectedCargoIndex < _grid.Cargo.Count;
|
||||
if (_standaloneDirty || hasCompatiblePulse)
|
||||
{
|
||||
_standaloneDirty = false;
|
||||
_standaloneCanvas.BeginFrame();
|
||||
EmitHbGpuOverlay(_standaloneCanvas, Vector2.Zero, _standaloneTime);
|
||||
_standaloneCanvas.EndFrameAndSubmit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +224,7 @@ public partial class InventoryGridControl : Control
|
|||
PackTempTexture(grid);
|
||||
FlushTextures();
|
||||
SyncRectUniform();
|
||||
_labelsOverlay.QueueRedraw();
|
||||
_standaloneDirty = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -224,7 +253,7 @@ public partial class InventoryGridControl : Control
|
|||
}
|
||||
if (dataChanged || tempChanged)
|
||||
{
|
||||
_labelsOverlay.QueueRedraw();
|
||||
_standaloneDirty = true;
|
||||
FlushTextures();
|
||||
}
|
||||
}
|
||||
|
|
@ -236,6 +265,7 @@ public partial class InventoryGridControl : Control
|
|||
_hitPulse[x, y] = Math.Clamp(intensity, 0f, 1f);
|
||||
PackDataTexture(_grid);
|
||||
FlushTextures();
|
||||
_standaloneDirty = true;
|
||||
}
|
||||
|
||||
public bool TryGetCellAt(Vector2 localPos, out Vector2I cell)
|
||||
|
|
@ -282,6 +312,7 @@ public partial class InventoryGridControl : Control
|
|||
{
|
||||
PackDataTexture(_grid);
|
||||
FlushTextures();
|
||||
_standaloneDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -301,6 +332,7 @@ public partial class InventoryGridControl : Control
|
|||
{
|
||||
PackDataTexture(_grid);
|
||||
FlushTextures();
|
||||
_standaloneDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -685,62 +717,218 @@ public partial class InventoryGridControl : Control
|
|||
_ => ColTextLight
|
||||
};
|
||||
|
||||
private sealed partial class LabelsOverlay : Control
|
||||
/// <summary>
|
||||
/// Emits crisp analytic vector cell borders, hardpoint L-brackets, compatibility pulses,
|
||||
/// stripped X-marks, and Monaspace Krypton hardpoint labels into <paramref name="canvas"/>.
|
||||
/// Zero GC allocations on steady-state calls.
|
||||
/// </summary>
|
||||
public void EmitHbGpuOverlay(HbGpuCanvas canvas, Vector2 originOffset, float timeSec)
|
||||
{
|
||||
private readonly InventoryGridControl _owner;
|
||||
public int DrawCount { get; private set; }
|
||||
public readonly Dictionary<string, string> LastDrawnTags = new(StringComparer.Ordinal);
|
||||
|
||||
public LabelsOverlay(InventoryGridControl owner) => _owner = owner;
|
||||
|
||||
public override void _Draw()
|
||||
_overlayEmitCount++;
|
||||
var grid = _grid;
|
||||
if (grid is null)
|
||||
{
|
||||
DrawCount++;
|
||||
LastDrawnTags.Clear();
|
||||
var grid = _owner._grid;
|
||||
if (grid is null) return;
|
||||
return;
|
||||
}
|
||||
|
||||
_owner.ComputeCellLayout(out float cellSize, out Vector2 origin);
|
||||
if (cellSize < 14f) return;
|
||||
ComputeCellLayout(out float cellSize, out Vector2 origin);
|
||||
if (cellSize < 8f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var spec = grid.Spec;
|
||||
int fontSize = cellSize >= 38f ? 10 : 9;
|
||||
float alpha = 0.95f;
|
||||
Vector2 basePos = originOffset + origin;
|
||||
var spec = grid.Spec;
|
||||
ModuleSpec? selectedCargo = _selectedCargoIndex >= 0 && _selectedCargoIndex < grid.Cargo.Count
|
||||
? grid.Cargo[_selectedCargoIndex]
|
||||
: null;
|
||||
HardpointSpec? hoveredHp = HoveredHardpoint;
|
||||
Color flashCol = new(1.0f, 0.76f, 0.38f, 1.0f);
|
||||
Color redAccent = new(0.92f, 0.26f, 0.18f, 1.0f);
|
||||
|
||||
for (int i = 0; i < spec.Hardpoints.Length; i++)
|
||||
// 1. Hull cell outlines, internal subdivisions, and stripped-cell X marks
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
var hp = spec.Hardpoints[i];
|
||||
var mounted = grid.GetMountedOn(hp.Id);
|
||||
var pos = origin + new Vector2(hp.X * cellSize, hp.Y * cellSize);
|
||||
float maxW = MathF.Max(12f, hp.Width * cellSize - 6f);
|
||||
if (!spec.IsActive(x, y))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string tag = mounted is not null
|
||||
? $"{mounted.Spec.Kind.ToString()[..1]}:{mounted.CurrentTemp:F0}°"
|
||||
: hp.Kind.ToString()[..3].ToUpperInvariant();
|
||||
LastDrawnTags[hp.Id] = tag;
|
||||
float cx = basePos.X + x * cellSize;
|
||||
float cy = basePos.Y + y * cellSize;
|
||||
bool stripped = grid.Armor[x, y] <= 0.01f;
|
||||
var hp = _hardpointLookup[x, y];
|
||||
|
||||
if (hp is null)
|
||||
{
|
||||
Color edgeCol = grid.BorderCells[x, y]
|
||||
? ColBorderHull.Lerp(ColBorderRadiatorCell, 0.30f)
|
||||
: ColBorderHull;
|
||||
float pulse = Math.Clamp(_hitPulse[x, y], 0f, 1f);
|
||||
bool isCellHovered = _hoveredCell is { } hc && hc.X == x && hc.Y == y;
|
||||
if (stripped) edgeCol = edgeCol.Lerp(redAccent, 0.65f);
|
||||
if (isCellHovered) edgeCol = edgeCol.Lerp(Colors.White, 0.35f);
|
||||
if (pulse > 0.01f) edgeCol = edgeCol.Lerp(flashCol, pulse * 0.90f);
|
||||
|
||||
float inset = 1.5f;
|
||||
float x0 = cx + inset;
|
||||
float y0 = cy + inset;
|
||||
float x1 = cx + cellSize - inset;
|
||||
float y1 = cy + cellSize - inset;
|
||||
|
||||
// Outer hull perimeter edges get crisp medium lines; internal matched hull edges get faint hairlines
|
||||
bool nMatch = spec.IsActive(x, y - 1) && _hardpointLookup[x, y - 1] is null;
|
||||
bool sMatch = spec.IsActive(x, y + 1) && _hardpointLookup[x, y + 1] is null;
|
||||
bool wMatch = spec.IsActive(x - 1, y) && _hardpointLookup[x - 1, y] is null;
|
||||
bool eMatch = spec.IsActive(x + 1, y) && _hardpointLookup[x + 1, y] is null;
|
||||
|
||||
Color outerCol = new(edgeCol.R, edgeCol.G, edgeCol.B, isCellHovered ? 0.85f : 0.42f);
|
||||
Color innerCol = new(edgeCol.R, edgeCol.G, edgeCol.B, 0.14f);
|
||||
|
||||
if (!nMatch) canvas.DrawLineSegment(x0, y0, x1, y0, 1.2f, outerCol);
|
||||
if (!sMatch) canvas.DrawLineSegment(x0, y1, x1, y1, 1.2f, outerCol);
|
||||
else canvas.DrawLineSegment(cx + 2f, cy + cellSize, cx + cellSize - 2f, cy + cellSize, 0.9f, innerCol);
|
||||
if (!wMatch) canvas.DrawLineSegment(x0, y0, x0, y1, 1.2f, outerCol);
|
||||
if (!eMatch) canvas.DrawLineSegment(x1, y0, x1, y1, 1.2f, outerCol);
|
||||
else canvas.DrawLineSegment(cx + cellSize, cy + 2f, cx + cellSize, cy + cellSize - 2f, 0.9f, innerCol);
|
||||
}
|
||||
|
||||
if (stripped)
|
||||
{
|
||||
float pad = MathF.Max(4.5f, cellSize * 0.18f);
|
||||
Color xCol = new(0.95f, 0.28f, 0.20f, 0.78f);
|
||||
canvas.DrawLineSegment(cx + pad, cy + pad, cx + cellSize - pad, cy + cellSize - pad, 1.5f, xCol);
|
||||
canvas.DrawLineSegment(cx + cellSize - pad, cy + pad, cx + pad, cy + cellSize - pad, 1.5f, xCol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Contiguous hardpoint borders, L-brackets, and Krypton tags
|
||||
float fontSize = cellSize >= 38f ? 10.5f : 9.2f;
|
||||
float compatPulse = 0.72f + 0.28f * MathF.Sin(timeSec * 6.5f);
|
||||
|
||||
for (int i = 0; i < spec.Hardpoints.Length; i++)
|
||||
{
|
||||
var hp = spec.Hardpoints[i];
|
||||
var mounted = grid.GetMountedOn(hp.Id);
|
||||
float hx = basePos.X + hp.X * cellSize;
|
||||
float hy = basePos.Y + hp.Y * cellSize;
|
||||
float hw = hp.Width * cellSize;
|
||||
float hh = hp.Height * cellSize;
|
||||
|
||||
bool strippedHp = !grid.IsHardpointOperational(hp);
|
||||
bool isCompatible = selectedCargo is not null && ChassisGrid.CanFit(hp, selectedCargo);
|
||||
bool isHovered = hoveredHp is not null && ReferenceEquals(hp, hoveredHp);
|
||||
|
||||
float maxPulse = 0f;
|
||||
for (int dy = 0; dy < hp.Height; dy++)
|
||||
{
|
||||
for (int dx = 0; dx < hp.Width; dx++)
|
||||
{
|
||||
int cx = hp.X + dx;
|
||||
int cy = hp.Y + dy;
|
||||
if (cx >= 0 && cy >= 0 && cx < _gridWidth && cy < _gridHeight)
|
||||
{
|
||||
maxPulse = MathF.Max(maxPulse, _hitPulse[cx, cy]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Color accent;
|
||||
if (isCompatible)
|
||||
{
|
||||
accent = ColGold;
|
||||
}
|
||||
else if (mounted is { Spec.IsImperial: true })
|
||||
{
|
||||
accent = ColGold;
|
||||
}
|
||||
else
|
||||
{
|
||||
accent = KindColor(hp.Kind);
|
||||
if (mounted is null)
|
||||
{
|
||||
accent = accent.Lerp(ColBorderHull, 0.45f);
|
||||
}
|
||||
}
|
||||
|
||||
if (strippedHp) accent = accent.Lerp(redAccent, 0.70f);
|
||||
if (isCompatible) accent = accent.Lerp(new Color(0.96f, 0.82f, 0.30f, 1f), compatPulse);
|
||||
if (isHovered) accent = accent.Lerp(Colors.White, 0.35f);
|
||||
if (maxPulse > 0.01f) accent = accent.Lerp(flashCol, maxPulse * 0.90f);
|
||||
|
||||
const float inset = 1.8f;
|
||||
float rx = hx + inset;
|
||||
float ry = hy + inset;
|
||||
float rw = MathF.Max(2f, hw - inset * 2f);
|
||||
float rh = MathF.Max(2f, hh - inset * 2f);
|
||||
|
||||
float ruleAlpha = isCompatible ? 0.68f : (isHovered ? 0.60f : 0.34f);
|
||||
canvas.DrawRectOutline(rx, ry, rw, rh, isCompatible ? 1.5f : 1.0f, new Color(accent.R, accent.G, accent.B, ruleAlpha));
|
||||
|
||||
float arm = Math.Clamp(MathF.Min(rw, rh) * 0.28f, 4.5f, 12f);
|
||||
float bracketThick = (isCompatible || isHovered) ? 2.4f : 1.8f;
|
||||
Color bracketCol = new(accent.R, accent.G, accent.B, 0.96f);
|
||||
canvas.DrawTargetBracketCorner(rx, ry, arm, bracketThick, 0, bracketCol);
|
||||
canvas.DrawTargetBracketCorner(rx + rw, ry, arm, bracketThick, 1, bracketCol);
|
||||
canvas.DrawTargetBracketCorner(rx + rw, ry + rh, arm, bracketThick, 2, bracketCol);
|
||||
canvas.DrawTargetBracketCorner(rx, ry + rh, arm, bracketThick, 3, bracketCol);
|
||||
|
||||
if (cellSize >= 14f)
|
||||
{
|
||||
ReadOnlySpan<char> tagSpan = FormatHardpointTag(hp, mounted, _tagScratch);
|
||||
if (!_lastEmittedTags.TryGetValue(hp.Id, out string? existingTag) || !tagSpan.SequenceEqual(existingTag))
|
||||
{
|
||||
_lastEmittedTags[hp.Id] = new string(tagSpan);
|
||||
}
|
||||
|
||||
Color col = mounted is { Spec.IsImperial: true } ? ColGold : ColTextLight;
|
||||
col.A = alpha;
|
||||
col.A = 0.95f;
|
||||
HbGpuCommandWriter.PackClipRect(hx + 2f, hy + 2f, hw - 4f, hh - 4f, out uint clipMin, out uint clipMax);
|
||||
|
||||
// Dark shadow for crisp legibility over bright thermal glow
|
||||
DrawString(
|
||||
UiFonts.Regular,
|
||||
pos + new Vector2(7f, fontSize + 6f),
|
||||
tag,
|
||||
HorizontalAlignment.Left,
|
||||
maxW - 2f,
|
||||
fontSize,
|
||||
new Color(0.04f, 0.05f, 0.04f, alpha * 0.9f));
|
||||
|
||||
DrawString(
|
||||
UiFonts.Regular,
|
||||
pos + new Vector2(6f, fontSize + 5f),
|
||||
tag,
|
||||
HorizontalAlignment.Left,
|
||||
maxW - 2f,
|
||||
fontSize,
|
||||
col);
|
||||
float tx = hx + 5f;
|
||||
float ty = hy + fontSize + 4.5f;
|
||||
canvas.DrawText(tagSpan, tx + 1f, ty + 1f, fontSize, new Color(0.04f, 0.05f, 0.04f, 0.90f),
|
||||
wght: 550f, stemDarken: true, clipMinPacked: clipMin, clipMaxPacked: clipMax);
|
||||
canvas.DrawText(tagSpan, tx, ty, fontSize, col,
|
||||
wght: 550f, stemDarken: true, clipMinPacked: clipMin, clipMaxPacked: clipMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlySpan<char> FormatHardpointTag(HardpointSpec hp, MountedModule? mounted, char[] buf)
|
||||
{
|
||||
if (mounted is null)
|
||||
{
|
||||
return hp.Kind switch
|
||||
{
|
||||
HardpointKind.Weapon => "WPN",
|
||||
HardpointKind.Engine => "ENG",
|
||||
HardpointKind.Radiator => "RAD",
|
||||
HardpointKind.Armor => "ARM",
|
||||
HardpointKind.Utility => "UTL",
|
||||
_ => "MOD"
|
||||
};
|
||||
}
|
||||
|
||||
buf[0] = mounted.Spec.Kind switch
|
||||
{
|
||||
HardpointKind.Weapon => 'W',
|
||||
HardpointKind.Engine => 'E',
|
||||
HardpointKind.Radiator => 'R',
|
||||
HardpointKind.Armor => 'A',
|
||||
HardpointKind.Utility => 'U',
|
||||
_ => 'M'
|
||||
};
|
||||
buf[1] = ':';
|
||||
int pos = 2;
|
||||
if (mounted.CurrentTemp.TryFormat(buf.AsSpan(pos), out int written, "F0", System.Globalization.CultureInfo.InvariantCulture))
|
||||
{
|
||||
pos += written;
|
||||
}
|
||||
buf[pos++] = '°';
|
||||
return buf.AsSpan(0, pos);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue