mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-19 23:37:13 +08:00
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
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);
|
|
}
|
|
}
|
|
} |