shop updated

This commit is contained in:
s-prechtl 2022-06-03 13:58:49 +02:00
parent 8211a11c2c
commit 7ccf683005
3 changed files with 21 additions and 12 deletions

View file

@ -5,29 +5,30 @@ public class ShopUI : MonoBehaviour {
public Transform itemsParent;
public GameObject shopUI;
public bool shopIsOpen;
public GameObject inventoryUI;
private Shop _shop;
private ShopSlot[] _slots;
private void Start() {
// Get Shop instance and add UpdateUI method to OnItemChanged delegate
_shop = Shop.instance;
_shop.onItemChangedCallback += UpdateUI;
// 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
foreach(ShopSlot slot in _slots) {
foreach (ShopSlot slot in _slots) {
slot.icon.raycastTarget = false;
}
}
private void Update() {
// When "Shop" button is pressed turn on/off Shop UI
if(Input.GetButtonDown("Shop")) {
if (Input.GetButtonDown("Shop")) {
shopIsOpen = true;
ToggleShop();
}
@ -37,6 +38,7 @@ public class ShopUI : MonoBehaviour {
* Turn on/off the Shop UI
*/
private void ToggleShop() {
inventoryUI.gameObject.SetActive(!shopUI.activeSelf);
shopUI.SetActive(!shopUI.activeSelf);
}
@ -45,13 +47,14 @@ public class ShopUI : MonoBehaviour {
*/
private void UpdateUI() {
// Add all items to the correct slots and clear the ones where no item should be
for(int i = 0; i < _slots.Length; i++) {
if(i < _shop.items.Count) {
for (int i = 0; i < _slots.Length; i++) {
if (i < _shop.items.Count) {
_slots[i].AddItem(_shop.items.ElementAt(i).Key);
_slots[i].nameText.text = _slots[i].Item.displayName;
_slots[i].costText.text = _slots[i].Item.cost + " µ";
_slots[i].amountText.text = _shop.items[_shop.items.ElementAt(i).Key] + " #";
} else {
}
else {
_slots[i].ClearSlot();
}
}

View file

@ -4,7 +4,7 @@ namespace Tiles
{
public class GrassTile : BaseTile
{
public GrassTile() : base("C:/Users/maile/UnityProjects/2122_3AHITN_Scrum_sprechtl_jweissen_dhain/Assets/Farming Asset Pack/Split Assets/farming_tileset_000.png")
public GrassTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_000.png")
{
}