Shop fix II
This commit is contained in:
parent
29a13e824f
commit
2280e5fc15
@ -20,6 +20,8 @@ public class NpcShopManager : MonoBehaviour
|
|||||||
|
|
||||||
bool CanShopBeOpened = false;
|
bool CanShopBeOpened = false;
|
||||||
|
|
||||||
|
bool IsRegistered = false;
|
||||||
|
|
||||||
public void Awake()
|
public void Awake()
|
||||||
{
|
{
|
||||||
gameObject.GetComponent<NpcDialogueManager>().OpenInDefaultWay = false;
|
gameObject.GetComponent<NpcDialogueManager>().OpenInDefaultWay = false;
|
||||||
@ -32,24 +34,28 @@ public class NpcShopManager : MonoBehaviour
|
|||||||
|
|
||||||
// 2. Init dialogue model
|
// 2. Init dialogue model
|
||||||
CreateInstanceBasedOnLanguage();
|
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()
|
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:
|
* Conditions:
|
||||||
* - player must be in range of shopping
|
* - player must be in range of shopping
|
||||||
@ -123,6 +129,8 @@ public class NpcShopManager : MonoBehaviour
|
|||||||
shop.GetContent()
|
shop.GetContent()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Debug.Log($"Shop {shop.Npc} registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenShop()
|
public void OpenShop()
|
||||||
|
@ -20,11 +20,9 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
|
|||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
Debug.Log("Create: " + gameObject);
|
|
||||||
|
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
|
||||||
Start();
|
//Start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -80,6 +78,8 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
|
|||||||
|
|
||||||
protected override void UseDefaultSettings()
|
protected override void UseDefaultSettings()
|
||||||
{
|
{
|
||||||
|
DynamicDataList.SetList(new List<Shop>());
|
||||||
|
UiManager.SetList(new List<Shop>());
|
||||||
// we dont need to convert anything
|
// we dont need to convert anything
|
||||||
// Instead of build elements on scene we collect shops distracted on scene from npc's
|
// 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();
|
LoadDynamicData();
|
||||||
|
|
||||||
|
|
||||||
// VERy VERY provisional SOLUTION
|
// VERy VERY provisional SOLUTION
|
||||||
if (DynamicDataList.GetList().Count == 0)
|
if (DynamicDataList.GetList().Count == 0)
|
||||||
{
|
{
|
||||||
@ -106,6 +105,7 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
|
|||||||
// TODO SHOP API
|
// TODO SHOP API
|
||||||
public void RegisterShop(Shop newShop)
|
public void RegisterShop(Shop newShop)
|
||||||
{
|
{
|
||||||
|
Debug.Log(DynamicDataList);
|
||||||
if (DynamicDataList.GetList().Where(shop => shop.Npc == newShop.Npc && shop.Map == SceneManager.GetActiveScene().name).Any())
|
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");
|
Debug.LogError("In Shop Manager there is register this shop already");
|
||||||
else
|
else
|
||||||
@ -134,7 +134,7 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
|
|||||||
// TODO
|
// TODO
|
||||||
// how to get list
|
// how to get list
|
||||||
// 1. List in UI manager should be synchronized with list in this manager
|
// 1. List in UI manager should be synchronized with list in this manager
|
||||||
|
Debug.Log(UiManager);
|
||||||
foreach (Shop shop in UiManager.GetList())
|
foreach (Shop shop in UiManager.GetList())
|
||||||
{
|
{
|
||||||
DynamicDataList.GetList().Where(el => el.Map == shop.Map && el.Npc == shop.Npc).ToList().ForEach(el => el = shop);
|
DynamicDataList.GetList().Where(el => el.Map == shop.Map && el.Npc == shop.Npc).ToList().ForEach(el => el = shop);
|
||||||
|
@ -17,7 +17,7 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeField] protected List<T> Elements = new List<T>(); // { get; set; } - this block inspector
|
[SerializeField] protected List<T> Elements = new List<T>(); // { get; set; } - this block inspector
|
||||||
|
|
||||||
public void Awake()
|
public virtual void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ public class InventoryUIManager : UIWarehouseManager
|
|||||||
public const string ITEM_LOCALIZATION = "UiPanels/";
|
public const string ITEM_LOCALIZATION = "UiPanels/";
|
||||||
public const string PANEL_NAME = "InventoryPanel";
|
public const string PANEL_NAME = "InventoryPanel";
|
||||||
|
|
||||||
public void Awake()
|
public override void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ public class ShopContentUIManager : UIWarehouseManager
|
|||||||
public const string ITEM_LOCALIZATION = "UiPanels/";
|
public const string ITEM_LOCALIZATION = "UiPanels/";
|
||||||
public const string PANEL_NAME = null;
|
public const string PANEL_NAME = null;
|
||||||
|
|
||||||
public void Awake()
|
public override void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ public class ShopUIManager : UIBaseManager<Shop>
|
|||||||
[Header("Current shop unique keys")]
|
[Header("Current shop unique keys")]
|
||||||
public string CurrentShopOwnerName = null; // OR NPC NAME
|
public string CurrentShopOwnerName = null; // OR NPC NAME
|
||||||
|
|
||||||
public void Awake()
|
public override void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
@ -28,6 +28,8 @@ public class ShopUIManager : UIBaseManager<Shop>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Debug.Log("Destroy " + gameObject);
|
||||||
|
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ public class TaskUIManager : UIBaseManager<Task>
|
|||||||
|
|
||||||
public static new TaskUIManager Instance { get; protected set; }
|
public static new TaskUIManager Instance { get; protected set; }
|
||||||
|
|
||||||
public void Awake()
|
public override void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user