Merge branch 'dhain' into develop

# Conflicts:
#	Assets/Farming Asset Pack/Split Assets.meta
#	Assets/Scenes/MainScene.unity
This commit is contained in:
dhain 2022-06-03 09:31:35 +02:00
commit ccb25d4335
10 changed files with 40 additions and 27 deletions

View file

@ -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
*/

View file

@ -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;
}

View file

@ -35,7 +35,7 @@ public class InventoryUI : MonoBehaviour {
private void ToggleInventory() {
inventoryUI.SetActive(!inventoryUI.activeSelf);
}
//TODO: sell Items with right click and when shop is open
/**
* Is called when something in the Inventory UI should update
*/

View file

@ -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;

View file

@ -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;
}
}
}

View file

@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEngine;
public class Shop : ItemStorage {

View file

@ -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.");
}

View file

@ -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();
}
}