using NEG.UI.UnityUi.WindowSlot; using NEG.UI.Window; using System.Collections.Generic; using System.Linq; 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); currentWindow?.SetOpenedState(this); } } private IWindow currentWindow; private readonly List windowsHistory = new List(); public override void AttachWindow(IWindow window) => CurrentWindow = window; public override void DetachWindow(IWindow window) { if(window == null) return; window.SetClosedState(); windowsHistory.Remove(window); if (window != currentWindow || windowsHistory.Count == 0) return; windowsHistory[^1].SeVisibleState(); currentWindow = windowsHistory[^1]; } public override void CloseAllWindows() { currentWindow = null; foreach (var window in windowsHistory) { window.SetClosedState(); } windowsHistory.Clear(); } } }