first commit
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace OTGIntegrated.Talents
|
||||
{
|
||||
public sealed class TalentNodeUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public Image background;
|
||||
public Text titleText;
|
||||
public Text costText;
|
||||
public Button button;
|
||||
|
||||
private TalentData talent;
|
||||
private TalentManager manager;
|
||||
private TalentTooltipUI tooltip;
|
||||
|
||||
public TalentData Talent => talent;
|
||||
|
||||
public void Initialize(TalentData talent, TalentManager manager, TalentTooltipUI tooltip, Font font)
|
||||
{
|
||||
this.talent = talent;
|
||||
this.manager = manager;
|
||||
this.tooltip = tooltip;
|
||||
|
||||
if (background == null) background = GetComponent<Image>();
|
||||
if (button == null) button = GetComponent<Button>();
|
||||
if (titleText != null)
|
||||
{
|
||||
titleText.font = font != null ? font : Resources.GetBuiltinResource<Font>("Arial.ttf");
|
||||
}
|
||||
|
||||
if (costText != null)
|
||||
{
|
||||
costText.font = font != null ? font : Resources.GetBuiltinResource<Font>("Arial.ttf");
|
||||
}
|
||||
|
||||
if (button != null)
|
||||
{
|
||||
button.onClick.RemoveAllListeners();
|
||||
button.onClick.AddListener(() =>
|
||||
{
|
||||
if (this.manager != null)
|
||||
{
|
||||
this.manager.LearnTalent(this.talent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (talent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (titleText != null)
|
||||
{
|
||||
titleText.text = talent.displayName;
|
||||
}
|
||||
|
||||
if (costText != null)
|
||||
{
|
||||
costText.text = talent.cost.ToString();
|
||||
}
|
||||
|
||||
bool learned = manager != null && manager.IsLearned(talent);
|
||||
bool canLearn = manager != null && manager.CanLearn(talent);
|
||||
bool prereqReady = manager != null && manager.ArePrerequisitesLearned(talent);
|
||||
|
||||
if (background != null)
|
||||
{
|
||||
if (learned)
|
||||
{
|
||||
background.color = new Color(0.86f, 0.68f, 0.22f, 0.96f);
|
||||
}
|
||||
else if (canLearn)
|
||||
{
|
||||
background.color = new Color(0.2f, 0.48f, 0.72f, 0.94f);
|
||||
}
|
||||
else if (prereqReady)
|
||||
{
|
||||
background.color = new Color(0.18f, 0.2f, 0.26f, 0.92f);
|
||||
}
|
||||
else
|
||||
{
|
||||
background.color = new Color(0.09f, 0.1f, 0.12f, 0.88f);
|
||||
}
|
||||
}
|
||||
|
||||
if (button != null)
|
||||
{
|
||||
button.interactable = canLearn;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
tooltip?.Show(talent, manager);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
tooltip?.Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user