diff --git a/MrBigsock/Assets/Code/UI/InventoryPanel.cs b/MrBigsock/Assets/Code/UI/InventoryPanel.cs index 958473c7cd15b8fe6cd48979f7b6398e6ded05ed..d8d3512e56e03be99c443f4e9c827bed5920b741 100644 --- a/MrBigsock/Assets/Code/UI/InventoryPanel.cs +++ b/MrBigsock/Assets/Code/UI/InventoryPanel.cs @@ -1,9 +1,13 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; +using TMPro; + + using BigSock.Item; using BigSock.Service; -using UnityEngine.UI; + namespace BigSock.UI { @@ -18,8 +22,15 @@ namespace BigSock.UI public GridLayoutGroup gridAccessory; public GridLayoutGroup gridEquipment; + public TextMeshProUGUI toolTip; + + public void Start() { GenerateInv(); + + // Get the tooltip child-component if it's not set in the prefab. + toolTip ??= transform.Find("ToolTip")?.GetComponent<TextMeshProUGUI>(); + } public void GenerateInv() @@ -100,6 +111,36 @@ namespace BigSock.UI } } + + /* + Sets the text of the tooltip. + (Current version is just a basic test of the concept) + */ + public void SetToolTip(string text) { + //Debug.Log($"[InventoryPanel.SetToolTip()]"); + + toolTip?.SetText(text); + + /* + Planned changes: + - Take in position. + - Give it a background. + - Place it where we indicate. + - Way to remove it when we move. + Vision: + - When player hovers over/clicks on the item, tooltip shows up. + - If we use hover: have delay and tooltip goes away when mouse moves away. + - If we use click: have it go away if user clicks elsewhere or again. + - Have tooltip either spawn based on cursor, or like a dropdown for the slot. + Ambitious: + - Have toolbox fade based on cursor distance from source. + - When cursor moves away from the item that caused it to appear, have it fade for a certain distance before it is removed. + + When cursor leaves the item slot, for a radius of 1x the slot size, fade from 100% to 0%, then remove if further. + - Have a way to color/bold part of the text. + - Bold the name. + - Use effects (color, italic, underline, ...) on key points of text to highlight. + */ + } } } diff --git a/MrBigsock/Assets/Code/UI/ItemPref.cs b/MrBigsock/Assets/Code/UI/ItemPref.cs index d918cc5617a6fd6fc7aa89876138918cc9dbfb64..8295d5d4a2fa909c72104cdbc650da7050e6e947 100644 --- a/MrBigsock/Assets/Code/UI/ItemPref.cs +++ b/MrBigsock/Assets/Code/UI/ItemPref.cs @@ -2,12 +2,14 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; + + using BigSock.Item; namespace BigSock.UI { - public class ItemPref : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler + public class ItemPref : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler, IPointerClickHandler { public IItem item; public ItemSlot itemSlot; @@ -55,11 +57,21 @@ namespace BigSock.UI canvasGroup.blocksRaycasts = true; } - public void OnPointerDown(PointerEventData eventData) - { - + public void OnPointerDown(PointerEventData eventData) { } + + + /* + When the user clicks on this box, display the tooltip. + (OnPointerClick only triggers if you press and release on the same object) + */ + public void OnPointerClick(PointerEventData eventData) { + //Debug.Log($"[ItemPref.OnPointerClick()] button: {eventData.button}, dragging: {eventData.dragging}"); + if(itemSlot != null && item != null) + itemSlot.DisplayToolTip(); + } + } } diff --git a/MrBigsock/Assets/Code/UI/ItemSlot.cs b/MrBigsock/Assets/Code/UI/ItemSlot.cs index ae690099aa3b3a466346c040c777d220b25abfc2..28f68084537029fedabdebbef0a27b2eac407c38 100644 --- a/MrBigsock/Assets/Code/UI/ItemSlot.cs +++ b/MrBigsock/Assets/Code/UI/ItemSlot.cs @@ -2,12 +2,14 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; + + using BigSock.Item; namespace BigSock.UI { - public class ItemSlot : MonoBehaviour, IDropHandler + public class ItemSlot : MonoBehaviour, IDropHandler, IPointerClickHandler { public InventoryType inventoryType; public int position; @@ -72,5 +74,32 @@ namespace BigSock.UI - If we want to add features to swap 2 items, this will need to be addressed. */ } + + + /* + When the user clicks on this box, display the tooltip. + (OnPointerClick only triggers if you press and release on the same objectS) + */ + public void OnPointerClick(PointerEventData eventData) { + Debug.Log($"[ItemSlot.OnPointerClick()] button: {eventData.button}, dragging: {eventData.dragging}"); + //DisplayToolTip(); + } + + + /* + Display the tooltip for our item onto the screen. + */ + public void DisplayToolTip() { + // We must have an item. + if(item?.item == null) return; + + // Find the inventory pannel we belong to. + var inventoryPanel = transform.parent?.parent?.GetComponent<InventoryPanel>(); + if(inventoryPanel == null) return; + + // Set the tooltip. + inventoryPanel.SetToolTip(item.item.GetToolTip()); + } + } } diff --git a/MrBigsock/Assets/Prefabs/UI/Inventory.prefab b/MrBigsock/Assets/Prefabs/UI/Inventory.prefab index 5ceaa0e7ee72e16a6ab35658cfe25754d8b3b060..508537f04f02a3c7e2dc96733d524af36f0a4600 100644 --- a/MrBigsock/Assets/Prefabs/UI/Inventory.prefab +++ b/MrBigsock/Assets/Prefabs/UI/Inventory.prefab @@ -1,5 +1,146 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &2098029998679132253 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7180107143627715269} + - component: {fileID: 3591846280383896495} + - component: {fileID: 1953923352213297619} + m_Layer: 5 + m_Name: ToolTip + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &7180107143627715269 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2098029998679132253} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6567380452587386444} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 750, y: 314} + m_SizeDelta: {x: 200, y: 50} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &3591846280383896495 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2098029998679132253} + m_CullTransparentMesh: 1 +--- !u!114 &1953923352213297619 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2098029998679132253} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: '[Name] + + + [Description] + + + [EffectText]' + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 30 + m_fontSizeBase: 30 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: -93.09827, w: -137.62933} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} --- !u!1 &6567380451069760396 GameObject: m_ObjectHideFlags: 0 @@ -278,6 +419,7 @@ RectTransform: - {fileID: 6567380451709996422} - {fileID: 6567380451432847410} - {fileID: 6567380451696418669} + - {fileID: 7180107143627715269} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -303,6 +445,7 @@ MonoBehaviour: gridTools: {fileID: 6567380451709996423} gridAccessory: {fileID: 6567380451696418666} gridEquipment: {fileID: 6567380451432847411} + toolTip: {fileID: 0} --- !u!1 &6567380452847058112 GameObject: m_ObjectHideFlags: 0 diff --git a/MrBigsock/Assets/Prefabs/UI/InventorySlot.prefab b/MrBigsock/Assets/Prefabs/UI/InventorySlot.prefab index bc8415168258f064f070eae14d31bf39c7ff3947..a97b6a52ea8c3436baf5843b51ee51b100ec0ac3 100644 --- a/MrBigsock/Assets/Prefabs/UI/InventorySlot.prefab +++ b/MrBigsock/Assets/Prefabs/UI/InventorySlot.prefab @@ -12,6 +12,7 @@ GameObject: - component: {fileID: 1755892659853653914} - component: {fileID: 103736067984069905} - component: {fileID: -7233777641745108413} + - component: {fileID: -7226931710873331521} m_Layer: 5 m_Name: InventorySlot m_TagString: Untagged @@ -89,3 +90,32 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9aa096919f2d6524e975802354e1093c, type: 3} m_Name: m_EditorClassIdentifier: + inventoryType: 0 + position: 0 + item: {fileID: 0} +--- !u!61 &-7226931710873331521 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7982190919252781434} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 diff --git a/MrBigsock/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset b/MrBigsock/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset index e85143257a739c972c247f7fa9716340394a4b34..f1a530f85f45e3523dba7e70fc00ef5642b47e63 100644 --- a/MrBigsock/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset +++ b/MrBigsock/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset @@ -9,7 +9,8 @@ Material: m_PrefabAsset: {fileID: 0} m_Name: LiberationSans SDF Material m_Shader: {fileID: 4800000, guid: fe393ace9b354375a9cb14cdbbc28be4, type: 3} - m_ValidKeywords: [] + m_ValidKeywords: + - OUTLINE_ON m_InvalidKeywords: [] m_LightmapFlags: 1 m_EnableInstancingVariants: 0 @@ -28,16 +29,16 @@ Material: m_Floats: - _ColorMask: 15 - _CullMode: 0 - - _FaceDilate: 0 + - _FaceDilate: 1 - _GradientScale: 10 - _MaskSoftnessX: 0 - _MaskSoftnessY: 0 - _OutlineSoftness: 0 - - _OutlineWidth: 0 + - _OutlineWidth: 0.666 - _PerspectiveFilter: 0.875 - - _ScaleRatioA: 0.9 + - _ScaleRatioA: 0.48556784 - _ScaleRatioB: 1 - - _ScaleRatioC: 0.73125 + - _ScaleRatioC: 0 - _ScaleX: 1 - _ScaleY: 1 - _ShaderFlags: 0 @@ -59,9 +60,9 @@ Material: - _WeightNormal: 0 m_Colors: - _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767} - - _FaceColor: {r: 1, g: 0, b: 0, a: 1} + - _FaceColor: {r: 1, g: 1, b: 1, a: 1} - _OutlineColor: {r: 0, g: 0, b: 0, a: 1} - - _UnderlayColor: {r: 0, g: 0, b: 0, a: 0.5} + - _UnderlayColor: {r: 0.6226415, g: 0, b: 0, a: 0.5} m_BuildTextureStacks: [] --- !u!114 &11400000 MonoBehaviour: