using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace IdleSpectator;
///
/// Screen-space count badges over multi-entry grave stacks (pooled, on-screen only).
///
public static class GraveCountBadges
{
private const int PoolSize = 64;
private static readonly List Scratch = new List(256);
private static readonly List Pool = new List(PoolSize);
private static Transform _root;
private static bool _built;
private sealed class Badge
{
public GameObject Go;
public RectTransform Rt;
public Text Label;
}
/// Badges retired - stack size lives in Lore title. Kept so old pools hide cleanly.
public static void Hide()
{
for (int i = 0; i < Pool.Count; i++)
{
if (Pool[i].Go != null)
{
Pool[i].Go.SetActive(false);
}
}
}
public static void Update()
{
Hide();
}
private static void EnsureBuilt()
{
if (_built)
{
return;
}
Canvas canvas = HudCanvas.Resolve();
if (canvas == null)
{
return;
}
GameObject rootGo = new GameObject("IdleGraveCountBadges", typeof(RectTransform));
rootGo.transform.SetParent(canvas.transform, false);
_root = rootGo.transform;
RectTransform rootRt = rootGo.GetComponent();
rootRt.anchorMin = Vector2.zero;
rootRt.anchorMax = Vector2.one;
rootRt.offsetMin = Vector2.zero;
rootRt.offsetMax = Vector2.zero;
for (int i = 0; i < PoolSize; i++)
{
GameObject go = new GameObject("Badge" + i, typeof(RectTransform), typeof(Image));
go.transform.SetParent(_root, false);
RectTransform rt = go.GetComponent();
rt.sizeDelta = new Vector2(14f, 10f);
Image img = go.GetComponent();
img.color = HudTheme.ToolFill;
img.raycastTarget = false;
Text label = HudCanvas.MakeText(go.transform, "N", "2", 8);
RectTransform lrt = label.GetComponent();
lrt.anchorMin = Vector2.zero;
lrt.anchorMax = Vector2.one;
lrt.offsetMin = Vector2.zero;
lrt.offsetMax = Vector2.zero;
label.alignment = TextAnchor.MiddleCenter;
label.color = HudTheme.AccentGold;
label.raycastTarget = false;
go.SetActive(false);
Pool.Add(new Badge { Go = go, Rt = rt, Label = label });
}
_built = true;
}
}