using NEG.UI.Area; using NEG.UI.WindowSlot; using NegUtils.NEG.UI; using UnityEngine; namespace NEG.UI.Window { public interface IWindow : ISlotsHolder, IControllable { /// /// Parent slot of this window. /// IWindowSlot Parent { get; } /// /// Called internally by slot to open window. /// /// slot that opens window /// data void SetOpenedState(IWindowSlot parentSlot, object data); /// /// Called internally to close window by slot. /// void SetClosedState(); /// /// Called internally to hide window by slot. /// void SetHiddenState(); /// /// Called internally to set window visible by slot. /// void SeVisibleState(); } public static class WindowInterfaceExtensions { /// /// Opens window as slot child. If slot is null or not provided, as child of current area. /// /// window to open /// slot to attach window /// data to send to window public static void Open(this IWindow window, IWindowSlot slot = null, object data = null) { if (slot != null) { slot.AttachWindow(window, data); return; } UiManager.Instance.CurrentArea.OpenWindow(window, data); } /// /// Opens window as child of selected area. /// /// window to open /// area to attach window /// data to send to window public static void Open(this IWindow window, IArea area, object data = null) => area.OpenWindow(window, data); /// /// Open passed window as child of this window. /// /// parent window /// window to open /// data to send to window public static void OpenChild(this IWindow window, IWindow windowToOpen, object data = null) { if (windowToOpen == null) { Debug.LogError("Window to open cannot be null"); return; } window.OpenWindow(windowToOpen, data); } /// /// Open window as child of provided window. If is null, as child of current main /// window in . If there is no main window, open on current area. /// /// window to open /// parent window /// data to send to window public static void OpenAsChild(this IWindow window, IWindow parentWindow = null, object data = null) { if (parentWindow != null) { parentWindow.OpenWindow(window, data); return; } if (UiManager.Instance.CurrentMainWindow != null) { UiManager.Instance.CurrentMainWindow.OpenWindow(window, data); return; } UiManager.Instance.CurrentArea.OpenWindow(window, data); } /// /// Close window. /// /// window to close public static void Close(this IWindow window) => window.Parent.DetachWindow(window); } }