2022-11-19 17:02:31 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class ChestUIManager : UIBaseManager<Chest>
|
|
|
|
|
{
|
|
|
|
|
public new static ChestUIManager Instance { get; private set; }
|
|
|
|
|
|
|
|
|
|
public const string ITEM_LOCALIZATION = "UiPanels/";
|
|
|
|
|
public const string PANEL_NAME = "ChestPanel";
|
|
|
|
|
public int SLOTS_NUMBER => 48;
|
|
|
|
|
|
|
|
|
|
public string CurrentChestName = null;
|
|
|
|
|
|
|
|
|
|
public void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (Instance == null)
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-29 00:56:54 +01:00
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
|
|
|
|
|
|
public override bool OpenPanel()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentChestName == null || CurrentChestName == "")
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"You re not in collision with any chest");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
// Open additiona panels
|
|
|
|
|
if (!EquipmentUIManager.Instance.GetPanelStatus()) EquipmentUIManager.Instance.OpenPanel();
|
|
|
|
|
|
|
|
|
|
if (!InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.OpenPanel();
|
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
|
return base.OpenPanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool ClosePanel()
|
|
|
|
|
{
|
|
|
|
|
base.ClosePanel();
|
|
|
|
|
|
|
|
|
|
ChestContentUIManager.Instance.DynamicPanel = null;
|
|
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
|
// Close additionals panels
|
|
|
|
|
if (EquipmentUIManager.Instance.GetPanelStatus()) EquipmentUIManager.Instance.ClosePanel();
|
|
|
|
|
|
|
|
|
|
if (InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.ClosePanel();
|
|
|
|
|
|
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetupPanel()
|
|
|
|
|
{
|
|
|
|
|
base.SetupPanel();
|
|
|
|
|
|
|
|
|
|
var chest = FindChestInCollection(CurrentChestName);
|
|
|
|
|
if (chest == null)
|
|
|
|
|
throw new Exception($"Chest {CurrentChestName} not found");
|
|
|
|
|
|
|
|
|
|
ChestContentUIManager.Instance.SetList(chest.GetContent());
|
|
|
|
|
ChestContentUIManager.Instance.DynamicPanel = DynamicPanel;
|
|
|
|
|
ChestContentUIManager.Instance.SetupPanel();
|
|
|
|
|
|
|
|
|
|
// setup models list
|
|
|
|
|
//DynamicPanel.GetComponent<ChestPanelController>().SetUp(chest.GetContent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UpdateList()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentChestName == null || CurrentChestName == "")
|
|
|
|
|
throw new Exception($"You re not in collision with any chest");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var chest = FindChestInCollection(CurrentChestName);
|
|
|
|
|
if (chest == null)
|
|
|
|
|
throw new Exception($"Chest {CurrentChestName} not found");
|
|
|
|
|
|
|
|
|
|
ChestContentUIManager.Instance.SetList(chest.GetContent());
|
|
|
|
|
ChestContentUIManager.Instance.DynamicPanel = DynamicPanel;
|
|
|
|
|
ChestContentUIManager.Instance.UpdateList();
|
|
|
|
|
|
|
|
|
|
//DynamicPanel.GetComponent<ChestPanelController>().BuildPanelContent(chest.GetContent());
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 03:03:30 +01:00
|
|
|
|
public void UpdateChestContent(string chestName, List<IndexValuePair<int, EquippableItem>> chestContent)
|
2022-11-19 17:02:31 +01:00
|
|
|
|
{
|
|
|
|
|
Elements.Where(chest => chest.name == chestName).ToList().ForEach(chest => chest.SetContent(chestContent));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override GameObject GetTemplatePanel()
|
|
|
|
|
{
|
|
|
|
|
// Resources = default path - Asset/Resources ... .obj
|
|
|
|
|
return Resources.Load(ITEM_LOCALIZATION + PANEL_NAME) as GameObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Chest FindChestInCollection(string _chestName)
|
|
|
|
|
{
|
|
|
|
|
return Elements.Find(chest => chest.Name == _chestName);
|
|
|
|
|
}
|
|
|
|
|
}
|