a4edf7a03b
Rebuild the in-game HUD on UI Toolkit (HudUi/HudSystem, Aether palette) consistent with the menu; build-palette bar (BuildPaletteState) drives cursor->cell ground-ghost preview (green/red via BuildPreviewMath), left-click place / right-click cancel / rotate; fire suppressed in build mode; combat juice restyle. +4 BuildPreviewMath EditMode tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
2.8 KiB
C#
69 lines
2.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace ProjectM.Client
|
|
{
|
|
/// <summary>
|
|
/// UI Toolkit factories for the in-game HUD — a thin extension of <see cref="MenuUi"/>'s Aether palette so the
|
|
/// HUD reads in the same visual language as the menu / pause / settings screens. Bars are a dark rounded track
|
|
/// + a percent-width fill; labels use the shared text weights/colours. Every element is built
|
|
/// <c>pickingMode = Ignore</c> by default so the HUD never eats clicks meant for the game world (only the
|
|
/// interactive build-palette buttons opt back into picking).
|
|
/// </summary>
|
|
public static class HudUi
|
|
{
|
|
public static readonly Color Track = new(0f, 0f, 0f, 0.55f);
|
|
|
|
/// <summary>A dark rounded bar track with a percent-width fill child (returned via <paramref name="fill"/>).</summary>
|
|
public static VisualElement Bar(float width, float height, Color fillColor, out VisualElement fill)
|
|
{
|
|
var track = new VisualElement();
|
|
track.style.width = width;
|
|
track.style.height = height;
|
|
track.style.backgroundColor = Track;
|
|
track.style.paddingLeft = 2; track.style.paddingRight = 2;
|
|
track.style.paddingTop = 2; track.style.paddingBottom = 2;
|
|
track.style.flexDirection = FlexDirection.Row;
|
|
track.pickingMode = PickingMode.Ignore;
|
|
MenuUi.Round(track, 4);
|
|
|
|
fill = new VisualElement();
|
|
fill.style.height = Length.Percent(100);
|
|
fill.style.width = Length.Percent(100);
|
|
fill.style.backgroundColor = fillColor;
|
|
fill.pickingMode = PickingMode.Ignore;
|
|
MenuUi.Round(fill, 3);
|
|
track.Add(fill);
|
|
return track;
|
|
}
|
|
|
|
/// <summary>A bold HUD label (non-interactive).</summary>
|
|
public static Label Text(string text, int size, Color color, TextAnchor align)
|
|
{
|
|
var l = new Label(text);
|
|
l.style.fontSize = size;
|
|
l.style.color = color;
|
|
l.style.unityTextAlign = align;
|
|
l.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|
l.pickingMode = PickingMode.Ignore;
|
|
return l;
|
|
}
|
|
|
|
/// <summary>Set a fill's width to a 0..1 fraction of its track.</summary>
|
|
public static void SetFill(VisualElement fill, float frac)
|
|
{
|
|
if (fill != null) fill.style.width = Length.Percent(Mathf.Clamp01(frac) * 100f);
|
|
}
|
|
|
|
/// <summary>A semi-transparent rounded panel for grouping a cluster of HUD elements.</summary>
|
|
public static VisualElement Group(Align items = Align.FlexStart)
|
|
{
|
|
var g = new VisualElement();
|
|
g.style.alignItems = items;
|
|
g.pickingMode = PickingMode.Ignore;
|
|
return g;
|
|
}
|
|
|
|
}
|
|
}
|