diff --git a/Assets/Prefabs/GridViewItem.prefab b/Assets/Prefabs/GridViewItem.prefab
index 053ba74..14e91a1 100644
--- a/Assets/Prefabs/GridViewItem.prefab
+++ b/Assets/Prefabs/GridViewItem.prefab
@@ -135,6 +135,7 @@ GameObject:
- component: {fileID: 1355062804588728591}
- component: {fileID: 6276336569359545557}
- component: {fileID: 4391249473562572445}
+ - component: {fileID: 2521131620876806752}
m_Layer: 5
m_Name: Name
m_TagString: Untagged
@@ -280,6 +281,18 @@ MonoBehaviour:
- {fileID: 0}
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
+--- !u!114 &2521131620876806752
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1245163151616179787}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: f1bf98089f9db1b4aacb219d05609744, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
--- !u!1 &1522873078225282773
GameObject:
m_ObjectHideFlags: 0
diff --git a/Assets/Scripts/Shop/Components.meta b/Assets/Scripts/Shop/Components.meta
new file mode 100644
index 0000000..5084472
--- /dev/null
+++ b/Assets/Scripts/Shop/Components.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: fa069fdb6941fa247b6d3ca2cfcc0307
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Shop/Components/ItemNameDisplay.cs b/Assets/Scripts/Shop/Components/ItemNameDisplay.cs
new file mode 100644
index 0000000..4c44dee
--- /dev/null
+++ b/Assets/Scripts/Shop/Components/ItemNameDisplay.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using TMPro;
+using UnityEngine;
+
+///
+/// This class' only purpose is to set the name of an item view prototype. Could be the item itself, or the infobox, or anything!
+///
+[RequireComponent(typeof(TextMeshProUGUI))]
+public class ItemNameDisplay : MonoBehaviour
+{
+ private TextMeshProUGUI text;
+ private void Start()
+ {
+ text = GetComponent(); // Because of the meta tag, Unity will make sure this exists. No sanity checks
+ }
+
+ public void SetName(string name)
+ {
+ if(text == null) text = GetComponent(); // Just in case this gets called before Start()
+ text.text = name;
+ }
+}
diff --git a/Assets/Scripts/Shop/Components/ItemNameDisplay.cs.meta b/Assets/Scripts/Shop/Components/ItemNameDisplay.cs.meta
new file mode 100644
index 0000000..8d6379c
--- /dev/null
+++ b/Assets/Scripts/Shop/Components/ItemNameDisplay.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f1bf98089f9db1b4aacb219d05609744
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Shop/Controller/MouseController.cs b/Assets/Scripts/Shop/Controller/MouseController.cs
index d027dc8..629f043 100644
--- a/Assets/Scripts/Shop/Controller/MouseController.cs
+++ b/Assets/Scripts/Shop/Controller/MouseController.cs
@@ -25,8 +25,9 @@ public class MouseController : ShopController, IPointerClickHandler
{
if (itemToSelect != null)
{
- SelectItem(itemToSelect);
+ var item = itemToSelect; // Temporarily remember the selected item
itemToSelect = null;//Now that the item was selected, set itemToSelect back to null
+ SelectItem(item); // Use the item we remembered, so itemToSelect can be reset even in case of errors or so
}
}
diff --git a/Assets/Scripts/Shop/Model/BuyModel.cs b/Assets/Scripts/Shop/Model/BuyModel.cs
index 32c4946..5279035 100644
--- a/Assets/Scripts/Shop/Model/BuyModel.cs
+++ b/Assets/Scripts/Shop/Model/BuyModel.cs
@@ -18,9 +18,9 @@ public class BuyModel : ShopModel
public override void ConfirmSelectedItem()
{
- OnRemove(GetSelectedItem()); // If there's a view subscribed, this will probably remove the item from it
inventory.RemoveItemByIndex(selectedItemIndex); // Before removing the item from the model's actual inventory
- SelectItemByIndex(--selectedItemIndex);
+ OnRemove(GetSelectedItem()); // If there's a view subscribed, this will probably remove the item from it
+ SelectItemByIndex(selectedItemIndex > inventory.GetItemCount() ? --selectedItemIndex : selectedItemIndex);
}
}
diff --git a/Assets/Scripts/Shop/Model/ShopModel.cs b/Assets/Scripts/Shop/Model/ShopModel.cs
index 5d325d1..fb056c6 100644
--- a/Assets/Scripts/Shop/Model/ShopModel.cs
+++ b/Assets/Scripts/Shop/Model/ShopModel.cs
@@ -108,7 +108,9 @@ public abstract class ShopModel : IModelObservable-
public void OnRemove(Item val)
{
- foreach (var observer in observers)
+ // We copy the list so we don't break it while iterating, as it's likely OnRemove will cause an object to unsub
+ var observerCopy = observers.ToArray();
+ foreach (var observer in observerCopy)
observer.OnRemoved(val);
}
diff --git a/Assets/Scripts/Shop/View/ViewItemContainer.cs b/Assets/Scripts/Shop/View/ViewItemContainer.cs
index 2dbbb1e..2806750 100644
--- a/Assets/Scripts/Shop/View/ViewItemContainer.cs
+++ b/Assets/Scripts/Shop/View/ViewItemContainer.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using TMPro;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
using UnityEngine.UI;
@@ -50,6 +51,7 @@ public class ViewItemContainer : MonoBehaviour, IItemContainer, IShopModelObserv
//Stores the item
this.item = item;
+ _unsubscriber = unsubscriber;
//Sets the highlight image and infoPanel's visibility
//if (isSelected) {
// highLight.SetActive(true);
@@ -58,6 +60,13 @@ public class ViewItemContainer : MonoBehaviour, IItemContainer, IShopModelObserv
// Clones the first Sprite in the icon atlas that matches the iconName and uses it as the sprite of the icon image.
Sprite sprite = iconAtlas.GetSprite(item.iconName);
+
+ // Sets name in all locations the prototype has a name component attached to
+ var nameComps = GetComponentsInChildren(true); // Include inactives!
+ foreach (var name in nameComps)
+ {
+ name.SetName(item.iconName); // Use iconname for now, debugging
+ }
if (sprite != null) {
icon.sprite = sprite;
@@ -73,7 +82,7 @@ public class ViewItemContainer : MonoBehaviour, IItemContainer, IShopModelObserv
public void OnRemoved(Item item)
{
if (item != Item) return; // Well we only want this if the item removed from the model is actually ours!
- _unsubscriber?.Dispose(); // Careful! If we don't make this thing aware that it manages itself, and we forget to manage it, we have a memory leak
+ _unsubscriber.Dispose(); // Careful! If we don't make this thing aware that it manages itself, and we forget to manage it, we have a memory leak
Destroy(gameObject);
}
diff --git a/Assets/Sprites/LeftArrow.png b/Assets/Sprites/LeftArrow.png
index de15c42..3d625f7 100644
Binary files a/Assets/Sprites/LeftArrow.png and b/Assets/Sprites/LeftArrow.png differ
diff --git a/Assets/Sprites/RightArrow.png b/Assets/Sprites/RightArrow.png
index 0bfc9ac..eef306d 100644
Binary files a/Assets/Sprites/RightArrow.png and b/Assets/Sprites/RightArrow.png differ
diff --git a/Assets/Unity Packages/TextMesh Pro/Fonts/LiberationSans.ttf b/Assets/Unity Packages/TextMesh Pro/Fonts/LiberationSans.ttf
index 626dd93..0d896af 100644
Binary files a/Assets/Unity Packages/TextMesh Pro/Fonts/LiberationSans.ttf and b/Assets/Unity Packages/TextMesh Pro/Fonts/LiberationSans.ttf differ
diff --git a/Assets/Unity Packages/TextMesh Pro/Sprites/EmojiOne.png b/Assets/Unity Packages/TextMesh Pro/Sprites/EmojiOne.png
index 4adb015..f4162d7 100644
Binary files a/Assets/Unity Packages/TextMesh Pro/Sprites/EmojiOne.png and b/Assets/Unity Packages/TextMesh Pro/Sprites/EmojiOne.png differ