From 2280e5fc150f4a75d93df8393d72e597091eebb1 Mon Sep 17 00:00:00 2001 From: kabix09 Date: Wed, 21 Dec 2022 12:19:57 +0100 Subject: [PATCH] Shop fix II --- .../Application/NPC/NpcShopManager.cs | 36 +++++++++++-------- .../Panel/Shop/SceneShopDataManager.cs | 10 +++--- .../Shared/Manager/UI/UIBaseManager.cs | 2 +- .../UI/Inventory/InventoryUIManager.cs | 2 +- .../UI/Shop/ShopContentUIManager.cs | 2 +- .../Application/UI/Shop/ShopUIManager.cs | 4 ++- .../Application/UI/Task/TaskUIManager.cs | 2 +- 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Assets/Scripts/REFACTORING/Application/NPC/NpcShopManager.cs b/Assets/Scripts/REFACTORING/Application/NPC/NpcShopManager.cs index 97000a7b..89deb3b3 100644 --- a/Assets/Scripts/REFACTORING/Application/NPC/NpcShopManager.cs +++ b/Assets/Scripts/REFACTORING/Application/NPC/NpcShopManager.cs @@ -20,6 +20,8 @@ public class NpcShopManager : MonoBehaviour bool CanShopBeOpened = false; + bool IsRegistered = false; + public void Awake() { gameObject.GetComponent().OpenInDefaultWay = false; @@ -32,24 +34,28 @@ public class NpcShopManager : MonoBehaviour // 2. Init dialogue model CreateInstanceBasedOnLanguage(); - - //this.RegisterShop(); - // if its new game or we dont have any save from this map - use deffault shop settings / content - // else overwrite value by saved one - if (OnMapAppearanceMethod.GameStatus == GameStatus.NewGame || - (OnMapAppearanceMethod.Gateway != OnMapAppearanceMethodEnum.NewGame || ShopUIManager.Instance.GetList().Count == 0) - ) - // 0. Register shop in scene shop manager - this.RegisterShop(); - //ShopUIManager.Instance.Add(shop); - else - shop = ShopUIManager.Instance.GetList().Where(shop => { - return shop.Npc == gameObject.GetComponent().name && shop.Map == SceneManager.GetActiveScene().name; - }).First(); } public void Update() { + if(!IsRegistered) + { + // if its new game or we dont have any save from this map - use deffault shop settings / content + // else overwrite value by saved one + if (OnMapAppearanceMethod.GameStatus == GameStatus.NewGame || + (OnMapAppearanceMethod.Gateway != OnMapAppearanceMethodEnum.NewGame || ShopUIManager.Instance.GetList().Count == 0) + ) { + // 0. Register shop in scene shop manager + this.RegisterShop(); + //ShopUIManager.Instance.Add(shop); + } + else + shop = ShopUIManager.Instance.GetList().Where(shop => { + return shop.Npc == gameObject.GetComponent().name && shop.Map == SceneManager.GetActiveScene().name; + }).First(); + + IsRegistered = true; + } /* * Conditions: * - player must be in range of shopping @@ -123,6 +129,8 @@ public class NpcShopManager : MonoBehaviour shop.GetContent() ) ); + + Debug.Log($"Shop {shop.Npc} registered"); } public void OpenShop() diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Shop/SceneShopDataManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Shop/SceneShopDataManager.cs index 275b878a..11482062 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Shop/SceneShopDataManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Shop/SceneShopDataManager.cs @@ -20,11 +20,9 @@ public class SceneShopDataManager : SceneBaseDataManager { if (Instance == null) { - Debug.Log("Create: " + gameObject); - Instance = this; - Start(); + //Start(); } else { @@ -80,6 +78,8 @@ public class SceneShopDataManager : SceneBaseDataManager protected override void UseDefaultSettings() { + DynamicDataList.SetList(new List()); + UiManager.SetList(new List()); // we dont need to convert anything // Instead of build elements on scene we collect shops distracted on scene from npc's } @@ -92,7 +92,6 @@ public class SceneShopDataManager : SceneBaseDataManager LoadDynamicData(); - // VERy VERY provisional SOLUTION if (DynamicDataList.GetList().Count == 0) { @@ -106,6 +105,7 @@ public class SceneShopDataManager : SceneBaseDataManager // TODO SHOP API public void RegisterShop(Shop newShop) { + Debug.Log(DynamicDataList); if (DynamicDataList.GetList().Where(shop => shop.Npc == newShop.Npc && shop.Map == SceneManager.GetActiveScene().name).Any()) Debug.LogError("In Shop Manager there is register this shop already"); else @@ -134,7 +134,7 @@ public class SceneShopDataManager : SceneBaseDataManager // TODO // how to get list // 1. List in UI manager should be synchronized with list in this manager - + Debug.Log(UiManager); foreach (Shop shop in UiManager.GetList()) { DynamicDataList.GetList().Where(el => el.Map == shop.Map && el.Npc == shop.Npc).ToList().ForEach(el => el = shop); diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIBaseManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIBaseManager.cs index 798fc9ee..719bbdc6 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIBaseManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIBaseManager.cs @@ -17,7 +17,7 @@ public abstract class UIBaseManager : MonoBehaviour, ManagerInterface /// [SerializeField] protected List Elements = new List(); // { get; set; } - this block inspector - public void Awake() + public virtual void Awake() { if (Instance == null) { diff --git a/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs b/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs index 28b11f72..89b9c144 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs @@ -12,7 +12,7 @@ public class InventoryUIManager : UIWarehouseManager public const string ITEM_LOCALIZATION = "UiPanels/"; public const string PANEL_NAME = "InventoryPanel"; - public void Awake() + public override void Awake() { if (Instance == null) { diff --git a/Assets/Scripts/REFACTORING/Application/UI/Shop/ShopContentUIManager.cs b/Assets/Scripts/REFACTORING/Application/UI/Shop/ShopContentUIManager.cs index 69e2c670..dc76f81a 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Shop/ShopContentUIManager.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Shop/ShopContentUIManager.cs @@ -12,7 +12,7 @@ public class ShopContentUIManager : UIWarehouseManager public const string ITEM_LOCALIZATION = "UiPanels/"; public const string PANEL_NAME = null; - public void Awake() + public override void Awake() { if (Instance == null) { diff --git a/Assets/Scripts/REFACTORING/Application/UI/Shop/ShopUIManager.cs b/Assets/Scripts/REFACTORING/Application/UI/Shop/ShopUIManager.cs index 5739b989..ed74ae16 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Shop/ShopUIManager.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Shop/ShopUIManager.cs @@ -20,7 +20,7 @@ public class ShopUIManager : UIBaseManager [Header("Current shop unique keys")] public string CurrentShopOwnerName = null; // OR NPC NAME - public void Awake() + public override void Awake() { if (Instance == null) { @@ -28,6 +28,8 @@ public class ShopUIManager : UIBaseManager } else { + Debug.Log("Destroy " + gameObject); + Destroy(gameObject); } } diff --git a/Assets/Scripts/REFACTORING/Application/UI/Task/TaskUIManager.cs b/Assets/Scripts/REFACTORING/Application/UI/Task/TaskUIManager.cs index a0de8505..436ed2b0 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Task/TaskUIManager.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Task/TaskUIManager.cs @@ -11,7 +11,7 @@ public class TaskUIManager : UIBaseManager public static new TaskUIManager Instance { get; protected set; } - public void Awake() + public override void Awake() { if (Instance == null) {