using NEG.UI; using NEG.UI.UnityUi.Window; using NEG.UI.UnityUi.WindowSlot; using NEG.UI.Window; using System.Collections.Generic; using System.Linq; using UnityEngine.EventSystems; namespace NegUtils.NEG.UI.UnityUi.WindowSlot { public class SingleWindowSlotWithHistory : MonoWindowSlot { public IWindow CurrentWindow { get => currentWindow; set { if (value == null) { CloseAllWindows(); return; } currentWindow?.SetHiddenState(); currentWindow = value; windowsHistory.Add(currentWindow); } } private IWindow currentWindow; private readonly List windowsHistory = new List(); public override void AttachWindow(IWindow window, object data) { CurrentWindow = window; CurrentWindow.SetOpenedState(this, data); } public override void DetachWindow(IWindow window) { if(window == null) return; window.SetClosedState(); windowsHistory.Remove(window); if (window != currentWindow || windowsHistory.Count == 0) return; currentWindow = windowsHistory[^1]; currentWindow.SeVisibleState(); if(UiManager.Instance.CurrentMainWindow == window) UiManager.Instance.MainWindowClosed(window); EventSystem.current.SetSelectedGameObject(((MonoWindow)currentWindow).DefaultSelectedItem); } public override void CloseAllWindows() { currentWindow = null; foreach (var window in windowsHistory) { window.SetClosedState(); } windowsHistory.Clear(); } } }