diff --git a/Assets/Scenes/NewShop.unity b/Assets/Scenes/NewShop.unity index 9775ed8..7b51209 100644 --- a/Assets/Scenes/NewShop.unity +++ b/Assets/Scenes/NewShop.unity @@ -337,7 +337,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3} m_Name: m_EditorClassIdentifier: - view: {fileID: 336428456} + view: {fileID: 0} filter: 100 --- !u!114 &24632925 MonoBehaviour: @@ -1543,7 +1543,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3} m_Name: m_EditorClassIdentifier: - view: {fileID: 336428456} + view: {fileID: 0} filter: 0 --- !u!114 &169548031 MonoBehaviour: @@ -3592,7 +3592,7 @@ MonoBehaviour: m_GameObject: {fileID: 336428454} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: efb84f97477b1db43871b69a638f1ac2, type: 3} + m_Script: {fileID: 11500000, guid: b11168ba444139f4cbb3adb089aaaea7, type: 3} m_Name: m_EditorClassIdentifier: itemPrefab: {fileID: 1985633672282538121, guid: f7e4aca495e6b46c1b69e85db31ac803, @@ -14710,7 +14710,7 @@ MonoBehaviour: m_GameObject: {fileID: 1296916388} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9a7a26539e5861144890978c82020e75, type: 3} + m_Script: {fileID: 11500000, guid: 17fb0ea364bd0fa43a25e8def7820bdb, type: 3} m_Name: m_EditorClassIdentifier: itemPrefab: {fileID: 6553243021197451808, guid: 2217ade0fb51b46daa2e279fbf1589d7, @@ -15198,7 +15198,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3} m_Name: m_EditorClassIdentifier: - view: {fileID: 336428456} + view: {fileID: 0} filter: 1 --- !u!114 &1371998400 MonoBehaviour: @@ -17028,7 +17028,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3} m_Name: m_EditorClassIdentifier: - view: {fileID: 336428456} + view: {fileID: 0} filter: 2 --- !u!114 &1484410839 MonoBehaviour: diff --git a/Assets/Scripts/Shop/View/SellViewGrid.cs b/Assets/Scripts/Shop/View/SellViewGrid.cs new file mode 100644 index 0000000..541f222 --- /dev/null +++ b/Assets/Scripts/Shop/View/SellViewGrid.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Security.Permissions; +using UnityEngine; +using UnityEngine.Assertions; +using UnityEngine.UI; + +public class SellViewGrid : ShopViewGrid +{ + protected override void RegisterMoneyObserver() + { + var moneyComp = GetComponentInChildren(); + if (moneyComp != null) model.inventory.RegisterObserver(moneyComp); // We wanna see our own money! + } +} diff --git a/Assets/Scripts/Shop/View/SellViewGrid.cs.meta b/Assets/Scripts/Shop/View/SellViewGrid.cs.meta new file mode 100644 index 0000000..5c2109e --- /dev/null +++ b/Assets/Scripts/Shop/View/SellViewGrid.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b11168ba444139f4cbb3adb089aaaea7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Shop/View/SellViewList.cs b/Assets/Scripts/Shop/View/SellViewList.cs new file mode 100644 index 0000000..0cc85a7 --- /dev/null +++ b/Assets/Scripts/Shop/View/SellViewList.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Security.Permissions; +using UnityEditor; +using UnityEngine; +using UnityEngine.Assertions; +using UnityEngine.UI; + +/// +/// This view is meant to be used in conjunction with a list. Realistically, it is mostly similar to the grid view, +/// as both operate with prototypes! +/// +public class SellViewList : ShopViewList +{ + protected override void RegisterMoneyObserver() + { + var moneyComp = GetComponentInChildren(); + if (moneyComp != null) model.inventory.RegisterObserver(moneyComp); // Same as grid sell view, we want to see our own money! + } +} diff --git a/Assets/Scripts/Shop/View/SellViewList.cs.meta b/Assets/Scripts/Shop/View/SellViewList.cs.meta new file mode 100644 index 0000000..3a32094 --- /dev/null +++ b/Assets/Scripts/Shop/View/SellViewList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 17fb0ea364bd0fa43a25e8def7820bdb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Shop/View/ShopView.cs b/Assets/Scripts/Shop/View/ShopView.cs index 917ad54..02ee2d7 100644 --- a/Assets/Scripts/Shop/View/ShopView.cs +++ b/Assets/Scripts/Shop/View/ShopView.cs @@ -28,7 +28,7 @@ public abstract class ShopView : MonoBehaviour [SerializeField] protected LayoutGroup layoutGroup; // The layout group that represents this view visually [SerializeField] private ModelComponent ownModel; // Reference to the model this view technically belongs to - [SerializeField] private InventoryComponent tradePartner; // Reference to the model this view technically belongs to + [SerializeField] protected InventoryComponent tradePartner; // Reference to the model this view technically belongs to protected ShopModel model; // Model in MVC pattern protected ShopModel other; // Other model in MVC pattern (our own inventory) @@ -50,11 +50,15 @@ public abstract class ShopView : MonoBehaviour //model.Subscribe(this); } + private void Start() + { + RegisterMoneyObserver(); // Make sure if this thing's got a money component somewhere we register it as an observer for the inventory we're looking at + } + private void OnEnable() { // sanity check if (model == null) model = ownModel.Model; - RegisterMoneyObserver(); // Make sure if this thing's got a money component somewhere we register it as an observer for the inventory we're looking at model.SetTradePartner(tradePartner.Inventory); PopulateItemIconView(); //Display items } @@ -66,12 +70,8 @@ public abstract class ShopView : MonoBehaviour UnregisterMoneyObserver(); } - // If view is generic, and shopview was just an implementation, this would be more flexible in theory. But for now it's enough to just manually assign "ourselves" as trade partner if we know the model works on just one inventory - private void RegisterMoneyObserver() - { - var moneyComp = GetComponentInChildren(); - if (moneyComp != null) tradePartner.Inventory.RegisterObserver(moneyComp); - } + // The view should decide which inventory is used to display money. Who knows what might be needed! + protected abstract void RegisterMoneyObserver(); // Undo the above private void UnregisterMoneyObserver() diff --git a/Assets/Scripts/Shop/View/ShopViewGrid.cs b/Assets/Scripts/Shop/View/ShopViewGrid.cs index 3776890..b1e8726 100644 --- a/Assets/Scripts/Shop/View/ShopViewGrid.cs +++ b/Assets/Scripts/Shop/View/ShopViewGrid.cs @@ -25,6 +25,12 @@ public class ShopViewGrid : ShopView, IShopModelObserver print("ShopView Grid Initialised"); } + protected override void RegisterMoneyObserver() + { + var moneyComp = GetComponentInChildren(); + if (moneyComp != null) tradePartner.Inventory.RegisterObserver(moneyComp); + } + protected override void SetupItemIconView() { _gridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;//Set the constraint mode of the GridLayoutGroup diff --git a/Assets/Scripts/Shop/View/ShopViewList.cs b/Assets/Scripts/Shop/View/ShopViewList.cs index c1a7c6a..35019c2 100644 --- a/Assets/Scripts/Shop/View/ShopViewList.cs +++ b/Assets/Scripts/Shop/View/ShopViewList.cs @@ -33,6 +33,12 @@ public class ShopViewList : ShopView, IShopModelObserver print("ShopView Grid Initialised"); } + protected override void RegisterMoneyObserver() + { + var moneyComp = GetComponentInChildren(); + if (moneyComp != null) tradePartner.Inventory.RegisterObserver(moneyComp); + } + protected override void SetupItemIconView() { //_listLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;//Set the constraint mode of the GridLayoutGroup