58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
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<IWindowSlot> AvailableSlots => windowSlots;
|
|
public IWindowSlot DefaultWindowSlot => windowSlots[0];
|
|
public IEnumerable<IWindow> CurrentWindows { get; }
|
|
public IEnumerable<IPopup> CurrentPopups => currentPopups;
|
|
|
|
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
|
|
|
[SerializeField] private Queue<IPopup> 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();
|
|
}
|
|
}
|
|
} |