first commit
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TalentNodeUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public TalentData talent;
|
||||
public TalentManager manager;
|
||||
public TalentTooltipUI tooltip;
|
||||
|
||||
public Image backgroundImage;
|
||||
public Image iconImage;
|
||||
public Text nameText;
|
||||
public Text costText;
|
||||
public Text stateText;
|
||||
public Button learnButton;
|
||||
public Outline borderOutline;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (learnButton == null)
|
||||
{
|
||||
learnButton = GetComponent<Button>();
|
||||
}
|
||||
|
||||
if (backgroundImage == null)
|
||||
{
|
||||
backgroundImage = GetComponent<Image>();
|
||||
}
|
||||
|
||||
if (borderOutline == null)
|
||||
{
|
||||
borderOutline = GetComponent<Outline>();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (learnButton != null)
|
||||
{
|
||||
learnButton.onClick.RemoveListener(OnClickLearn);
|
||||
learnButton.onClick.AddListener(OnClickLearn);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (learnButton != null)
|
||||
{
|
||||
learnButton.onClick.RemoveListener(OnClickLearn);
|
||||
}
|
||||
}
|
||||
|
||||
public void Setup(TalentData talent, TalentManager manager)
|
||||
{
|
||||
this.talent = talent;
|
||||
this.manager = manager;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (talent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (nameText != null)
|
||||
{
|
||||
nameText.text = talent.displayName;
|
||||
}
|
||||
|
||||
if (costText != null)
|
||||
{
|
||||
costText.text = $"{talent.cost} очк.";
|
||||
}
|
||||
|
||||
if (iconImage != null)
|
||||
{
|
||||
iconImage.sprite = talent.icon;
|
||||
iconImage.color = talent.icon != null ? Color.white : talent.branchColor;
|
||||
}
|
||||
|
||||
bool learned = manager != null && manager.IsLearned(talent);
|
||||
bool prerequisitesLearned = manager != null && manager.ArePrerequisitesLearned(talent);
|
||||
bool enoughPoints = manager != null && manager.GetAvailableTalentPoints() >= talent.cost;
|
||||
bool available = manager != null && manager.CanLearn(talent);
|
||||
|
||||
Color nodeColor = UITheme.LockedNode;
|
||||
string state = "Заблокировано";
|
||||
|
||||
if (learned)
|
||||
{
|
||||
nodeColor = UITheme.LearnedNode;
|
||||
state = "Изучено";
|
||||
}
|
||||
else if (available)
|
||||
{
|
||||
nodeColor = talent.branchColor;
|
||||
state = "Доступно";
|
||||
}
|
||||
else if (prerequisitesLearned && !enoughPoints)
|
||||
{
|
||||
nodeColor = UITheme.NotEnoughNode;
|
||||
state = "Не хватает очков";
|
||||
}
|
||||
|
||||
if (backgroundImage != null)
|
||||
{
|
||||
backgroundImage.color = new Color(nodeColor.r, nodeColor.g, nodeColor.b, learned || available ? 0.92f : 0.72f);
|
||||
}
|
||||
|
||||
if (borderOutline != null)
|
||||
{
|
||||
borderOutline.effectColor = learned ? UITheme.Gold : (available ? Color.white : UITheme.LockedNode);
|
||||
}
|
||||
|
||||
if (stateText != null)
|
||||
{
|
||||
stateText.text = state;
|
||||
}
|
||||
|
||||
if (learnButton != null)
|
||||
{
|
||||
learnButton.interactable = available;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClickLearn()
|
||||
{
|
||||
if (manager != null && talent != null)
|
||||
{
|
||||
manager.LearnTalent(talent);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowTooltip()
|
||||
{
|
||||
if (tooltip == null)
|
||||
{
|
||||
tooltip = FindObjectOfType<TalentTooltipUI>(true);
|
||||
}
|
||||
|
||||
if (tooltip != null)
|
||||
{
|
||||
tooltip.Show(talent, manager);
|
||||
}
|
||||
}
|
||||
|
||||
public void HideTooltip()
|
||||
{
|
||||
if (tooltip != null)
|
||||
{
|
||||
tooltip.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
ShowTooltip();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
HideTooltip();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user