2022-12-19 03:34:45 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class ShopUIManager : UIBaseManager<Shop>
|
|
|
|
{
|
|
|
|
public new static ShopUIManager Instance { get; private set; }
|
|
|
|
|
|
|
|
public const string ITEM_LOCALIZATION = "UiPanels/Shop/";
|
|
|
|
public const string PANEL_NAME = "ShopPanel";
|
|
|
|
//public int SLOTS_NUMBER => 24;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Keys pair to detect chest
|
|
|
|
/// </summary>
|
|
|
|
[Space]
|
|
|
|
[Header("Current shop unique keys")]
|
|
|
|
public string CurrentShopOwnerName = null; // OR NPC NAME
|
|
|
|
|
2022-12-21 12:19:57 +01:00
|
|
|
public override void Awake()
|
2022-12-19 03:34:45 +01:00
|
|
|
{
|
|
|
|
if (Instance == null)
|
|
|
|
{
|
|
|
|
Instance = this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-21 12:19:57 +01:00
|
|
|
Debug.Log("Destroy " + gameObject);
|
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
}
|
2022-12-29 00:56:54 +01:00
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
public override bool OpenPanel()
|
|
|
|
{
|
|
|
|
if (CurrentShopOwnerName == null || CurrentShopOwnerName == "")
|
|
|
|
{
|
|
|
|
Debug.Log($"You re not in range of any shop");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-29 00:56:54 +01:00
|
|
|
|
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
// Open additionals panels
|
|
|
|
if (!InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.OpenPanel();
|
|
|
|
|
|
|
|
return base.OpenPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool ClosePanel()
|
|
|
|
{
|
|
|
|
base.ClosePanel();
|
|
|
|
|
|
|
|
ShopContentUIManager.Instance.DynamicPanel = null;
|
|
|
|
|
2022-12-20 03:30:37 +01:00
|
|
|
CurrentShopOwnerName = "";
|
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
// Close additionals panels
|
|
|
|
if (InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.ClosePanel();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetupPanel()
|
|
|
|
{
|
|
|
|
base.SetupPanel();
|
|
|
|
|
|
|
|
var shop = FindShopInCollection(SceneManager.GetActiveScene().name, CurrentShopOwnerName);
|
|
|
|
if (shop == null)
|
|
|
|
throw new Exception($"Shop {CurrentShopOwnerName} not found");
|
|
|
|
|
|
|
|
|
|
|
|
ShopContentUIManager.Instance.SetList(shop.GetContent());
|
|
|
|
ShopContentUIManager.Instance.DynamicPanel = DynamicPanel;
|
|
|
|
ShopContentUIManager.Instance.SetupPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void UpdateList()
|
|
|
|
{
|
|
|
|
if (CurrentShopOwnerName == null || CurrentShopOwnerName == "")
|
|
|
|
throw new Exception($"You re not in collision with any chest");
|
|
|
|
|
|
|
|
|
|
|
|
var shop = FindShopInCollection(SceneManager.GetActiveScene().name, CurrentShopOwnerName);
|
|
|
|
if (shop == null)
|
|
|
|
throw new Exception($"Chest {CurrentShopOwnerName} not found");
|
|
|
|
|
|
|
|
ShopContentUIManager.Instance.SetList(shop.GetContent());
|
|
|
|
ShopContentUIManager.Instance.DynamicPanel = DynamicPanel;
|
|
|
|
ShopContentUIManager.Instance.UpdateList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateShopContent(string mapName, string shopOwnerName, List<IndexValuePair<int, EquippableItem>> chestContent)
|
|
|
|
{
|
|
|
|
Elements.Where(shop => shop.Map == mapName && shop.Npc == shopOwnerName).ToList().ForEach(shop => shop.SetContent(chestContent));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override GameObject GetTemplatePanel()
|
|
|
|
{
|
|
|
|
// Resources = default path - Asset/Resources ... .obj
|
|
|
|
return Resources.Load(ITEM_LOCALIZATION + PANEL_NAME) as GameObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Shop FindShopInCollection(string _mapName, string _shopOwnerName)
|
|
|
|
{
|
|
|
|
return Elements.Find(shop => shop.Map == _mapName && shop.Npc == _shopOwnerName);
|
|
|
|
}
|
|
|
|
}
|