diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Tooltip.meta b/Assets/Scripts/REFACTORING/Application/Panel/Tooltip.meta new file mode 100644 index 00000000..d07d952b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Tooltip.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: be0bbc86b6144804a8277039b5fe9a16 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Tooltip/ItemTooltip.cs b/Assets/Scripts/REFACTORING/Application/Panel/Tooltip/ItemTooltip.cs new file mode 100644 index 00000000..cee322ff --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Tooltip/ItemTooltip.cs @@ -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(), + Input.mousePosition, + GameObject.FindObjectOfType(), + out localPoint + ); + + transform.localPosition = localPoint; + + Vector2 anchoredPosition = transform.GetComponent().anchoredPosition; + + //if(anchoredPosition.x + back) + transform.GetComponent().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) + { + + } +} + diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Tooltip/ItemTooltip.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Tooltip/ItemTooltip.cs.meta new file mode 100644 index 00000000..2afd20cb --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Tooltip/ItemTooltip.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ea432c2f9c08bc348a24bc7659a46d80 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip.meta new file mode 100644 index 00000000..c08d3cf9 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: aa6860085c4248c4ab493d42340da014 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip/ItemTooltipController.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip/ItemTooltipController.cs new file mode 100644 index 00000000..6d88215c --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip/ItemTooltipController.cs @@ -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().BuildContent(item); + } + + public void DestroyTooltip() + { + DestroyImmediate(_tooltip); + } + + public void UpdateTooltipPosition() + { + + } +} diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip/ItemTooltipController.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip/ItemTooltipController.cs.meta new file mode 100644 index 00000000..4e0c393f --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Tooltip/ItemTooltipController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bb8913178367b0745a545a9feb8cfb35 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs b/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs index a6b9af89..cf6b12f9 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs @@ -109,13 +109,14 @@ public class InventoryPanelController : WarehousePanelController // 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 + // 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