Browse Source

Add proper money display to sell view

master
Devin 4 years ago
parent
commit
a3ed15078d
  1. 12
      Assets/Scenes/NewShop.unity
  2. 16
      Assets/Scripts/Shop/View/SellViewGrid.cs
  3. 11
      Assets/Scripts/Shop/View/SellViewGrid.cs.meta
  4. 21
      Assets/Scripts/Shop/View/SellViewList.cs
  5. 11
      Assets/Scripts/Shop/View/SellViewList.cs.meta
  6. 16
      Assets/Scripts/Shop/View/ShopView.cs
  7. 6
      Assets/Scripts/Shop/View/ShopViewGrid.cs
  8. 6
      Assets/Scripts/Shop/View/ShopViewList.cs

12
Assets/Scenes/NewShop.unity

@ -337,7 +337,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3} m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
view: {fileID: 336428456} view: {fileID: 0}
filter: 100 filter: 100
--- !u!114 &24632925 --- !u!114 &24632925
MonoBehaviour: MonoBehaviour:
@ -1543,7 +1543,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3} m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
view: {fileID: 336428456} view: {fileID: 0}
filter: 0 filter: 0
--- !u!114 &169548031 --- !u!114 &169548031
MonoBehaviour: MonoBehaviour:
@ -3592,7 +3592,7 @@ MonoBehaviour:
m_GameObject: {fileID: 336428454} m_GameObject: {fileID: 336428454}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: efb84f97477b1db43871b69a638f1ac2, type: 3} m_Script: {fileID: 11500000, guid: b11168ba444139f4cbb3adb089aaaea7, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemPrefab: {fileID: 1985633672282538121, guid: f7e4aca495e6b46c1b69e85db31ac803, itemPrefab: {fileID: 1985633672282538121, guid: f7e4aca495e6b46c1b69e85db31ac803,
@ -14710,7 +14710,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1296916388} m_GameObject: {fileID: 1296916388}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9a7a26539e5861144890978c82020e75, type: 3} m_Script: {fileID: 11500000, guid: 17fb0ea364bd0fa43a25e8def7820bdb, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemPrefab: {fileID: 6553243021197451808, guid: 2217ade0fb51b46daa2e279fbf1589d7, itemPrefab: {fileID: 6553243021197451808, guid: 2217ade0fb51b46daa2e279fbf1589d7,
@ -15198,7 +15198,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3} m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
view: {fileID: 336428456} view: {fileID: 0}
filter: 1 filter: 1
--- !u!114 &1371998400 --- !u!114 &1371998400
MonoBehaviour: MonoBehaviour:
@ -17028,7 +17028,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3} m_Script: {fileID: 11500000, guid: a5001818e381b2c4890a9f8b1d8c943e, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
view: {fileID: 336428456} view: {fileID: 0}
filter: 2 filter: 2
--- !u!114 &1484410839 --- !u!114 &1484410839
MonoBehaviour: MonoBehaviour:

16
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<InventoryMoneyDisplay>();
if (moneyComp != null) model.inventory.RegisterObserver(moneyComp); // We wanna see our own money!
}
}

11
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:

21
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;
/// <summary>
/// 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!
/// </summary>
public class SellViewList : ShopViewList
{
protected override void RegisterMoneyObserver()
{
var moneyComp = GetComponentInChildren<InventoryMoneyDisplay>();
if (moneyComp != null) model.inventory.RegisterObserver(moneyComp); // Same as grid sell view, we want to see our own money!
}
}

11
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:

16
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] 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 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 model; // Model in MVC pattern
protected ShopModel other; // Other model in MVC pattern (our own inventory) protected ShopModel other; // Other model in MVC pattern (our own inventory)
@ -50,11 +50,15 @@ public abstract class ShopView : MonoBehaviour
//model.Subscribe(this); //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() private void OnEnable()
{ {
// sanity check // sanity check
if (model == null) model = ownModel.Model; 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); model.SetTradePartner(tradePartner.Inventory);
PopulateItemIconView(); //Display items PopulateItemIconView(); //Display items
} }
@ -66,12 +70,8 @@ public abstract class ShopView : MonoBehaviour
UnregisterMoneyObserver(); 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 // The view should decide which inventory is used to display money. Who knows what might be needed!
private void RegisterMoneyObserver() protected abstract void RegisterMoneyObserver();
{
var moneyComp = GetComponentInChildren<InventoryMoneyDisplay>();
if (moneyComp != null) tradePartner.Inventory.RegisterObserver(moneyComp);
}
// Undo the above // Undo the above
private void UnregisterMoneyObserver() private void UnregisterMoneyObserver()

6
Assets/Scripts/Shop/View/ShopViewGrid.cs

@ -25,6 +25,12 @@ public class ShopViewGrid : ShopView, IShopModelObserver<Item>
print("ShopView Grid Initialised"); print("ShopView Grid Initialised");
} }
protected override void RegisterMoneyObserver()
{
var moneyComp = GetComponentInChildren<InventoryMoneyDisplay>();
if (moneyComp != null) tradePartner.Inventory.RegisterObserver(moneyComp);
}
protected override void SetupItemIconView() protected override void SetupItemIconView()
{ {
_gridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;//Set the constraint mode of the GridLayoutGroup _gridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;//Set the constraint mode of the GridLayoutGroup

6
Assets/Scripts/Shop/View/ShopViewList.cs

@ -33,6 +33,12 @@ public class ShopViewList : ShopView, IShopModelObserver<Item>
print("ShopView Grid Initialised"); print("ShopView Grid Initialised");
} }
protected override void RegisterMoneyObserver()
{
var moneyComp = GetComponentInChildren<InventoryMoneyDisplay>();
if (moneyComp != null) tradePartner.Inventory.RegisterObserver(moneyComp);
}
protected override void SetupItemIconView() protected override void SetupItemIconView()
{ {
//_listLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;//Set the constraint mode of the GridLayoutGroup //_listLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;//Set the constraint mode of the GridLayoutGroup

Loading…
Cancel
Save