From 24fa26ddb2aafb04e7d93593985f2785d7a9ea13 Mon Sep 17 00:00:00 2001 From: dhain Date: Fri, 3 Jun 2022 09:29:24 +0200 Subject: [PATCH] added Item changing Sprite when hovering over Slot in Shop or Inventory --- Assets/Farming Asset Pack/Split Assets.meta | 8 ++++++++ Assets/Items/Usable/FishingRod.asset | 2 +- Assets/Scenes/MainScene.unity | 6 +++--- Assets/Scripts/HoverManager.cs | 8 ++++---- Assets/Scripts/Inventory.cs | 4 ++-- Assets/Scripts/ItemStorage.cs | 2 +- Assets/Scripts/ItemStorageSlot.cs | 17 +++++++++++++++-- Assets/Scripts/Shop.cs | 1 - Assets/Scripts/ShopSlot.cs | 4 ++-- Assets/Scripts/ShopUI.cs | 4 ++++ Assets/ShopSlot.prefab | 13 ++++++------- 11 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 Assets/Farming Asset Pack/Split Assets.meta diff --git a/Assets/Farming Asset Pack/Split Assets.meta b/Assets/Farming Asset Pack/Split Assets.meta new file mode 100644 index 0000000..7a0c647 --- /dev/null +++ b/Assets/Farming Asset Pack/Split Assets.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c73478f9c6622694193b6b0525d76af5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Items/Usable/FishingRod.asset b/Assets/Items/Usable/FishingRod.asset index 996a94d..b5dff46 100644 --- a/Assets/Items/Usable/FishingRod.asset +++ b/Assets/Items/Usable/FishingRod.asset @@ -1,4 +1,4 @@ -%YAML 1.1 +%YAML 1.1 %TAG !u! tag:unity3d.com,2011: --- !u!114 &11400000 MonoBehaviour: diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index e71aedd..0c5b725 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -1639,7 +1639,7 @@ MonoBehaviour: m_HandleRect: {fileID: 2006577138} m_Direction: 2 m_Value: 1 - m_Size: 0.59324205 + m_Size: 0.5932421 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -4996,7 +4996,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1291863650 MonoBehaviour: m_ObjectHideFlags: 0 @@ -5010,7 +5010,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: tile: {fileID: 4752245148499717901, guid: ea81011a3ce83fb4386934728a92ee2d, type: 3} - cameraGameObject: {fileID: 0} + cameraGameObject: {fileID: 598358736} --- !u!4 &1291863651 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/HoverManager.cs b/Assets/Scripts/HoverManager.cs index 1908452..4f4753c 100644 --- a/Assets/Scripts/HoverManager.cs +++ b/Assets/Scripts/HoverManager.cs @@ -6,23 +6,23 @@ public class HoverManager : MonoBehaviour { public TextMeshProUGUI descriptionText; public RectTransform descriptionHoverBackground; - public static Action onMouseHover; + public static Action onMouseHoverDescription; public static Action onMouseExit; private void OnEnable() { - onMouseHover += ShowDescription; + onMouseHoverDescription += ShowDescription; onMouseExit += HideDescription; } private void OnDisable() { - onMouseHover -= ShowDescription; + onMouseHoverDescription -= ShowDescription; onMouseExit -= HideDescription; } private void Start() { HideDescription(); } - + /** * Show the description Text at the mouse position */ diff --git a/Assets/Scripts/Inventory.cs b/Assets/Scripts/Inventory.cs index f297705..b6e5187 100644 --- a/Assets/Scripts/Inventory.cs +++ b/Assets/Scripts/Inventory.cs @@ -15,13 +15,13 @@ public class Inventory : ItemStorage { #endregion - public const int InventorySpace = 28; + private const int _InventorySpace = 28; /** * Adds the specified amount of items to the Inventory */ public override void AddItem(Item item, int amount) { - if(items.Count >= InventorySpace) { + if(items.Count >= _InventorySpace) { Debug.Log("Not enough inventory space!"); return; } diff --git a/Assets/Scripts/ItemStorage.cs b/Assets/Scripts/ItemStorage.cs index 3b023ba..99e5f02 100644 --- a/Assets/Scripts/ItemStorage.cs +++ b/Assets/Scripts/ItemStorage.cs @@ -35,7 +35,7 @@ public class ItemStorage : MonoBehaviour { * Removes the specified amount of items in the Item Storage */ public void RemoveItem(Item item, int amount) { - if(items[item] <= 0) { + if(items[item]-amount <= 0) { items.Remove(item); } else { items[item] -= amount; diff --git a/Assets/Scripts/ItemStorageSlot.cs b/Assets/Scripts/ItemStorageSlot.cs index f8c8f04..5aba5c4 100644 --- a/Assets/Scripts/ItemStorageSlot.cs +++ b/Assets/Scripts/ItemStorageSlot.cs @@ -13,23 +13,36 @@ public class ItemStorageSlot : MonoBehaviour, IPointerEnterHandler, IPointerExit private Item _item; - #region DescriptionHover + #region HoverOverItem public float timeToWait; public void OnPointerEnter(PointerEventData eventData) { StopAllCoroutines(); StartCoroutine(StartTimer()); + + ChangeItemSelectedSprite(true); } public void OnPointerExit(PointerEventData eventData) { StopAllCoroutines(); + ChangeItemSelectedSprite(false); HoverManager.onMouseExit(); } private void ShowMessage() { if(_item){ - HoverManager.onMouseHover(_item.description, Input.mousePosition); + HoverManager.onMouseHoverDescription(_item.description, Input.mousePosition); + } + } + + private void ChangeItemSelectedSprite(bool on) { + if(_item) { + if(on) { + icon.sprite = _item.selectedSprite; + } else { + icon.sprite = _item.defaultSprite; + } } } diff --git a/Assets/Scripts/Shop.cs b/Assets/Scripts/Shop.cs index 71c261a..072271a 100644 --- a/Assets/Scripts/Shop.cs +++ b/Assets/Scripts/Shop.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using UnityEngine; public class Shop : ItemStorage { diff --git a/Assets/Scripts/ShopSlot.cs b/Assets/Scripts/ShopSlot.cs index 6c7855a..f18347e 100644 --- a/Assets/Scripts/ShopSlot.cs +++ b/Assets/Scripts/ShopSlot.cs @@ -19,10 +19,11 @@ public class ShopSlot : ItemStorageSlot { * Clears the Shop Slot */ public override void ClearSlot() { - base.ClearSlot(); nameText.text = ""; costText.text = ""; amountText.text = ""; + // _shop.RemoveItem(Item, 1); + base.ClearSlot(); } /** @@ -35,7 +36,6 @@ public class ShopSlot : ItemStorageSlot { _playerController.ChangeMoney(-Item.cost); Debug.Log("Buying Item: " + Item.displayName); - Debug.Log("money left: " + _playerController.Money); } else { Debug.Log("Not enough money to buy item."); } diff --git a/Assets/Scripts/ShopUI.cs b/Assets/Scripts/ShopUI.cs index 61a9050..c4e63f9 100644 --- a/Assets/Scripts/ShopUI.cs +++ b/Assets/Scripts/ShopUI.cs @@ -4,6 +4,8 @@ using UnityEngine; public class ShopUI : MonoBehaviour { public Transform itemsParent; public GameObject shopUI; + public bool shopIsOpen; + private Shop _shop; private ShopSlot[] _slots; @@ -14,6 +16,7 @@ public class ShopUI : MonoBehaviour { // Add all ShopSlot GameObjects to _slots and turn off the Shop UI _slots = itemsParent.GetComponentsInChildren(); + shopIsOpen = false; ToggleShop(); // Set the icon to not be a raycast target for the Description Hovering to work @@ -25,6 +28,7 @@ public class ShopUI : MonoBehaviour { private void Update() { // When "Shop" button is pressed turn on/off Shop UI if(Input.GetButtonDown("Shop")) { + shopIsOpen = true; ToggleShop(); } } diff --git a/Assets/ShopSlot.prefab b/Assets/ShopSlot.prefab index cde36d3..d589e1a 100644 --- a/Assets/ShopSlot.prefab +++ b/Assets/ShopSlot.prefab @@ -60,7 +60,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Material: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 + m_RaycastTarget: 0 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: @@ -136,7 +136,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Material: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 + m_RaycastTarget: 0 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: @@ -271,7 +271,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Material: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 + m_RaycastTarget: 0 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: @@ -406,7 +406,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Material: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 + m_RaycastTarget: 0 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: @@ -633,11 +633,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: icon: {fileID: 5121261191727116855} - item: {fileID: 0} - nameText: {fileID: 5121261192692990484} - costText: {fileID: 5121261192300927449} amountText: {fileID: 5121261192606669392} timeToWait: 0.5 + nameText: {fileID: 5121261192692990484} + costText: {fileID: 5121261192300927449} --- !u!61 &5121261193055935941 BoxCollider2D: m_ObjectHideFlags: 0