Compare commits

...

2 Commits

Author SHA1 Message Date
kabix09
2db82701a4 Tooltip - template 2023-01-14 02:33:11 +01:00
kabix09
815c5de830 Tooltip - events 2023-01-14 00:39:13 +01:00
10 changed files with 207 additions and 1 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: be0bbc86b6144804a8277039b5fe9a16
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
class ItemTooltip : MonoBehaviour
{
// Card elements
// like text fields etc
// function to overwrite tooltip position to follow the mouse
public void Update()
{
// if tooltip is created then update its position
Vector2 localPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(
transform.parent.GetComponent<RectTransform>(),
Input.mousePosition,
GameObject.FindObjectOfType<Camera>(),
out localPoint
);
transform.localPosition = localPoint;
Vector2 anchoredPosition = transform.GetComponent<RectTransform>().anchoredPosition;
//if(anchoredPosition.x + back)
transform.GetComponent<RectTransform>().anchoredPosition = anchoredPosition;
}
public void BuildContent(Item item)
{
// 1. detect type
var equippableItem = item as EquippableItem;
// 2. todo - build tooltip content
if (equippableItem == null)
BuildBasedOnItem(item);
else
BuildBasedOnEquippableItem(equippableItem);
}
private void BuildBasedOnItem(Item item)
{
}
private void BuildBasedOnEquippableItem(EquippableItem item)
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea432c2f9c08bc348a24bc7659a46d80
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -33,6 +33,8 @@ public abstract class DraggablePanelController : PanelController<IndexValuePair<
slot.OnDragEvent += Drag; slot.OnDragEvent += Drag;
slot.OnDropEvent += Drop; slot.OnDropEvent += Drop;
slot.OnPointerClickEvent += MouseClick; slot.OnPointerClickEvent += MouseClick;
slot.OnPointerEnterEvent += MouseEnter;
slot.OnPointerExitEvent += MouseExit;
return slot; return slot;
} }
@ -143,6 +145,15 @@ public abstract class DraggablePanelController : PanelController<IndexValuePair<
} }
#endregion #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() public ISlot GetDraggedSlot()
{ {

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aa6860085c4248c4ab493d42340da014
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
class ItemTooltipController : MonoBehaviour
{
public static ItemTooltipController Instance { get; private set; }
[Header("Tooltip template")]
[SerializeField] protected GameObject TooltipTemplate;
[Space]
[Header("Tooltip panel")]
[SerializeField] protected GameObject _tooltip;
// canvast react transform - canvast from scene
// background rect transform - current slot rect transform
public void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
}
public void CreateTooltip(Item item)
{
// detect if passed equippable or base item
_tooltip = Instantiate(_tooltip, GameObject.FindGameObjectWithTag("GUI").transform);
// build content based on passed item info
_tooltip.GetComponent<ItemTooltip>().BuildContent(item);
}
public void DestroyTooltip()
{
DestroyImmediate(_tooltip);
}
public void UpdateTooltipPosition()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bb8913178367b0745a545a9feb8cfb35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -94,10 +94,30 @@ public class InventoryPanelController : WarehousePanelController
} }
} }
#region mouse actions
public override void SingleLeftMouseClick(ItemSlot itemSlot) public override void SingleLeftMouseClick(ItemSlot itemSlot)
{ {
// mark item as selected in shop panel // mark item as selected in shop panel
if (ShopContentUIManager.Instance.DynamicPanel) if (ShopContentUIManager.Instance.DynamicPanel)
ShopContentUIManager.Instance.DynamicPanel.transform.Find("ItemDetails").GetComponent<ShopItemCardKeeper>().ShowItemDetails(itemSlot, ShopItemCardMode.Sell); 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);
// Tooltip.OpenPanel(itemSlot.Item); - instantiate tooltip panel object
ItemTooltipController.Instance.CreateTooltip(itemSlot.Item);
}
public override void MouseExit(ItemSlot itemSlot, PointerEventData eventData)
{
// Tooltip.CloePanel(); - destroy gameobject if panel is opened
ItemTooltipController.Instance.DestroyTooltip();
}
#endregion
} }

View File

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

View File

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