fixed first Shop Slot
started on shop switcher button (for animal shop)
This commit is contained in:
parent
b0ab924037
commit
acd602c85a
11 changed files with 286 additions and 143 deletions
|
|
@ -2,7 +2,8 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
|
||||
public class ElementStorage<T> : MonoBehaviour {
|
||||
public Dictionary<T, int> elements;
|
||||
private Dictionary<T, int> _elements;
|
||||
public Dictionary<T, int> Elements => _elements;
|
||||
public T[] startElements;
|
||||
|
||||
/**
|
||||
|
|
@ -12,7 +13,7 @@ public class ElementStorage<T> : MonoBehaviour {
|
|||
public OnElementChanged onElementChangedCallback;
|
||||
|
||||
private void Start() {
|
||||
elements ??= new Dictionary<T, int>();
|
||||
_elements ??= new Dictionary<T, int>();
|
||||
foreach(T element in startElements) {
|
||||
AddElement(element, 1);
|
||||
}
|
||||
|
|
@ -22,10 +23,10 @@ public class ElementStorage<T> : MonoBehaviour {
|
|||
* Adds the specified amount of elements to the Element Storage
|
||||
*/
|
||||
public virtual void AddElement(T element, int amount) {
|
||||
if(!elements.ContainsKey(element)) {
|
||||
elements.Add(element, amount);
|
||||
if(!_elements.ContainsKey(element)) {
|
||||
_elements.Add(element, amount);
|
||||
} else {
|
||||
elements[element] += amount;
|
||||
_elements[element] += amount;
|
||||
}
|
||||
|
||||
onElementChangedCallback?.Invoke();
|
||||
|
|
@ -35,10 +36,10 @@ public class ElementStorage<T> : MonoBehaviour {
|
|||
* Removes the specified amount of elements in the Element Storage
|
||||
*/
|
||||
public virtual void RemoveElement(T element, int amount) {
|
||||
if(elements[element]-amount <= 0) {
|
||||
elements.Remove(element);
|
||||
if(_elements[element]-amount <= 0) {
|
||||
_elements.Remove(element);
|
||||
} else {
|
||||
elements[element] -= amount;
|
||||
_elements[element] -= amount;
|
||||
}
|
||||
|
||||
onElementChangedCallback?.Invoke();
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class ElementStorageSlot<T> : MonoBehaviour, IPointerEnterHandler, IPoint
|
|||
* Clears the Element Storage Slot
|
||||
*/
|
||||
public virtual void ClearSlot() {
|
||||
_element = default(T);
|
||||
_element = default;
|
||||
icon.sprite = null;
|
||||
icon.enabled = false;
|
||||
amountText.text = "";
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class FishingController : MonoBehaviour {
|
|||
}
|
||||
|
||||
public void StartFishing() {
|
||||
if (!_iv.elements.ContainsKey(_ic.GetItemByName("Bait"))) {
|
||||
if (!_iv.Elements.ContainsKey(_ic.GetItemByName("Bait"))) {
|
||||
_messageView.SendMessage("No bait!", 1.0f);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ public class Inventory : ElementStorage<Item> {
|
|||
* Adds the specified amount of items to the Inventory
|
||||
*/
|
||||
public override void AddElement(Item item, int amount) {
|
||||
if (elements.Count >= _InventorySpace) {
|
||||
if (Elements.Count >= _InventorySpace) {
|
||||
Debug.Log("Not enough inventory space!");
|
||||
return;
|
||||
}
|
||||
// Sell overflowing Items
|
||||
if (elements.ContainsKey(item) && elements[item] + amount >= _MaxItemStack) {
|
||||
SellItem(item, amount - (_MaxItemStack - elements[item]));
|
||||
amount = _MaxItemStack - elements[item];
|
||||
if (Elements.ContainsKey(item) && Elements[item] + amount >= _MaxItemStack) {
|
||||
SellItem(item, amount - (_MaxItemStack - Elements[item]));
|
||||
amount = _MaxItemStack - Elements[item];
|
||||
}
|
||||
base.AddElement(item, amount);
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ public class Inventory : ElementStorage<Item> {
|
|||
*/
|
||||
public override void RemoveElement(Item item, int amount) {
|
||||
base.RemoveElement(item, amount);
|
||||
if (!elements.ContainsKey(item) && PlayerController.instance.SelectedItem == item) {
|
||||
if (!Elements.ContainsKey(item) && PlayerController.instance.SelectedItem == item) {
|
||||
PlayerController.instance.DeselectItem();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@ public class InventoryUI : MonoBehaviour {
|
|||
private void UpdateUI() {
|
||||
// Add all items to the correct slots, clear the ones where no item should be and set the number of how many items are in the slot
|
||||
for(int i = 0; i < _slots.Length; i++) {
|
||||
if(i < _inventory.elements.Count) {
|
||||
_slots[i].AddElement(_inventory.elements.ElementAt(i).Key);
|
||||
_slots[i].amountText.text = "" + _inventory.elements[_inventory.elements.ElementAt(i).Key];
|
||||
if(_inventory.elements[_inventory.elements.ElementAt(i).Key] == 1) {
|
||||
if(i < _inventory.Elements.Count) {
|
||||
_slots[i].AddElement(_inventory.Elements.ElementAt(i).Key);
|
||||
_slots[i].amountText.text = "" + _inventory.Elements[_inventory.Elements.ElementAt(i).Key];
|
||||
if(_inventory.Elements[_inventory.Elements.ElementAt(i).Key] == 1) {
|
||||
_slots[i].amountText.text = "";
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class PlayerController : MonoBehaviour {
|
|||
public UsableItem SelectedItem {
|
||||
get => _selectedItem;
|
||||
set {
|
||||
if(_inventory.elements.ContainsKey(value)) {
|
||||
if(_inventory.Elements.ContainsKey(value)) {
|
||||
_selectedItem = value;
|
||||
Cursor.SetCursor(value.defaultSprite.texture, Vector2.zero, CursorMode.Auto);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ public class ShopSlot : ElementStorageSlot<Item> {
|
|||
nameText.text = "";
|
||||
costText.text = "";
|
||||
amountText.text = "";
|
||||
// _shop.RemoveItem(Item, 1);
|
||||
base.ClearSlot();
|
||||
}
|
||||
|
||||
|
|
|
|||
13
Assets/Scripts/ShopSwitcher.cs
Normal file
13
Assets/Scripts/ShopSwitcher.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class ShopSwitcher : MonoBehaviour {
|
||||
public Sprite animalShopSprite;
|
||||
public Sprite itemShopSprite;
|
||||
|
||||
public void SwitchShops() {
|
||||
// switch text in Shop Title
|
||||
// switch image on switch Button
|
||||
// turn off one content and turn on the other
|
||||
// remove undo purchase button when switching to an animal shop
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ShopSwitcher.cs.meta
Normal file
11
Assets/Scripts/ShopSwitcher.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 47545d0c6734b804c9407d5752a08ee4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -46,11 +46,11 @@ 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.elements.Count) {
|
||||
_slots[i].AddElement(_shop.elements.ElementAt(i).Key);
|
||||
if (i < _shop.Elements.Count) {
|
||||
_slots[i].AddElement(_shop.Elements.ElementAt(i).Key);
|
||||
_slots[i].nameText.text = _slots[i].Element.displayName;
|
||||
_slots[i].costText.text = _slots[i].Element.price + " µ";
|
||||
_slots[i].amountText.text = _shop.elements[_shop.elements.ElementAt(i).Key] + " #";
|
||||
_slots[i].amountText.text = _shop.Elements[_shop.Elements.ElementAt(i).Key] + " #";
|
||||
}
|
||||
else {
|
||||
_slots[i].ClearSlot();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue