2025-10-03 00:31:34 +08:00
|
|
|
using System.Linq;
|
|
|
|
|
using Data;
|
|
|
|
|
using Managers;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace UI
|
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
public class SkillTreeNodeInformationUI : MonoBehaviour
|
2025-10-03 00:31:34 +08:00
|
|
|
{
|
|
|
|
|
public TMP_Text label;
|
|
|
|
|
public TMP_Text description;
|
|
|
|
|
public TMP_Text coin;
|
|
|
|
|
public Button purchaseButton;
|
2025-10-10 14:08:23 +08:00
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
public SkillTreeNodeUI currentLink;
|
|
|
|
|
public SkillTreeDef SkillTreeDef => currentLink.SkillTreeDefine;
|
2025-10-10 14:08:23 +08:00
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
public bool CanUnlock
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (SkillTreeDef.cost > Program.Instance.CoinCount)
|
|
|
|
|
return false;
|
|
|
|
|
var parent = SkillTreeManager.Instance.GetAllDirectParents(SkillTreeDef);
|
|
|
|
|
return parent.All(p => SkillTreeManager.Instance.IsSkillTreeUnlocked(p.defName));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-10 14:08:23 +08:00
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
public void Init(SkillTreeNodeUI nodeUI)
|
|
|
|
|
{
|
|
|
|
|
currentLink = nodeUI;
|
2025-10-10 14:08:23 +08:00
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
label.text = SkillTreeDef.label;
|
|
|
|
|
description.text = SkillTreeDef.description;
|
|
|
|
|
coin.text = $"{SkillTreeDef.cost}/{Program.Instance.CoinCount}";
|
|
|
|
|
if (CanUnlock)
|
|
|
|
|
{
|
|
|
|
|
coin.color = Color.white;
|
|
|
|
|
purchaseButton.interactable = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
coin.color = Color.red;
|
|
|
|
|
purchaseButton.interactable = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-10 14:08:23 +08:00
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
public void Purchase()
|
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
if(SkillTreeDef.cost <= Program.Instance.CoinCount)
|
|
|
|
|
{
|
|
|
|
|
SkillTreeManager.Instance.UnlockSkillTree(SkillTreeDef.defName);
|
|
|
|
|
Program.Instance.CoinCount -= SkillTreeDef.cost;
|
|
|
|
|
}
|
2025-10-03 00:31:34 +08:00
|
|
|
OnHide();
|
|
|
|
|
currentLink.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnHide()
|
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
gameObject.SetActive(false);
|
2025-10-03 00:31:34 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|