using System.Collections.Generic; using UnityEngine; using NEG.UI.Popup; using NEG.UI.Window; using NEG.UI.WindowSlot; namespace NEG.UI.Area { public class MonoArea : MonoBehaviour, IArea { public IEnumerable AvailableSlots => windowSlots; public IWindowSlot DefaultWindowSlot => windowSlots[0]; public IEnumerable CurrentWindows { get; } public IEnumerable CurrentPopups => currentPopups; [SerializeField] private List windowSlots; [SerializeField] private Queue currentPopups = new(); public void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled); public void OpenWindow(IWindow window) => DefaultWindowSlot.AttachWindow(window); public void OpenPopup(IPopup popup) { currentPopups.Enqueue(popup); popup.OnPopupClosed += OnPopupClosed; popup.Show(); UpdatePopupStates(); } private void UpdatePopupStates() { if(currentPopups.Count == 0) return; while (currentPopups.TryPeek(out var popup)) { if(popup.IsValid) popup.SetEnabled(true); currentPopups.Dequeue(); } } private void OnPopupClosed(IPopup popup) { if (!currentPopups.Contains(popup)) return; if(currentPopups.Peek() != popup) return; currentPopups.Dequeue(); UpdatePopupStates(); } } }