Files
beyond/Assets/Scripts/UI/PowersMenuController.cs
2024-11-20 15:21:28 +01:00

103 lines
3.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Beyond
{
public class PowersMenuController : MonoBehaviour
{
[SerializeField] private MenuScroll menuScroll;
[SerializeField] private bEquipArea powersArea;
[SerializeField] private bItemWindow powersPicker, scrollsPicker;
[SerializeField] private bInventory inventory;
[SerializeField] private TMP_Text categoryText;
[SerializeField] private Image quantaPowersImage, powerScrollImage;
private Image currentCategoryImage = null;
private List<bItemType> quantaPowerTypes = new List<bItemType> { bItemType.QuantaPower };
private List<bItemType> powerScrollTypes = new List<bItemType> { bItemType.PowerScroll };
private List<bItemType> currentTypes = new List<bItemType>();
public void OpenPowers()
{
OpenPowerScrollsArea();
menuScroll.OnOpened += RefreshEquipmentWindow;
}
public void ClosePowers()
{
menuScroll.OnOpened -= RefreshEquipmentWindow;
}
public void OpenQuantaPowersArea()
{
currentTypes = quantaPowerTypes;
categoryText.text = "Quanta Powers";
Player.Instance.PlayCategoryChangeSound();
powersArea.SetNewItemWindow(powersPicker);
scrollsPicker.gameObject.SetActive(false);
powersPicker.gameObject.SetActive(true);
RefreshEquipmentWindow();
EnableProperCategoryImage(quantaPowersImage);
}
public void OpenPowerScrollsArea()
{
currentTypes = powerScrollTypes;
categoryText.text = "Power Scrolls";
Player.Instance.PlayCategoryChangeSound();
powersArea.SetNewItemWindow(scrollsPicker);
scrollsPicker.gameObject.SetActive(true);
powersPicker.gameObject.SetActive(false);
RefreshEquipmentWindow();
EnableProperCategoryImage(powerScrollImage);
}
public void TryToOpenScrollsOnPowerGaze()
{
OpenPowerScrollsArea();
menuScroll.OnOpened += TryToSelectCovertGaze;
}
private void TryToSelectCovertGaze()
{
bItemSlot gazeSlot = scrollsPicker.slots.Find(slot => slot.item && slot.item.name == "Covert Gaze ");
if (gazeSlot)
{
gazeSlot.OnSelect(null);
}
menuScroll.OnOpened -= TryToSelectCovertGaze;
}
private void EnableProperCategoryImage(Image imageToEnable)
{
if (currentCategoryImage != null)
{
currentCategoryImage.enabled = false;
}
currentCategoryImage = imageToEnable;
currentCategoryImage.enabled = true;
}
public void RefreshEquipmentWindow()
{
powersArea.SetEquipmentwindowWithFilter(currentTypes);
}
private void OnDestroy()
{
if (menuScroll)
{
menuScroll.OnOpened -= RefreshEquipmentWindow;
}
if (inventory)
{
inventory.OnUpdateInventory -= RefreshEquipmentWindow;
}
}
}
}