From d4a2413a9b4fedfa083b8de37c48cd2364f05331 Mon Sep 17 00:00:00 2001 From: Devin Date: Tue, 16 Nov 2021 19:47:59 +0100 Subject: [PATCH] Fix upgrade view not updating price until refresh --- Assets/Scenes/NewShop.unity | 10 +++++----- Assets/Scripts/Shop/View/ViewItemContainer.cs | 10 +++++----- Assets/Scripts/Shop/View/ViewItemContainerGrid.cs | 5 +++++ Assets/Scripts/Shop/View/ViewItemContainerList.cs | 5 +++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Assets/Scenes/NewShop.unity b/Assets/Scenes/NewShop.unity index edf42f7..6115634 100644 --- a/Assets/Scenes/NewShop.unity +++ b/Assets/Scenes/NewShop.unity @@ -8546,7 +8546,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &842666263 RectTransform: m_ObjectHideFlags: 0 @@ -10426,7 +10426,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Sell + m_text: Upgrade m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -10495,7 +10495,7 @@ MonoBehaviour: m_margin: {x: 0, y: 0, z: 0, w: 0} m_textInfo: textComponent: {fileID: 970726939} - characterCount: 3 + characterCount: 4 spriteCount: 0 spaceCount: 0 wordCount: 1 @@ -15726,7 +15726,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1396837741 RectTransform: m_ObjectHideFlags: 0 @@ -16571,7 +16571,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Sell + m_text: Upgrade m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} diff --git a/Assets/Scripts/Shop/View/ViewItemContainer.cs b/Assets/Scripts/Shop/View/ViewItemContainer.cs index 1c762e7..eb20bb8 100644 --- a/Assets/Scripts/Shop/View/ViewItemContainer.cs +++ b/Assets/Scripts/Shop/View/ViewItemContainer.cs @@ -63,26 +63,26 @@ public abstract class ViewItemContainer : MonoBehaviour, IItemContainer, IShopMo protected abstract void OnInitialize(Item item, ShopModel owner = null); // When the observable fires, check if we're the view corresponding to the selected item. Select if we are! - public void OnSelected(Item item) + public virtual void OnSelected(Item item) { IsSelected = this.item == item; } - public void OnRemoved(Item item) + public virtual void OnRemoved(Item item) { if (item != Item) return; // Well we only want this if the item removed from the model is actually ours! IsSelected = false; // Kind of pointless, but won't hurt Destroy(gameObject); } - public void OnAdded(Item item) + public virtual void OnAdded(Item item) { throw new NotImplementedException(); } - public void OnTransaction(int cost) + public virtual void OnTransaction(int cost) { - //throw new NotImplementedException(); Irrelevant for the view containers + } // The reason we do this in OnDestroy() is so we don't have a memory leak when this gets removed externally somehow diff --git a/Assets/Scripts/Shop/View/ViewItemContainerGrid.cs b/Assets/Scripts/Shop/View/ViewItemContainerGrid.cs index d5b4970..70e3b83 100644 --- a/Assets/Scripts/Shop/View/ViewItemContainerGrid.cs +++ b/Assets/Scripts/Shop/View/ViewItemContainerGrid.cs @@ -25,4 +25,9 @@ public class ViewItemContainerGrid : ViewItemContainer { infoPanel.SetItemInfo(item, owner); // Grid info comes with a panel, so we set its info just once } + + public override void OnTransaction(int balance) + { + infoPanel.Refresh(); + } } diff --git a/Assets/Scripts/Shop/View/ViewItemContainerList.cs b/Assets/Scripts/Shop/View/ViewItemContainerList.cs index 3904ea8..198ed64 100644 --- a/Assets/Scripts/Shop/View/ViewItemContainerList.cs +++ b/Assets/Scripts/Shop/View/ViewItemContainerList.cs @@ -25,4 +25,9 @@ public class ViewItemContainerList : ViewItemContainer itemInfo = GetComponent(); itemInfo?.SetItemInfo(item,owner); } + + public override void OnTransaction(int balance) + { + itemInfo.Refresh(); + } }