Undo last purchase working again
Added Comments to AnimalShop, ItemShop and ShopUI classes
This commit is contained in:
parent
441ffb900a
commit
c01c592976
7 changed files with 25 additions and 194 deletions
|
|
@ -1,8 +1,6 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Shop {
|
||||
|
||||
|
||||
public class AnimalShop : ElementStorage<Animal> {
|
||||
#region Singleton
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ using TMPro;
|
|||
using UnityEngine;
|
||||
|
||||
namespace Shop {
|
||||
|
||||
public class AnimalShopSlot : ElementStorageSlot<Animal> {
|
||||
public TextMeshProUGUI nameText;
|
||||
public TextMeshProUGUI costText;
|
||||
|
|
@ -16,8 +15,8 @@ namespace Shop {
|
|||
}
|
||||
|
||||
/**
|
||||
* Clears the Shop Slot
|
||||
*/
|
||||
* Clears the Shop Slot
|
||||
*/
|
||||
public override void ClearSlot() {
|
||||
nameText.text = "";
|
||||
costText.text = "";
|
||||
|
|
@ -26,8 +25,8 @@ namespace Shop {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets called when the Shop Slot is clicked
|
||||
*/
|
||||
* Gets called when the Shop Slot is clicked
|
||||
*/
|
||||
public override void UseElement() {
|
||||
if(Element) {
|
||||
if(_playerController.Money >= Element.price) {
|
||||
|
|
@ -46,6 +45,9 @@ namespace Shop {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Places cow randomly on Screen
|
||||
*/
|
||||
private void PlaceCowRandomlyOnScreen() {
|
||||
float spawnY = Random.Range
|
||||
(Camera.main.ScreenToWorldPoint(new Vector2(0, 0)).y,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Shop {
|
||||
|
||||
|
||||
public class ItemShop : ElementStorage<Item> {
|
||||
#region Singleton
|
||||
|
||||
|
|
@ -26,8 +24,8 @@ namespace Shop {
|
|||
private int _lastBoughtItemAmount;
|
||||
|
||||
/**
|
||||
* Calls ElementStorage.RemoveItem() and sets 2 Variables to remember the last bought item
|
||||
*/
|
||||
* Calls ElementStorage.RemoveItem() and sets 2 Variables to remember the last bought item
|
||||
*/
|
||||
public override void RemoveElement(Item item, int amount) {
|
||||
base.RemoveElement(item, amount);
|
||||
if(itemWasBought) {
|
||||
|
|
@ -36,6 +34,9 @@ namespace Shop {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo the last purchase (refund money)
|
||||
*/
|
||||
public void UndoLastPurchase() {
|
||||
if(itemWasBought) {
|
||||
_inventory = Inventory.instance;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ namespace Shop {
|
|||
}
|
||||
|
||||
/**
|
||||
* Clears the Shop Slot
|
||||
*/
|
||||
* Clears the Shop Slot
|
||||
*/
|
||||
public override void ClearSlot() {
|
||||
nameText.text = "";
|
||||
costText.text = "";
|
||||
|
|
@ -26,8 +26,8 @@ namespace Shop {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets called when the Shop Slot is clicked
|
||||
*/
|
||||
* Gets called when the Shop Slot is clicked
|
||||
*/
|
||||
public override void UseElement() {
|
||||
if(Element) {
|
||||
if(_playerController.Money >= Element.price) {
|
||||
|
|
@ -36,7 +36,6 @@ namespace Shop {
|
|||
_itemShop.itemWasBought = true;
|
||||
// Debug.Log("Buying Item: " + Element.displayName);
|
||||
}
|
||||
|
||||
_inventory.AddElement(Element, 1);
|
||||
_itemShop.RemoveElement(Element, 1);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ using UnityEngine;
|
|||
using UnityEngine.UI;
|
||||
|
||||
namespace Shop {
|
||||
|
||||
|
||||
public class ShopSwitcher : MonoBehaviour {
|
||||
public Sprite animalShopSprite;
|
||||
public Sprite itemShopSprite;
|
||||
|
|
@ -22,6 +20,10 @@ namespace Shop {
|
|||
viewportAnimals.SetActive(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shops get switched between Animal and Item Shop
|
||||
* The Image on the Button gets changes depending at which Shop you are
|
||||
*/
|
||||
public void SwitchShops() {
|
||||
// switch Shop Title text and Image of the Button
|
||||
if(shopTitleText.text.StartsWith("Item")) {
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ namespace Shop {
|
|||
}
|
||||
|
||||
/**
|
||||
* Turn on/off the Shop UI
|
||||
*/
|
||||
* Turn on/off the Shop UI
|
||||
*/
|
||||
private void ToggleShop() {
|
||||
inventoryUI.gameObject.SetActive(!shopUI.activeSelf);
|
||||
HoverManager.instance.HideDescription();
|
||||
|
|
@ -54,10 +54,10 @@ namespace Shop {
|
|||
}
|
||||
|
||||
/**
|
||||
* Is called when something in the Shop UI should update
|
||||
*/
|
||||
* Is called when something in the Shop UI should update
|
||||
*/
|
||||
private void UpdateUI() {
|
||||
// Add all items to the correct slots and clear the ones where no item should be
|
||||
// Add all items and animals to the correct slots and clear the ones where no item/animal should be
|
||||
for(int i = 0; i < _itemSlots.Length; i++) {
|
||||
// Item Slots
|
||||
if(i < _itemShop.Elements.Count) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue