using System.Linq; using Data; using Managers; using TMPro; using UnityEngine; using UnityEngine.UI; namespace UI { public class SkillTreeNodeInformationUI : MonoBehaviour { public TMP_Text label; public TMP_Text description; public TMP_Text coin; public Button purchaseButton; public SkillTreeNodeUI currentLink; public SkillTreeDef SkillTreeDef => currentLink.SkillTreeDefine; 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)); } } public void Init(SkillTreeNodeUI nodeUI) { currentLink = nodeUI; 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; } } public void Purchase() { if(SkillTreeDef.cost <= Program.Instance.CoinCount) { SkillTreeManager.Instance.UnlockSkillTree(SkillTreeDef.defName); Program.Instance.CoinCount -= SkillTreeDef.cost; } OnHide(); currentLink.Refresh(); } public void OnHide() { gameObject.SetActive(false); } } }