Tooltip - events

This commit is contained in:
kabix09 2023-01-14 00:39:13 +01:00
parent 48832ab428
commit 815c5de830
4 changed files with 55 additions and 1 deletions

View File

@ -33,6 +33,8 @@ public abstract class DraggablePanelController : PanelController<IndexValuePair<
slot.OnDragEvent += Drag;
slot.OnDropEvent += Drop;
slot.OnPointerClickEvent += MouseClick;
slot.OnPointerEnterEvent += MouseEnter;
slot.OnPointerExitEvent += MouseExit;
return slot;
}
@ -143,6 +145,15 @@ public abstract class DraggablePanelController : PanelController<IndexValuePair<
}
#endregion
#region toolpit
public virtual void MouseEnter(ItemSlot itemSlot, PointerEventData eventData)
{
if (itemSlot.Item == null)
return;
}
public virtual void MouseExit(ItemSlot itemSlot, PointerEventData eventData) { }
#endregion
public ISlot GetDraggedSlot()
{

View File

@ -94,10 +94,29 @@ public class InventoryPanelController : WarehousePanelController
}
}
#region mouse actions
public override void SingleLeftMouseClick(ItemSlot itemSlot)
{
// mark item as selected in shop panel
if (ShopContentUIManager.Instance.DynamicPanel)
ShopContentUIManager.Instance.DynamicPanel.transform.Find("ItemDetails").GetComponent<ShopItemCardKeeper>().ShowItemDetails(itemSlot, ShopItemCardMode.Sell);
}
#endregion
#region tooltip
public override void MouseEnter(ItemSlot itemSlot, PointerEventData eventData)
{
// check if there is item on slot else retrun null breaking function
base.MouseEnter(itemSlot, eventData);
// todo open tooltip panel with item data
// Tooltip.OpenPanel(itemSlot. Item); - instantiate tooltip panel object
}
public override void MouseExit(ItemSlot itemSlot, PointerEventData eventData)
{
// Tooltip.CloePanel(); - destroy gameobject if panel is opened
}
#endregion
}

View File

@ -18,6 +18,8 @@ public interface ISlot
event Action<ItemSlot> OnDragEvent;
event Action<ItemSlot> OnDropEvent;
event Action<ItemSlot, PointerEventData> OnPointerClickEvent;
event Action<ItemSlot, PointerEventData> OnPointerEnterEvent;
event Action<ItemSlot, PointerEventData> OnPointerExitEvent;
//(B)Islot // as B
public void SetupSlot(int _number, EquippableItem _item, WarehousePanelController _PanelController);

View File

@ -6,7 +6,15 @@ using UnityEngine.UI;
using UnityEngine.EventSystems;
using System; // for Action type
public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler, IDragHandler, IDropHandler, IPointerClickHandler
public class ItemSlot : MonoBehaviour,
ISlot,
IBeginDragHandler,
IEndDragHandler,
IDragHandler,
IDropHandler,
IPointerClickHandler,
IPointerEnterHandler,
IPointerExitHandler
{
[Header("UI Stuff to change")]
[SerializeField] private TextMeshProUGUI slotItemNumberText;
@ -48,6 +56,8 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler
public event Action<ItemSlot> OnDragEvent;
public event Action<ItemSlot> OnDropEvent;
public event Action<ItemSlot, PointerEventData> OnPointerClickEvent;
public event Action<ItemSlot, PointerEventData> OnPointerEnterEvent;
public event Action<ItemSlot, PointerEventData> OnPointerExitEvent;
/* public ItemSlot() { }
public ItemSlot(int number, EquippableItem item = null)
@ -161,5 +171,17 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler
if (OnPointerClickEvent != null)
OnPointerClickEvent(this, eventData);
}
public void OnPointerEnter(PointerEventData eventData)
{
if (OnPointerEnterEvent != null)
OnPointerEnterEvent(this, eventData);
}
public void OnPointerExit(PointerEventData eventData)
{
if (OnPointerExitEvent != null)
OnPointerExitEvent(this, eventData);
}
#endregion
}