Files
HCI_GazeLab/Assets/GazeLab/Scripts/UI/MetaTreeModalView.cs
T

1317 lines
56 KiB
C#

using System;
using System.Collections.Generic;
using GazeLab.Combat;
using GazeLab.Core;
using GazeLab.Data;
using UnityEngine;
using UnityEngine.UI;
namespace GazeLab.UI
{
/// <summary>
/// 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.
/// </summary>
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<MetaNodeSocketWidget> nodeSockets = new List<MetaNodeSocketWidget>();
private readonly List<ConduitEdgeData> conduitEdgesBuffer = new List<ConduitEdgeData>();
// 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<GazeLabUIThemeSO>();
}
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<RectTransform>();
Transform closeBtn = overlay.Find("CloseTreeBtn");
if (closeBtn != null)
{
Button b = closeBtn.GetComponent<Button>();
if (b != null)
{
b.onClick.RemoveAllListeners();
b.onClick.AddListener(CloseModal);
}
DwellButton dw = closeBtn.GetComponent<DwellButton>();
if (dw != null) dw.Bind(CloseModal, 0.85f);
}
Transform pointsPanel = overlay.Find("HeaderResourcesBadgeRow") ?? overlay.Find("HeaderPointsRow");
if (pointsPanel != null)
{
headerPointsAvailableText = pointsPanel.Find("HeaderAvailableBadge/Count")?.GetComponent<Text>()
?? pointsPanel.Find("AvailableBadge/Count")?.GetComponent<Text>();
headerPointsTotalText = pointsPanel.Find("HeaderTotalBadge/Count")?.GetComponent<Text>()
?? pointsPanel.Find("TotalBadge/Count")?.GetComponent<Text>();
}
Transform subBar = overlay.Find("SubBar") ?? overlay.Find("SubActionBar");
if (subBar != null)
{
metaStatusText = subBar.Find("StationStatus")?.GetComponent<Text>()
?? subBar.Find("BonusesSummary")?.GetComponent<Text>();
Transform rBtn = subBar.Find("ResetDistributionBtn") ?? subBar.Find("QuickRepairBtn");
if (rBtn != null)
{
resetDistributionBtn = rBtn.GetComponent<Button>();
resetBtnLabel = rBtn.Find("BtnLabel")?.GetComponent<Text>() ?? rBtn.Find("Label")?.GetComponent<Text>();
if (resetDistributionBtn != null)
{
resetDistributionBtn.onClick.RemoveAllListeners();
resetDistributionBtn.onClick.AddListener(OnResetDistributionClicked);
}
DwellButton dw = rBtn.GetComponent<DwellButton>();
if (dw != null) dw.Bind(OnResetDistributionClicked, 0.90f, KeyCode.R);
}
Transform instBtn = subBar.Find("InstantBuyBtn") ?? subBar.Find("InstantBuyToggleBtn");
if (instBtn != null)
{
instantBuyBtn = instBtn.GetComponent<Button>();
instantBuyToggleLabel = instBtn.Find("BtnLabel")?.GetComponent<Text>() ?? instBtn.Find("Label")?.GetComponent<Text>();
if (instantBuyBtn != null)
{
instantBuyBtn.onClick.RemoveAllListeners();
instantBuyBtn.onClick.AddListener(ToggleInstantBuy);
}
}
}
Transform graphContainer = overlay.Find("ConstellationGraphContainer") ?? overlay.Find("ConstellationGraphPanel");
if (graphContainer != null)
{
graphCanvasRect = graphContainer.Find("GraphInnerCanvas")?.GetComponent<RectTransform>()
?? graphContainer.Find("GraphCanvas")?.GetComponent<RectTransform>();
if (graphCanvasRect != null)
{
conduitGraphic = graphCanvasRect.GetComponentInChildren<TechTreeConduitGraphic>(true);
}
}
detailCardRoot = (overlay.Find("TechTreeDetailCard") ?? overlay.Find("DetailInspectorCard")) as RectTransform;
if (detailCardRoot != null)
{
detailTrackBanner = detailCardRoot.Find("TrackBanner")?.GetComponent<Image>();
detailCategoryBadge = detailCardRoot.Find("TrackBanner/CategoryBadge")?.GetComponent<Text>()
?? detailCardRoot.Find("CategoryBadge")?.GetComponent<Text>();
detailIconBg = detailCardRoot.Find("DetailIconBg")?.GetComponent<Image>();
detailIcon = detailCardRoot.Find("DetailIconBg/DetailIcon")?.GetComponent<Image>()
?? detailCardRoot.Find("DetailIcon")?.GetComponent<Image>();
detailTitle = detailCardRoot.Find("DetailTitle")?.GetComponent<Text>()
?? detailCardRoot.Find("Title")?.GetComponent<Text>();
detailRankStatus = detailCardRoot.Find("DetailRank")?.GetComponent<Text>()
?? detailCardRoot.Find("RankStatus")?.GetComponent<Text>();
detailDescription = detailCardRoot.Find("BenefitBox/DetailDesc")?.GetComponent<Text>()
?? detailCardRoot.Find("Description")?.GetComponent<Text>();
detailPrereqHeader = detailCardRoot.Find("PrereqChecklistBox/PrereqHeader")?.GetComponent<Text>()
?? detailCardRoot.Find("PrereqHeader")?.GetComponent<Text>();
detailPrereqChecklist = detailCardRoot.Find("PrereqChecklistBox/PrereqList")?.GetComponent<Text>()
?? detailCardRoot.Find("PrereqChecklist")?.GetComponent<Text>();
detailCostText = detailCardRoot.Find("DetailCost")?.GetComponent<Text>()
?? detailCardRoot.Find("CostText")?.GetComponent<Text>();
Transform buyTrans = detailCardRoot.Find("DetailBuyBtn") ?? detailCardRoot.Find("DetailBuyButton");
if (buyTrans != null)
{
detailBuyButton = buyTrans.GetComponent<Button>();
detailBuyBtnLabel = buyTrans.Find("BtnLabel")?.GetComponent<Text>() ?? buyTrans.Find("Label")?.GetComponent<Text>();
if (detailBuyButton != null)
{
detailBuyButton.onClick.RemoveAllListeners();
detailBuyButton.onClick.AddListener(OnDetailBuyClicked);
}
DwellButton dw = buyTrans.GetComponent<DwellButton>();
if (dw != null) dw.Bind(OnDetailBuyClicked, 0.90f, KeyCode.Space);
}
}
Transform bottomBar = overlay.Find("BottomLoadoutBar") ?? overlay.Find("BottomActionBar");
if (bottomBar != null)
{
bottomInfoText = bottomBar.Find("LoadoutTitle")?.GetComponent<Text>()
?? bottomBar.Find("InfoText")?.GetComponent<Text>();
Transform actBtn = bottomBar.Find("LaunchWaveBtn") ?? bottomBar.Find("LaunchNewRunBtn") ?? bottomBar.Find("CloseBtnBottom");
if (actBtn != null)
{
bottomActionBtn = actBtn.GetComponent<Button>();
bottomActionBtnLabel = actBtn.Find("BtnLabel")?.GetComponent<Text>() ?? actBtn.Find("Label")?.GetComponent<Text>();
if (bottomActionBtn != null)
{
bottomActionBtn.onClick.RemoveAllListeners();
bottomActionBtn.onClick.AddListener(OnBottomActionClicked);
}
DwellButton dw = actBtn.GetComponent<DwellButton>();
if (dw != null) dw.Bind(OnBottomActionClicked, 0.90f, KeyCode.Space);
}
}
overlayRoot.SetActive(false);
RebuildSocketsFromDefinition();
}
private void BuildHeaderBar(RectTransform overlay)
{
// Title matching live Main.unity TechTreeModal
hud.CreateTextElement(
overlay,
"TreeTitle",
"LEGACY MASTERY MATRIX // PERMANENT ROGUE-LITE PROGRESSION",
22,
TextAnchor.MiddleLeft,
new Vector2(0.018f, 0.935f),
new Vector2(0.48f, 0.99f),
new Color(0.38f, 0.95f, 1f));
// Header Points Row (Matching HeaderResourcesBadgeRow in Main.unity)
RectTransform pointsPanel = hud.CreatePanelElement(
overlay,
"HeaderResourcesBadgeRow",
new Vector2(0.48f, 0.932f),
new Vector2(0.925f, 0.992f),
new Color(0.45323068f, 0.59534246f, 0.9150943f, 0.75f));
CreateHeaderBadge(pointsPanel, "HeaderAvailableBadge",
hud.metaTreeIconSprite != null ? hud.metaTreeIconSprite : (hud.roundSlotGoldSprite != null ? hud.roundSlotGoldSprite : hud.goldIconSprite),
new Vector2(0.02f, 0.08f), new Vector2(0.48f, 0.92f),
new Color(1f, 0.88f, 0.35f), out headerPointsAvailableText);
CreateHeaderBadge(pointsPanel, "HeaderTotalBadge",
hud.metaTreeIconSprite != null ? hud.metaTreeIconSprite : (hud.roundSlotCyanSprite != null ? hud.roundSlotCyanSprite : hud.scrapIconSprite),
new Vector2(0.52f, 0.08f), new Vector2(0.98f, 0.92f),
new Color(0.45f, 1f, 0.65f), out headerPointsTotalText);
// Close Button Top Right matching Main.unity CloseTreeBtn
hud.CreateButtonElement(
overlay,
"CloseTreeBtn",
"[ X ]",
new Vector2(0.935f, 0.935f),
new Vector2(0.985f, 0.99f),
hud.buttonOrangeSprite,
new Color(0.72f, 0.22f, 0.22f),
CloseModal,
out _,
16,
KeyCode.Escape);
}
private void CreateHeaderBadge(Transform parent, string name, Sprite icon, Vector2 anchorMin, Vector2 anchorMax, Color textColor, out Text countLabel)
{
GameObject badgeGo = new GameObject(name, typeof(RectTransform));
badgeGo.transform.SetParent(parent, false);
RectTransform rt = badgeGo.GetComponent<RectTransform>();
rt.anchorMin = anchorMin;
rt.anchorMax = anchorMax;
rt.offsetMin = Vector2.zero;
rt.offsetMax = Vector2.zero;
GameObject iconGo = new GameObject("Icon", typeof(RectTransform), typeof(Image));
iconGo.transform.SetParent(badgeGo.transform, false);
RectTransform iRt = iconGo.GetComponent<RectTransform>();
iRt.anchorMin = new Vector2(0.02f, 0.06f);
iRt.anchorMax = new Vector2(0.24f, 0.94f);
iRt.offsetMin = Vector2.zero;
iRt.offsetMax = Vector2.zero;
Image img = iconGo.GetComponent<Image>();
img.sprite = icon != null ? icon : ShockwaveExplosionController.GetFallbackGlowSprite();
img.preserveAspect = true;
img.color = Color.white;
img.raycastTarget = false;
countLabel = hud.CreateTextElement(
badgeGo.transform,
"Count",
"0",
16,
TextAnchor.MiddleLeft,
new Vector2(0.28f, 0f),
new Vector2(0.98f, 1f),
textColor);
}
private void BuildSubBarAndLegend(RectTransform overlay)
{
// SubBar matching Main.unity SubBar styling
RectTransform subBar = hud.CreatePanelElement(
overlay,
"SubBar",
new Vector2(0.015f, 0.855f),
new Vector2(0.985f, 0.925f),
theme.subHeaderSurfaceColor);
metaStatusText = hud.CreateTextElement(
subBar,
"StationStatus",
"PERMANENT SPECIALIZATIONS ACTIVE",
14,
TextAnchor.MiddleLeft,
new Vector2(0.015f, 0.08f),
new Vector2(0.30f, 0.92f),
new Color(0.10f, 0.25f, 0.45f));
resetDistributionBtn = hud.CreateButtonElement(
subBar,
"QuickRepairBtn",
"RESET DISTRIBUTION [R]",
new Vector2(0.31f, 0.12f),
new Vector2(0.52f, 0.88f),
hud.buttonOrangeSprite != null ? hud.buttonOrangeSprite : hud.buttonBlueSprite,
new Color(0.68f, 0.32f, 0.18f),
OnResetDistributionClicked,
out resetBtnLabel,
12,
KeyCode.R);
instantBuyBtn = hud.CreateButtonElement(
subBar,
"InstantBuyBtn",
"<color=#55FF77>[✓] INSTANT ALLOCATE</color>",
new Vector2(0.53f, 0.12f),
new Vector2(0.68f, 0.88f),
hud.buttonBlueSprite,
new Color(0.14f, 0.30f, 0.48f),
ToggleInstantBuy,
out instantBuyToggleLabel,
12);
hud.CreateTextElement(
subBar,
"TrackLegend",
"<color=#007799>■ DEFENSE</color> <color=#995500>■ ORDNANCE</color> <color=#770099>■ CITADEL</color> <color=#007733>■ LOGISTICS</color>",
12,
TextAnchor.MiddleRight,
new Vector2(0.69f, 0.08f),
new Vector2(0.988f, 0.92f),
new Color(0.12f, 0.20f, 0.35f));
}
private void BuildConstellationGraphArea(RectTransform overlay)
{
// Constellation Graph Container matching Main.unity
RectTransform graphContainer = hud.CreatePanelElement(
overlay,
"ConstellationGraphContainer",
new Vector2(0.015f, 0.165f),
new Vector2(0.675f, 0.845f),
new Color(0.27687788f, 0.2915035f, 0.3207547f, 0.94f));
// Tier Column Header Bar
RectTransform tierHeaderBar = hud.CreatePanelElement(
graphContainer,
"TierColumnHeaderBar",
new Vector2(0f, 0.92f),
new Vector2(1f, 1f),
new Color(0.02f, 0.05f, 0.11f, 0.85f));
string[] tierTitles =
{
"CORE ROOT",
"TIER I: EXPEDITION",
"TIER II: FORTIFICATION",
"TIER III: SYSTEMS",
"TIER IV: APEX"
};
float[] tierXCenters = { 0.08f, 0.28f, 0.55f, 0.72f, 0.88f };
for (int i = 0; i < tierTitles.Length; i++)
{
float cx = tierXCenters[i];
hud.CreateTextElement(
tierHeaderBar,
$"TierColHeader_{i}",
tierTitles[i],
11,
TextAnchor.MiddleCenter,
new Vector2(Mathf.Max(0.005f, cx - 0.085f), 0.05f),
new Vector2(Mathf.Min(0.995f, cx + 0.085f), 0.95f),
i == 0 ? new Color(0.45f, 0.95f, 1f, 0.95f) : new Color(0.65f, 0.82f, 0.98f, 0.85f));
}
// Graph Inner Canvas
GameObject innerGo = new GameObject("GraphInnerCanvas", typeof(RectTransform));
innerGo.transform.SetParent(graphContainer, false);
graphCanvasRect = innerGo.GetComponent<RectTransform>();
graphCanvasRect.anchorMin = new Vector2(0.01f, 0.02f);
graphCanvasRect.anchorMax = new Vector2(0.99f, 0.91f);
graphCanvasRect.offsetMin = Vector2.zero;
graphCanvasRect.offsetMax = Vector2.zero;
// Track Lane Watermarks
CreateTrackLaneWatermark(graphCanvasRect, "DEFENSE", 0.84f, theme.defenseTrackColor);
CreateTrackLaneWatermark(graphCanvasRect, "ORDNANCE", 0.62f, theme.ordnanceTrackColor);
CreateTrackLaneWatermark(graphCanvasRect, "CITADEL", 0.38f, theme.citadelTrackColor);
CreateTrackLaneWatermark(graphCanvasRect, "LOGISTICS", 0.16f, theme.logisticsTrackColor);
// Conduit Graphic Layer behind sockets
GameObject conduitGo = new GameObject("ConduitGraphicLayer", typeof(RectTransform), typeof(CanvasRenderer), typeof(TechTreeConduitGraphic));
conduitGo.transform.SetParent(graphCanvasRect, false);
RectTransform cRt = conduitGo.GetComponent<RectTransform>();
cRt.anchorMin = Vector2.zero;
cRt.anchorMax = Vector2.one;
cRt.offsetMin = Vector2.zero;
cRt.offsetMax = Vector2.zero;
conduitGraphic = conduitGo.GetComponent<TechTreeConduitGraphic>();
conduitGraphic.raycastTarget = false;
}
private void CreateTrackLaneWatermark(RectTransform parent, string label, float normY, Color trackCol)
{
Color c = new Color(trackCol.r, trackCol.g, trackCol.b, 0.32f);
hud.CreateTextElement(
parent,
$"TrackLabel_{label}",
label,
10,
TextAnchor.MiddleLeft,
new Vector2(0.005f, Mathf.Clamp01(normY - 0.04f)),
new Vector2(0.14f, Mathf.Clamp01(normY + 0.04f)),
c);
}
private void BuildDetailInspectorCard(RectTransform overlay)
{
// TechTreeDetailCard matching Main.unity
detailCardRoot = hud.CreatePanelElement(
overlay,
"TechTreeDetailCard",
new Vector2(0.685f, 0.165f),
new Vector2(0.985f, 0.845f),
theme.cardSurfaceColor);
RectTransform bannerRt = hud.CreatePanelElement(
detailCardRoot,
"TrackBanner",
new Vector2(0f, 0.91f),
new Vector2(1f, 1f),
new Color(0.10f, 0.24f, 0.42f, 0.95f));
detailTrackBanner = bannerRt.GetComponent<Image>();
detailCategoryBadge = hud.CreateTextElement(
bannerRt,
"CategoryBadge",
"★ ROGUE-LITE MASTERY ★",
13,
TextAnchor.MiddleCenter,
new Vector2(0.04f, 0.05f),
new Vector2(0.96f, 0.95f),
new Color(1f, 0.88f, 0.30f));
// Detail Icon Frame (68x68)
GameObject iconBgGo = new GameObject("DetailIconBg", typeof(RectTransform), typeof(Image), typeof(Outline));
iconBgGo.transform.SetParent(detailCardRoot, false);
RectTransform iconBgRt = iconBgGo.GetComponent<RectTransform>();
iconBgRt.anchorMin = new Vector2(0.16f, 0.78f);
iconBgRt.anchorMax = new Vector2(0.16f, 0.78f);
iconBgRt.pivot = new Vector2(0.5f, 0.5f);
iconBgRt.sizeDelta = new Vector2(68f, 68f);
detailIconBg = iconBgGo.GetComponent<Image>();
detailIconBg.sprite = hud.roundSlotGoldSprite != null ? hud.roundSlotGoldSprite : hud.roundSlotCyanSprite;
detailIconBg.color = new Color(0.18f, 0.38f, 0.60f, 0.95f);
iconBgGo.GetComponent<Outline>().effectColor = new Color(0.35f, 0.85f, 1f, 0.75f);
GameObject dIconGo = new GameObject("DetailIcon", typeof(RectTransform), typeof(Image));
dIconGo.transform.SetParent(iconBgGo.transform, false);
RectTransform dIconRt = dIconGo.GetComponent<RectTransform>();
dIconRt.anchorMin = new Vector2(0.16f, 0.16f);
dIconRt.anchorMax = new Vector2(0.84f, 0.84f);
dIconRt.offsetMin = Vector2.zero;
dIconRt.offsetMax = Vector2.zero;
detailIcon = dIconGo.GetComponent<Image>();
detailIcon.preserveAspect = true;
detailIcon.raycastTarget = false;
detailTitle = hud.CreateTextElement(
detailCardRoot,
"DetailTitle",
"SELECT A MASTERY NODE",
18,
TextAnchor.LowerLeft,
new Vector2(0.31f, 0.77f),
new Vector2(0.96f, 0.89f),
new Color(0.45f, 0.96f, 1f));
detailRankStatus = hud.CreateTextElement(
detailCardRoot,
"DetailRank",
"RANK 0 / 1",
14,
TextAnchor.UpperLeft,
new Vector2(0.31f, 0.67f),
new Vector2(0.96f, 0.77f),
new Color(0.80f, 0.92f, 1f));
// Benefit Box
RectTransform descBox = hud.CreatePanelElement(
detailCardRoot,
"BenefitBox",
new Vector2(0.04f, 0.46f),
new Vector2(0.96f, 0.66f),
new Color(0.02f, 0.05f, 0.10f, 0.85f));
detailDescription = hud.CreateTextElement(
descBox,
"DetailDesc",
"Permanent meta-upgrades persist across all subsequent runs.",
14,
TextAnchor.MiddleLeft,
new Vector2(0.04f, 0.04f),
new Vector2(0.96f, 0.96f),
Color.white);
// Prereq Box
RectTransform prereqBox = hud.CreatePanelElement(
detailCardRoot,
"PrereqChecklistBox",
new Vector2(0.04f, 0.22f),
new Vector2(0.96f, 0.44f),
new Color(0.02f, 0.05f, 0.10f, 0.85f));
detailPrereqHeader = hud.CreateTextElement(
prereqBox,
"PrereqHeader",
"PREREQUISITES & REPUTATION",
12,
TextAnchor.MiddleLeft,
new Vector2(0.04f, 0.74f),
new Vector2(0.96f, 0.98f),
new Color(1f, 0.85f, 0.35f));
detailPrereqChecklist = hud.CreateTextElement(
prereqBox,
"PrereqList",
"• None",
13,
TextAnchor.UpperLeft,
new Vector2(0.04f, 0.04f),
new Vector2(0.96f, 0.72f),
new Color(0.82f, 0.90f, 1f));
detailCostText = hud.CreateTextElement(
detailCardRoot,
"DetailCost",
"COST: 1 MASTERY POINT",
15,
TextAnchor.MiddleLeft,
new Vector2(0.04f, 0.06f),
new Vector2(0.48f, 0.18f),
new Color(1f, 0.88f, 0.35f));
detailBuyButton = hud.CreateButtonElement(
detailCardRoot,
"DetailBuyBtn",
"ALLOCATE [SPACE]",
new Vector2(0.50f, 0.04f),
new Vector2(0.96f, 0.18f),
hud.buttonGreenSprite != null ? hud.buttonGreenSprite : hud.buttonBlueSprite,
new Color(0.15f, 0.65f, 0.35f),
OnDetailBuyClicked,
out detailBuyBtnLabel,
16,
KeyCode.Space);
}
private void BuildBottomBar(RectTransform overlay)
{
// BottomLoadoutBar matching Main.unity
RectTransform bottomBar = hud.CreatePanelElement(
overlay,
"BottomLoadoutBar",
new Vector2(0.015f, 0.015f),
new Vector2(0.985f, 0.15f),
new Color(0.4693396f, 0.48077232f, 0.5f, 0.95f));
bottomInfoText = hud.CreateTextElement(
bottomBar,
"LoadoutTitle",
"Mastery upgrades are permanent rogue-lite enhancements that persist across all runs.\nFirst-time wave completions bank Mastery Points. Distribute up to 30 points to fully max out the tree.",
14,
TextAnchor.MiddleLeft,
new Vector2(0.02f, 0.10f),
new Vector2(0.68f, 0.90f),
Color.white);
bottomActionBtn = hud.CreateButtonElement(
bottomBar,
"LaunchWaveBtn",
"CLOSE & RESUME [ESC]",
new Vector2(0.725f, 0.12f),
new Vector2(0.988f, 0.88f),
hud.buttonGreenSprite,
new Color(0.15f, 0.68f, 0.38f),
OnBottomActionClicked,
out bottomActionBtnLabel,
17,
KeyCode.Escape);
}
public void OpenModal()
{
if (overlayRoot == null) return;
overlayRoot.SetActive(true);
Refresh();
}
public void CloseModal()
{
if (overlayRoot == null) return;
overlayRoot.SetActive(false);
DwellButton.ResetAllDwellState();
if (GazeLabGameManager.Instance != null && GazeLabGameManager.Instance.CurrentState != GameFlowState.GameOver)
{
GazeLabGameManager.Instance.ResumeGameSession();
}
}
public void ToggleModal()
{
if (IsOpen) CloseModal();
else OpenModal();
}
private void OnBottomActionClicked()
{
if (GazeLabGameManager.Instance != null && GazeLabGameManager.Instance.CurrentState == GameFlowState.GameOver)
{
CloseModal();
GazeLabGameManager.Instance.StartNewGameSession();
}
else
{
CloseModal();
}
}
public void Refresh()
{
if (overlayRoot == null || !overlayRoot.activeSelf) return;
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta == null) return;
if (headerPointsAvailableText != null)
headerPointsAvailableText.text = $"{meta.AvailablePoints} PTS AVAILABLE";
if (headerPointsTotalText != null)
headerPointsTotalText.text = $"{meta.TotalEarnedPoints} / {MetaProgressionManager.MAX_MASTERY_POINTS} BANKED";
if (metaStatusText != null)
{
MetaRunBonuses b = meta.GetActiveRunBonuses();
metaStatusText.text = $"BONUSES: Scrap +{b.startingScrap} | G/U +{b.startingGold}/{b.startingUranium} | Hull +{Mathf.RoundToInt((b.baseHullMultiplier - 1f) * 100f)}% | Dmg +{Mathf.RoundToInt((b.baseDamageMultiplier - 1f) * 100f)}% | Harpoon: {(b.unlockHarpoonAtStart ? "<color=#55FF77>ON</color>" : "OFF")}";
}
if (bottomActionBtnLabel != null)
{
bool isGameOver = GazeLabGameManager.Instance != null && GazeLabGameManager.Instance.CurrentState == GameFlowState.GameOver;
bottomActionBtnLabel.text = isGameOver ? "START NEW EXPEDITION [SPACE]" : "CLOSE & RESUME [ESC]";
}
// Ensure sockets exist
if (nodeSockets.Count == 0 && meta.TreeDefinition != null)
{
RebuildSocketsFromDefinition();
}
// Default select root node if none selected
if (currentlySelectedNode == null && meta.TreeDefinition != null && meta.TreeDefinition.allNodes != null && meta.TreeDefinition.allNodes.Length > 0)
{
currentlySelectedNode = meta.TreeDefinition.allNodes[0];
}
UpdateSocketsVisuals();
UpdateConduitGraphic();
UpdateDetailCard();
}
public void UpdatePulseAnimations()
{
if (!IsOpen) return;
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta == null) return;
float ping = Mathf.PingPong(Time.unscaledTime * 2.6f, 1f);
Color pulseCol = Color.Lerp(new Color(0.28f, 0.88f, 1f, 0.55f), new Color(1f, 0.88f, 0.25f, 0.98f), ping);
for (int i = 0; i < nodeSockets.Count; i++)
{
MetaNodeSocketWidget w = nodeSockets[i];
if (w == null || w.boundNode == null || w.rootGo == null || !w.rootGo.activeSelf) continue;
bool isSelected = w.boundNode == currentlySelectedNode;
bool canAfford = meta.CanPurchaseNode(w.boundNode, out _);
bool prereqMet = meta.ArePrerequisitesMet(w.boundNode, out _);
if (canAfford)
{
w.outline.effectColor = pulseCol;
}
else if (isSelected)
{
if (prereqMet)
{
// Unlocked but unaffordable: maintain distinct red highlight
w.outline.effectColor = new Color(1f, 0.25f, 0.25f, 0.95f);
}
else
{
w.outline.effectColor = new Color(0.35f, 0.95f, 1f, 0.90f);
}
}
}
}
public void RebuildSocketsFromDefinition()
{
if (graphCanvasRect == null) return;
MetaTreeDefinitionSO def = null;
if (MetaProgressionManager.Instance != null && MetaProgressionManager.Instance.TreeDefinition != null)
{
def = MetaProgressionManager.Instance.TreeDefinition;
}
#if UNITY_EDITOR
if (def == null)
{
def = UnityEditor.AssetDatabase.LoadAssetAtPath<MetaTreeDefinitionSO>("Assets/GazeLab/ScriptableObjects/MetaUpgrades/MetaTreeDefinition.asset");
}
#endif
if (def == null || def.allNodes == null) return;
// Map existing sockets in graphCanvasRect so scene-placed objects are preserved
var existingSockets = new Dictionary<string, GameObject>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < graphCanvasRect.childCount; i++)
{
Transform child = graphCanvasRect.GetChild(i);
if (child.name == "ConduitGraphicLayer" || child.name.StartsWith("TrackLabel_")) continue;
existingSockets[child.name] = child.gameObject;
}
nodeSockets.Clear();
for (int i = 0; i < def.allNodes.Length; i++)
{
MetaUpgradeNodeSO node = def.allNodes[i];
if (node == null) continue;
string key1 = $"MetaSocket_{node.nodeId}";
string key2 = $"Socket_{node.nodeId}";
string key3 = node.nodeId;
GameObject existingGo = null;
if (existingSockets.TryGetValue(key1, out GameObject go1)) existingGo = go1;
else if (existingSockets.TryGetValue(key2, out GameObject go2)) existingGo = go2;
else if (existingSockets.TryGetValue(key3, out GameObject go3)) existingGo = go3;
MetaNodeSocketWidget widget;
if (existingGo != null)
{
widget = BindExistingSocketWidget(existingGo, node);
}
else
{
widget = CreateSocketWidget(node, graphCanvasRect);
}
nodeSockets.Add(widget);
}
}
private MetaNodeSocketWidget BindExistingSocketWidget(GameObject root, MetaUpgradeNodeSO node)
{
RectTransform rt = root.GetComponent<RectTransform>();
Transform glowGo = root.transform.Find("OuterGlow");
Image glowImg = glowGo != null ? glowGo.GetComponent<Image>() : null;
Transform rimGo = root.transform.Find("SocketRim") ?? root.transform;
Image rimImg = rimGo.GetComponent<Image>();
Button btn = rimGo.GetComponent<Button>();
DwellButton dwell = rimGo.GetComponent<DwellButton>();
Outline ol = rimGo.GetComponent<Outline>();
Transform iconGo = rimGo.Find("NodeIcon") ?? root.transform.Find("NodeIcon");
Image iImg = iconGo != null ? iconGo.GetComponent<Image>() : null;
Transform nameGo = root.transform.Find("ShortName");
Text nameTxt = nameGo != null ? nameGo.GetComponent<Text>() : null;
if (nameTxt != null && nameTxt.font == null && font != null) nameTxt.font = font;
Transform rankGo = root.transform.Find("RankBadge");
Text rankTxt = rankGo != null ? rankGo.GetComponent<Text>() : null;
if (rankTxt != null && rankTxt.font == null && font != null) rankTxt.font = font;
Vector2 normPos = node.normalizedGraphPosition;
if (rt != null && rt.anchorMin == rt.anchorMax)
{
normPos = rt.anchorMin;
}
MetaNodeSocketWidget widget = new MetaNodeSocketWidget
{
rootGo = root,
rectTransform = rt,
button = btn,
dwellButton = dwell,
outerGlowImage = glowImg,
socketRimImage = rimImg,
outline = ol,
iconImage = iImg,
shortNameLabel = nameTxt,
rankBadgeText = rankTxt,
boundNode = node,
normalizedPos = normPos
};
if (btn != null)
{
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(() => OnNodeSocketClicked(widget));
}
if (dwell != null)
{
dwell.showDwellBar = false;
dwell.Bind(
onClick: () => OnNodeSocketActivated(widget),
dwellTime: 0.82f,
shortcut: KeyCode.None,
onHover: () => OnNodeSocketHovered(widget));
}
return widget;
}
private MetaNodeSocketWidget CreateSocketWidget(MetaUpgradeNodeSO node, RectTransform parent)
{
GameObject root = new GameObject($"MetaSocket_{node.nodeId}", typeof(RectTransform));
root.transform.SetParent(parent, false);
RectTransform rt = root.GetComponent<RectTransform>();
Vector2 normPos = node.normalizedGraphPosition;
rt.anchorMin = normPos;
rt.anchorMax = normPos;
rt.pivot = new Vector2(0.5f, 0.5f);
rt.anchoredPosition = Vector2.zero;
// Outer glow halo
GameObject glowGo = new GameObject("OuterGlow", typeof(RectTransform), typeof(Image));
glowGo.transform.SetParent(root.transform, false);
RectTransform gRt = glowGo.GetComponent<RectTransform>();
gRt.anchorMin = new Vector2(-0.18f, -0.18f);
gRt.anchorMax = new Vector2(1.18f, 1.18f);
gRt.offsetMin = Vector2.zero;
gRt.offsetMax = Vector2.zero;
Image glowImg = glowGo.GetComponent<Image>();
glowImg.sprite = hud.roundSlotGoldSprite != null ? hud.roundSlotGoldSprite : hud.roundSlotCyanSprite;
glowImg.color = Color.clear;
glowImg.raycastTarget = false;
// Socket Rim
GameObject rimGo = new GameObject("SocketRim", typeof(RectTransform), typeof(Image), typeof(Button), typeof(DwellButton), typeof(Outline));
rimGo.transform.SetParent(root.transform, false);
RectTransform rRt = rimGo.GetComponent<RectTransform>();
rRt.anchorMin = Vector2.zero;
rRt.anchorMax = Vector2.one;
rRt.offsetMin = Vector2.zero;
rRt.offsetMax = Vector2.zero;
Image rimImg = rimGo.GetComponent<Image>();
Sprite containerSprite = hud.GetMetaNodeContainerSprite(node, out Vector2 socketSize);
rimImg.sprite = containerSprite;
rimImg.preserveAspect = true;
rimImg.color = Color.white;
rt.sizeDelta = socketSize;
Outline ol = rimGo.GetComponent<Outline>();
ol.effectColor = new Color(0.22f, 0.65f, 0.95f, 0.50f);
ol.effectDistance = socketSize.x > 60f ? new Vector2(2.5f, -2.5f) : (socketSize.x > 50f ? new Vector2(2f, -2f) : new Vector2(1.5f, -1.5f));
// Inner Icon
GameObject iconGo = new GameObject("NodeIcon", typeof(RectTransform), typeof(Image));
iconGo.transform.SetParent(rimGo.transform, false);
RectTransform iRt = iconGo.GetComponent<RectTransform>();
iRt.anchorMin = new Vector2(0.18f, 0.18f);
iRt.anchorMax = new Vector2(0.82f, 0.82f);
iRt.offsetMin = Vector2.zero;
iRt.offsetMax = Vector2.zero;
Image iImg = iconGo.GetComponent<Image>();
iImg.sprite = node.icon != null ? node.icon : (hud.metaTreeIconSprite != null ? hud.metaTreeIconSprite : hud.roundSlotGoldSprite);
iImg.preserveAspect = true;
iImg.raycastTarget = false;
// Short Name Label Above Socket (Font 10 Bold)
Text nameTxt = hud.CreateTextElement(
root.transform,
"ShortName",
node.shortName,
10,
TextAnchor.LowerCenter,
new Vector2(-0.95f, 0.96f),
new Vector2(1.95f, 1.48f),
new Color(0.82f, 0.92f, 1f, 0.92f));
// Rank Badge Below/Inside Socket (Font 10 Bold)
Text rankTxt = hud.CreateTextElement(
root.transform,
"RankBadge",
"0/1",
10,
TextAnchor.UpperCenter,
new Vector2(-0.50f, -0.42f),
new Vector2(1.50f, -0.02f),
new Color(1f, 0.88f, 0.35f));
Button btn = rimGo.GetComponent<Button>();
btn.targetGraphic = rimImg;
DwellButton dwell = rimGo.GetComponent<DwellButton>();
MetaNodeSocketWidget widget = new MetaNodeSocketWidget
{
rootGo = root,
rectTransform = rt,
button = btn,
dwellButton = dwell,
outerGlowImage = glowImg,
socketRimImage = rimImg,
outline = ol,
iconImage = iImg,
shortNameLabel = nameTxt,
rankBadgeText = rankTxt,
boundNode = node,
normalizedPos = normPos
};
btn.onClick.AddListener(() => OnNodeSocketClicked(widget));
dwell.showDwellBar = false;
dwell.Bind(
onClick: () => OnNodeSocketActivated(widget),
dwellTime: 0.82f,
shortcut: KeyCode.None,
onHover: () => OnNodeSocketHovered(widget));
return widget;
}
private void OnNodeSocketHovered(MetaNodeSocketWidget widget)
{
if (widget == null || widget.boundNode == null) return;
currentlyHoveredNode = widget.boundNode;
currentlySelectedNode = widget.boundNode;
Refresh();
}
private void OnNodeSocketActivated(MetaNodeSocketWidget widget)
{
if (widget == null || widget.boundNode == null) return;
currentlySelectedNode = widget.boundNode;
if (instantBuyEnabled)
{
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta != null && meta.CanPurchaseNode(widget.boundNode, out _))
{
meta.TryPurchaseNode(widget.boundNode, out _);
if (SpaceAudioController.Instance != null)
SpaceAudioController.Instance.PlayUpgrade();
}
}
Refresh();
}
private void OnNodeSocketClicked(MetaNodeSocketWidget widget)
{
if (widget == null || widget.boundNode == null) return;
currentlySelectedNode = widget.boundNode;
if (instantBuyEnabled)
{
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta != null && meta.CanPurchaseNode(widget.boundNode, out _))
{
meta.TryPurchaseNode(widget.boundNode, out _);
if (SpaceAudioController.Instance != null)
SpaceAudioController.Instance.PlayUpgrade();
}
}
Refresh();
}
private void OnDetailBuyClicked()
{
if (currentlySelectedNode == null) return;
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta != null && meta.TryPurchaseNode(currentlySelectedNode, out string failReason))
{
if (SpaceAudioController.Instance != null)
SpaceAudioController.Instance.PlayUpgrade();
Refresh();
}
else
{
if (SpaceAudioController.Instance != null)
SpaceAudioController.Instance.PlayClick();
}
}
private void OnResetDistributionClicked()
{
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta != null)
{
meta.ResetDistribution();
if (SpaceAudioController.Instance != null)
SpaceAudioController.Instance.PlayWaveClear();
Refresh();
}
}
private void ToggleInstantBuy()
{
instantBuyEnabled = !instantBuyEnabled;
if (instantBuyToggleLabel != null)
{
instantBuyToggleLabel.text = instantBuyEnabled
? "<color=#55FF77>[✓] INSTANT ALLOCATE</color>"
: "[ ] INSTANT ALLOCATE";
}
}
private void UpdateSocketsVisuals()
{
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta == null) return;
for (int i = 0; i < nodeSockets.Count; i++)
{
MetaNodeSocketWidget w = nodeSockets[i];
if (w == null || w.boundNode == null) continue;
int curRank = meta.GetNodeRank(w.boundNode.nodeId);
int maxRank = w.boundNode.maxRank;
bool isMax = curRank >= maxRank;
bool prereqMet = meta.ArePrerequisitesMet(w.boundNode, out _);
bool canAfford = meta.CanPurchaseNode(w.boundNode, out _);
bool isSelected = w.boundNode == currentlySelectedNode;
if (isMax)
{
w.dwellButton.isDwellEnabled = false;
w.button.interactable = true;
w.socketRimImage.color = new Color(0.35f, 1f, 0.65f, 0.95f);
w.iconImage.color = Color.white;
w.outerGlowImage.color = isSelected ? new Color(0.35f, 1f, 0.65f, 0.50f) : Color.clear;
w.shortNameLabel.color = new Color(0.35f, 0.95f, 1f);
w.outline.effectColor = new Color(0.25f, 0.85f, 0.45f, 0.85f);
w.rankBadgeText.text = $"<color=#55FF77>{curRank}/{maxRank} ✓</color>";
}
else if (!prereqMet)
{
// Locked behind prerequisites
w.dwellButton.isDwellEnabled = false;
w.button.interactable = true; // still allow clicking/hovering to inspect
w.socketRimImage.color = new Color(0.35f, 0.40f, 0.50f, 0.45f);
w.iconImage.color = new Color(0.30f, 0.35f, 0.45f, 0.40f);
w.outerGlowImage.color = Color.clear;
w.shortNameLabel.color = new Color(0.40f, 0.45f, 0.55f, 0.60f);
w.outline.effectColor = new Color(0.12f, 0.30f, 0.50f, 0.35f);
w.rankBadgeText.text = $"<color=#667788>{curRank}/{maxRank}</color>";
}
else if (canAfford)
{
// Unlocked and affordable: allow gaze dwell fill and normal colors
w.dwellButton.isDwellEnabled = true;
w.button.interactable = true;
w.socketRimImage.color = new Color(1f, 0.88f, 0.35f, 1f);
w.iconImage.color = Color.white;
w.outerGlowImage.color = new Color(1f, 0.85f, 0.25f, 0.40f);
w.shortNameLabel.color = new Color(1f, 0.85f, 0.25f);
w.outline.effectColor = new Color(1f, 0.92f, 0.40f, 0.95f);
w.rankBadgeText.text = maxRank > 1
? $"<color=#55FF77>{curRank}/{maxRank} ▲</color>"
: "<color=#FFE066>READY</color>";
}
else
{
// Unlocked / prerequisites met, but NOT enough mastery points for next rank:
// 1. Disable cursor fill indicator (so dwelling does not misleadingly charge)
w.dwellButton.isDwellEnabled = false;
w.button.interactable = true; // still allow inspecting
// 2. Tint the whole circular icon, rim, and outline red
w.socketRimImage.color = new Color(0.75f, 0.15f, 0.18f, 0.95f);
w.iconImage.color = new Color(1f, 0.45f, 0.45f, 0.90f);
w.outerGlowImage.color = Color.clear;
w.outline.effectColor = new Color(0.92f, 0.18f, 0.18f, 0.85f);
w.shortNameLabel.color = new Color(1f, 0.55f, 0.55f);
w.rankBadgeText.text = $"<color=#FF7777>{curRank}/{maxRank}</color>";
}
if (isSelected)
{
if (canAfford)
{
w.outline.effectColor = new Color(0.35f, 0.95f, 1f, 0.90f);
}
else if (!prereqMet || isMax)
{
w.outline.effectColor = new Color(0.35f, 0.95f, 1f, 0.70f);
}
else
{
// Distinct red outline when selected and unaffordable
w.outline.effectColor = new Color(1f, 0.25f, 0.25f, 0.95f);
}
w.outline.effectDistance = new Vector2(2.5f, -2.5f);
}
else
{
w.outline.effectDistance = new Vector2(1.5f, -1.5f);
}
}
}
private void UpdateConduitGraphic()
{
if (conduitGraphic == null) return;
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta == null || meta.TreeDefinition == null) return;
conduitEdgesBuffer.Clear();
for (int i = 0; i < nodeSockets.Count; i++)
{
MetaNodeSocketWidget childW = nodeSockets[i];
if (childW.boundNode == null || childW.boundNode.prerequisites == null) continue;
for (int p = 0; p < childW.boundNode.prerequisites.Length; p++)
{
var req = childW.boundNode.prerequisites[p];
if (req.parentNode == null) continue;
MetaNodeSocketWidget parentW = nodeSockets.Find(w => w.boundNode == req.parentNode);
if (parentW == null) continue;
int parentRank = meta.GetNodeRank(req.parentNode.nodeId);
int childRank = meta.GetNodeRank(childW.boundNode.nodeId);
bool reqSatisfied = parentRank >= Mathf.Max(1, req.minRequiredRank);
ConduitVisualState state = ConduitVisualState.Locked;
if (childRank > 0) state = ConduitVisualState.Purchased;
else if (reqSatisfied) state = ConduitVisualState.Unlockable;
Vector2 startPos = (parentW.rectTransform != null && parentW.rectTransform.anchorMin == parentW.rectTransform.anchorMax)
? parentW.rectTransform.anchorMin
: parentW.normalizedPos;
Vector2 endPos = (childW.rectTransform != null && childW.rectTransform.anchorMin == childW.rectTransform.anchorMax)
? childW.rectTransform.anchorMin
: childW.normalizedPos;
conduitEdgesBuffer.Add(new ConduitEdgeData
{
startNormalized = startPos,
endNormalized = endPos,
state = state,
trackAccentColor = GetTrackAccentColor(childW.boundNode.branchTrack)
});
}
}
conduitGraphic.SetEdges(conduitEdgesBuffer);
}
private Color GetTrackAccentColor(TechBranchTrack track)
{
switch (track)
{
case TechBranchTrack.Defense: return new Color(0.20f, 0.65f, 1f);
case TechBranchTrack.Ordnance: return new Color(1f, 0.40f, 0.25f);
case TechBranchTrack.CitadelCommand: return new Color(0.85f, 0.35f, 1f);
case TechBranchTrack.Logistics: return new Color(0.30f, 0.95f, 0.55f);
default: return new Color(1f, 0.85f, 0.30f);
}
}
private void UpdateDetailCard()
{
if (detailCardRoot == null) return;
MetaProgressionManager meta = MetaProgressionManager.Instance;
if (meta == null) return;
MetaUpgradeNodeSO node = currentlySelectedNode;
if (node == null)
{
detailTitle.text = "SELECT A MASTERY NODE";
detailRankStatus.text = "";
detailDescription.text = "Choose a specialization node to inspect its persistent Rogue-Lite bonuses.";
detailPrereqChecklist.text = "";
detailCostText.text = "";
if (detailBuyButton != null) detailBuyButton.interactable = false;
return;
}
int curRank = meta.GetNodeRank(node.nodeId);
int maxRank = node.maxRank;
bool isMax = curRank >= maxRank;
detailCategoryBadge.text = $"★ {node.branchTrack.ToString().ToUpper()} TRACK // TIER {node.treeTier} ★";
detailTrackBanner.color = GetTrackAccentColor(node.branchTrack);
detailIconBg.sprite = hud.GetMetaNodeContainerSprite(node, out _);
detailIcon.sprite = node.icon != null ? node.icon : (hud.metaTreeIconSprite != null ? hud.metaTreeIconSprite : hud.roundSlotGoldSprite);
detailTitle.text = node.displayName.ToUpper();
detailRankStatus.text = isMax ? $"<color=#55FF77>RANK {curRank} / {maxRank} [MAXIMUM RANK]</color>" : $"RANK {curRank} / {maxRank} <color=#FFE066>(Next: Rank {curRank + 1})</color>";
detailDescription.text = $"{node.description}\n\n<color=#55FF77>Next Rank Effect:</color>\n{node.GetEffectDescriptionForRank(curRank + 1)}";
// Prerequisites
if (node.prerequisites != null && node.prerequisites.Length > 0)
{
string checklist = "";
for (int i = 0; i < node.prerequisites.Length; i++)
{
var req = node.prerequisites[i];
if (req.parentNode == null) continue;
int rk = meta.GetNodeRank(req.parentNode.nodeId);
int needed = Mathf.Max(1, req.minRequiredRank);
bool ok = rk >= needed;
checklist += $"{(ok ? "<color=#55FF77>✓" : "<color=#FF5555>✗")} {req.parentNode.displayName} (Rank {rk}/{needed})</color>\n";
}
detailPrereqChecklist.text = checklist;
}
else
{
detailPrereqChecklist.text = "<color=#55FF77>• Root Node (No prerequisites)</color>";
}
// Cost & Buy Button
if (isMax)
{
detailCostText.text = "<color=#55FF77>MAX RANK REACHED</color>";
if (detailBuyBtnLabel != null) detailBuyBtnLabel.text = "MAX RANK REACHED";
if (detailBuyButton != null)
{
detailBuyButton.interactable = false;
detailBuyButton.GetComponent<Image>().color = new Color(0.12f, 0.26f, 0.18f, 0.75f);
}
}
else
{
int cost = node.pointCostPerRank;
bool canAfford = meta.CanPurchaseNode(node, out string reason);
detailCostText.text = $"COST: {cost} MASTERY POINT{(cost > 1 ? "S" : "")} (AVAILABLE: {meta.AvailablePoints})";
if (canAfford)
{
if (detailBuyBtnLabel != null) detailBuyBtnLabel.text = $"ALLOCATE POINT ({cost} PT)";
if (detailBuyButton != null)
{
detailBuyButton.interactable = true;
detailBuyButton.GetComponent<Image>().color = new Color(0.16f, 0.68f, 0.38f);
}
}
else
{
if (detailBuyBtnLabel != null) detailBuyBtnLabel.text = string.IsNullOrEmpty(reason) ? "INSUFFICIENT MASTERY POINTS" : reason.ToUpper();
if (detailBuyButton != null)
{
detailBuyButton.interactable = false;
detailBuyButton.GetComponent<Image>().color = new Color(0.20f, 0.22f, 0.28f, 0.70f);
}
}
}
}
}
}