Shop fix II

This commit is contained in:
kabix09 2022-12-21 12:19:57 +01:00
parent 29a13e824f
commit 2280e5fc15
7 changed files with 34 additions and 24 deletions

View File

@ -20,6 +20,8 @@ public class NpcShopManager : MonoBehaviour
bool CanShopBeOpened = false;
bool IsRegistered = false;
public void Awake()
{
gameObject.GetComponent<NpcDialogueManager>().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<NPC>().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<NPC>().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()

View File

@ -20,11 +20,9 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
{
if (Instance == null)
{
Debug.Log("Create: " + gameObject);
Instance = this;
Start();
//Start();
}
else
{
@ -80,6 +78,8 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
protected override void UseDefaultSettings()
{
DynamicDataList.SetList(new List<Shop>());
UiManager.SetList(new List<Shop>());
// 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<Shop>
LoadDynamicData();
// VERy VERY provisional SOLUTION
if (DynamicDataList.GetList().Count == 0)
{
@ -106,6 +105,7 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
// 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<Shop>
// 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);

View File

@ -17,7 +17,7 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
/// </summary>
[SerializeField] protected List<T> Elements = new List<T>(); // { get; set; } - this block inspector
public void Awake()
public virtual void Awake()
{
if (Instance == null)
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -20,7 +20,7 @@ public class ShopUIManager : UIBaseManager<Shop>
[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<Shop>
}
else
{
Debug.Log("Destroy " + gameObject);
Destroy(gameObject);
}
}

View File

@ -11,7 +11,7 @@ public class TaskUIManager : UIBaseManager<Task>
public static new TaskUIManager Instance { get; protected set; }
public void Awake()
public override void Awake()
{
if (Instance == null)
{