Scriptum/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs

115 lines
3.3 KiB
C#
Raw Normal View History

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);
}
}
2023-01-05 01:30:01 +01:00
public void Update()
{
keyToOpen = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("Interact"));
}
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();
return base.OpenPanel();
}
public override bool ClosePanel()
{
base.ClosePanel();
ChestContentUIManager.Instance.DynamicPanel = null;
// Close additionals panels
if (EquipmentUIManager.Instance.GetPanelStatus()) EquipmentUIManager.Instance.ClosePanel();
if (InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.ClosePanel();
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)
{
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);
}
}