Pedro Gomes 9461120386 Rogue-lite progression continued (WIP)
- ability unlocks (90% done)
- class unlocks (working)
- new human base class
- bugfix small issues
2025-01-19 23:18:07 +00:00

79 lines
2.1 KiB
C#

using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
namespace Kryz.CharacterStats.Examples
{
public class ItemSlot : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField] protected Image image;
public UnityEvent_ItemInstance OnRightClickEvent = new UnityEvent_ItemInstance();
protected ItemInstance _item;
public ItemInstance Item {
get { return _item; }
set {
_item = value;
if (_item == null) {
image.enabled = false;
} else if (_item.Icon == null) {
image.enabled = false;
}
else
{
//Debug.Log("Item Slot: " + _item);
//Debug.Log("Item Slot: " + _item.Icon);
//Debug.Log("Item Slot: " + _item.templateIndex);
//Debug.Log("Item Slot: " + ItemIndexer.Instance.Items[_item.templateIndex].ItemName);
image.sprite = _item.Icon;
image.enabled = true;
}
}
}
public void OnPointerClick(PointerEventData eventData)
{
if (eventData != null && eventData.button == PointerEventData.InputButton.Right)
{
//Debug.LogError("PointerClick");
//Debug.LogError(Item);
//Debug.LogError(OnRightClickEvent);
if (Item != null && OnRightClickEvent != null)
{
OnRightClickEvent.Invoke(Item);
//Debug.LogError("right click: " + Item.ItemName);
}
}
}
protected virtual void OnValidate()
{
if (image == null)
image = GetComponent<Image>();
}
public virtual void OnPointerEnter(PointerEventData eventData)
{
ItemTooltip.Instance.ShowTooltip(Item);
if (Item is EquippableItemInstance ei)
{
EquippableItemInstance equippedInSameSlot = EquipmentPanel.Instance.GetEquippedItemOnSpecificSlot(ei.EquipmentType);
if (equippedInSameSlot != null && !string.IsNullOrEmpty(equippedInSameSlot.ItemName))
{
EquippedItemTooltip.Instance.ShowTooltip(equippedInSameSlot);
}
}
}
public void OnPointerExit(PointerEventData eventData)
{
ItemTooltip.Instance.HideTooltip();
EquippedItemTooltip.Instance.HideTooltip();
}
}
}