using System; using System.Collections.Generic; using GazeLab.Combat; using GazeLab.Core; using GazeLab.Data; using UnityEngine; using UnityEngine.UI; namespace GazeLab.UI { /// /// Modular presenter and procedural builder for the Rogue-Lite Meta-Progression Tree modal, /// matching the exact live UI styling, colors, containers, sprites, and font hierarchy of TechTreeModal in Main.unity. /// public sealed class MetaTreeModalView { private sealed class MetaNodeSocketWidget { public GameObject rootGo; public RectTransform rectTransform; public Button button; public DwellButton dwellButton; public Image outerGlowImage; public Image socketRimImage; public Outline outline; public Image iconImage; public Text shortNameLabel; public Text rankBadgeText; public MetaUpgradeNodeSO boundNode; public Vector2 normalizedPos; } private readonly GazeLabHUD hud; private readonly Font font; private readonly GazeLabUIThemeSO theme; private GameObject overlayRoot; private Text headerPointsAvailableText; private Text headerPointsTotalText; private Text metaStatusText; private Button resetDistributionBtn; private Text resetBtnLabel; private Button instantBuyBtn; private Text instantBuyToggleLabel; private bool instantBuyEnabled = true; private RectTransform graphCanvasRect; private TechTreeConduitGraphic conduitGraphic; private readonly List nodeSockets = new List(); private readonly List conduitEdgesBuffer = new List(); // Right Inspector Card private RectTransform detailCardRoot; private Image detailTrackBanner; private Text detailCategoryBadge; private Image detailIconBg; private Image detailIcon; private Text detailTitle; private Text detailRankStatus; private Text detailDescription; private Text detailPrereqHeader; private Text detailPrereqChecklist; private Text detailCostText; private Button detailBuyButton; private Text detailBuyBtnLabel; // Bottom Action Bar private Text bottomInfoText; private Button bottomActionBtn; private Text bottomActionBtnLabel; private MetaUpgradeNodeSO currentlySelectedNode; private MetaUpgradeNodeSO currentlyHoveredNode; public GameObject RootGameObject => overlayRoot; public bool IsOpen => overlayRoot != null && overlayRoot.activeSelf; public MetaTreeModalView(GazeLabHUD ownerHud, Font defaultFont, GazeLabUIThemeSO uiTheme) { hud = ownerHud; font = defaultFont; theme = uiTheme != null ? uiTheme : ScriptableObject.CreateInstance(); } public void Build(RectTransform canvasRect) { Transform existing = canvasRect.Find("MetaTreeModal"); if (existing != null) { BindExisting(existing.gameObject); return; } RectTransform overlay = hud.CreatePanelElement( canvasRect, "MetaTreeModal", Vector2.zero, Vector2.one, theme.modalBackdropColor); overlayRoot = overlay.gameObject; BuildHeaderBar(overlay); BuildSubBarAndLegend(overlay); BuildConstellationGraphArea(overlay); BuildDetailInspectorCard(overlay); BuildBottomBar(overlay); overlayRoot.SetActive(false); RebuildSocketsFromDefinition(); } public void BindExisting(GameObject modalRoot) { overlayRoot = modalRoot; RectTransform overlay = overlayRoot.GetComponent(); Transform closeBtn = overlay.Find("CloseTreeBtn"); if (closeBtn != null) { Button b = closeBtn.GetComponent