using Beyond; using DanielLochner.Assets.SimpleScrollSnap; using Invector.vItemManager; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ButtonSpellBindController : MonoBehaviour, IButtonItemBindController { [SerializeField] private SimpleScrollSnap scrollSnap; [SerializeField] private List itemPanels = new(); [SerializeField] private bEquipArea equipArea; private void Start() { EnablePanelIfSomethingIsEquipped(null); DisablePanelIfNothingIsEquipped(null); for (int i = 0; i < itemPanels.Count; i++) { BindPanelToItemSlot(i); } } private void OnDestroy() { RemoveListeners(); } private void RemoveListeners() { if (!equipArea) { return; } List itemPanelControllers = GetItemPanels(); for (int i = 0; i < equipArea.equipSlots.Count; i++) { bEquipSlot equipSlot = equipArea.equipSlots[i]; if (!equipSlot) continue; equipSlot.onAddItem.RemoveListener(EnablePanelIfSomethingIsEquipped); equipSlot.onRemoveItem.RemoveListener(DisablePanelIfNothingIsEquipped); if (itemPanelControllers.Count > i) { ItemPanelController spellPanel = itemPanelControllers[i]; if (spellPanel) { equipSlot.onAddItem.RemoveListener(spellPanel.SetPanelToItemImage); equipSlot.onRemoveItem.RemoveListener(spellPanel.SetPanelToDefaultImage); } } } } public void BindPanelToItemSlot(int index) { //GameObject spellanelObject = scrollSnap.Panels[index]; //spellanelObject.SetActive(true); //ItemPanelController spellPanel = spellanelObject.GetComponent(); //itemPanels.Add(spellPanel); ItemPanelController spellPanel = itemPanels[index]; bEquipSlot equipSlot = equipArea.equipSlots[index]; if (itemPanels.Count == 1) { equipSlot.onAddItem.AddListener(UpdateFirstSlotOnFirstSpellEquipped); } equipSlot.onAddItem.AddListener(spellPanel.SetPanelToItemImage); if (equipArea.equipSlots[index].item) { spellPanel.SetPanelToItemImage(equipArea.equipSlots[index].item); } equipSlot.onAddItem.AddListener(EnablePanelIfSomethingIsEquipped); equipSlot.onRemoveItem.AddListener(spellPanel.SetPanelToDefaultImage); equipSlot.onRemoveItem.AddListener(DisablePanelIfNothingIsEquipped); } public void DisablePanelIfNothingIsEquipped(bItem item) { if (!equipArea.IsAnyItemEquipped()) { scrollSnap.gameObject.SetActive(false); } } //should probably be always activating if on add item public void EnablePanelIfSomethingIsEquipped(bItem item) { if (equipArea.IsAnyItemEquipped() && !scrollSnap.gameObject.activeSelf) { scrollSnap.gameObject.SetActive(true); } } private void UpdateFirstSlotOnFirstSpellEquipped(bItem item) { bEquipSlot equipSlot = equipArea.equipSlots[0]; equipSlot.onAddItem.RemoveListener(UpdateFirstSlotOnFirstSpellEquipped); } public ItemPanelController GetCurrentItemPanel() { return itemPanels[scrollSnap.CurrentPanel]; } public int GetEquipSlotsCount() { return equipArea.equipSlots.Count; } public bEquipArea getEquipArea() { return equipArea; } public void SetEquipSlot() { equipArea.SetEquipSlot(scrollSnap.CurrentPanel); } public bEquipArea GetEquipArea() { return equipArea; } public List GetItemPanels() { return itemPanels; } }