Merge branch 'develop' into jweissen
# Conflicts: # Assets/Scripts/Tiles/BaseTile.cs
This commit is contained in:
commit
7e7d9854f7
176 changed files with 4239 additions and 527 deletions
|
|
@ -6,28 +6,45 @@ using UnityEngine;
|
|||
using UnityEngine.Events;
|
||||
|
||||
public class HouseController : MonoBehaviour {
|
||||
private int dayCount = 1;
|
||||
private static UnityEvent newDayEvent;
|
||||
public static UnityEvent NewDayEvent => newDayEvent;
|
||||
private int _dayCount = 1;
|
||||
private static UnityEvent _newDayEvent;
|
||||
public static UnityEvent NewDayEvent => _newDayEvent;
|
||||
|
||||
public Canvas menu;
|
||||
public TextMeshProUGUI dayCountTextMeshProUGUI;
|
||||
public GameObject menuPanel;
|
||||
|
||||
private void OnMouseDown() {
|
||||
toggleMenu();
|
||||
ToggleMenu();
|
||||
}
|
||||
|
||||
void Start() {
|
||||
newDayEvent ??= new UnityEvent();
|
||||
_newDayEvent ??= new UnityEvent();
|
||||
ToggleMenu();
|
||||
}
|
||||
|
||||
public void newDay() {
|
||||
dayCount++;
|
||||
dayCountTextMeshProUGUI.text = dayCount.ToString();
|
||||
newDayEvent?.Invoke();
|
||||
public void NewDay() {
|
||||
_dayCount++;
|
||||
dayCountTextMeshProUGUI.text = _dayCount.ToString();
|
||||
_newDayEvent?.Invoke();
|
||||
}
|
||||
|
||||
public void toggleMenu() {
|
||||
public void ToggleMenu() {
|
||||
menu.gameObject.SetActive(!menu.gameObject.activeSelf);
|
||||
float newPosY;
|
||||
if (Camera.main != null) {
|
||||
|
||||
Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
|
||||
|
||||
if (pos.y - 50 - ((RectTransform)menuPanel.transform).rect.height >= 0) { //check if bottom of panel is in screen
|
||||
newPosY = pos.y - ((RectTransform)menuPanel.transform).rect.height;
|
||||
} else {
|
||||
newPosY = pos.y + ((RectTransform)menuPanel.transform).rect.height;
|
||||
}
|
||||
|
||||
menuPanel.transform.position = new Vector3(pos.x, newPosY);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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 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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class PlayerController : MonoBehaviour {
|
|||
public void SetSelectedItem(UsableItem item) {
|
||||
if(_inventory.items.ContainsKey(item)) {
|
||||
_selectedItem = item;
|
||||
Cursor.SetCursor(item.selectedSprite.texture, Vector2.zero, CursorMode.Auto);
|
||||
Cursor.SetCursor(item.defaultSprite.texture, Vector2.zero, CursorMode.Auto);
|
||||
} else {
|
||||
Debug.Log("An item requested to select isn't in the inventory" + item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Shop : ItemStorage {
|
||||
|
|
|
|||
|
|
@ -14,33 +14,37 @@ public class ShopSlot : ItemStorageSlot {
|
|||
_inventory = Inventory.instance;
|
||||
_playerController = PlayerController.instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears the Shop Slot
|
||||
*/
|
||||
public override void ClearSlot() {
|
||||
base.ClearSlot();
|
||||
nameText.text = "";
|
||||
costText.text = "";
|
||||
amountText.text = "";
|
||||
// _shop.RemoveItem(Item, 1);
|
||||
base.ClearSlot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called when the Shop Slot is clicked
|
||||
*/
|
||||
public override void UseItem() {
|
||||
if(_playerController.Money >= Item.cost) {
|
||||
_inventory.AddItem(Item, 1);
|
||||
_shop.RemoveItem(Item, 1);
|
||||
_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.");
|
||||
if(Item) {
|
||||
if(_playerController.Money >= Item.cost) {
|
||||
_inventory.AddItem(Item, 1);
|
||||
_shop.RemoveItem(Item, 1);
|
||||
if(Item) {
|
||||
_playerController.ChangeMoney(-Item.cost);
|
||||
|
||||
Debug.Log("Buying Item: " + Item.displayName);
|
||||
}
|
||||
} else {
|
||||
Debug.Log("Not enough money to buy item.");
|
||||
}
|
||||
|
||||
_shop.onItemChangedCallback?.Invoke();
|
||||
_inventory.onItemChangedCallback?.Invoke();
|
||||
}
|
||||
|
||||
_shop.onItemChangedCallback?.Invoke();
|
||||
_inventory.onItemChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using UnityEngine;
|
|||
public class TileBehaviour : MonoBehaviour
|
||||
{
|
||||
private BaseTile _tile;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue