added Item changing Sprite when hovering over Slot in Shop or Inventory
This commit is contained in:
parent
fe63511825
commit
24fa26ddb2
11 changed files with 46 additions and 23 deletions
|
|
@ -6,23 +6,23 @@ public class HoverManager : MonoBehaviour {
|
|||
public TextMeshProUGUI descriptionText;
|
||||
public RectTransform descriptionHoverBackground;
|
||||
|
||||
public static Action<string, Vector2> onMouseHover;
|
||||
public static Action<string, Vector2> 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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Shop : ItemStorage {
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ShopSlot>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue