using UnityEngine;
using UnityEngine.UIElements;
namespace ProjectM.Client
{
///
/// UI Toolkit factories for the in-game HUD — a thin extension of '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
/// pickingMode = Ignore by default so the HUD never eats clicks meant for the game world (only the
/// interactive build-palette buttons opt back into picking).
///
public static class HudUi
{
public static readonly Color Track = new(0f, 0f, 0f, 0.55f);
/// A dark rounded bar track with a percent-width fill child (returned via ).
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;
}
/// A bold HUD label (non-interactive).
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;
}
/// Set a fill's width to a 0..1 fraction of its track.
public static void SetFill(VisualElement fill, float frac)
{
if (fill != null) fill.style.width = Length.Percent(Mathf.Clamp01(frac) * 100f);
}
/// A semi-transparent rounded panel for grouping a cluster of HUD elements.
public static VisualElement Group(Align items = Align.FlexStart)
{
var g = new VisualElement();
g.style.alignItems = items;
g.pickingMode = PickingMode.Ignore;
return g;
}
}
}