48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using NEG.UI.Area;
|
|
using NEG.UI.WindowSlot;
|
|
using UnityEngine;
|
|
|
|
namespace NEG.UI.Window
|
|
{
|
|
public interface IWindow
|
|
{
|
|
IWindowSlot Parent { get; }
|
|
IArea ChildWindowArea { get; }
|
|
|
|
/// <summary>
|
|
/// Call internally by slot to open window
|
|
/// </summary>
|
|
/// <param name="parentSlot">Slot that opens window</param>
|
|
internal void Open(IWindowSlot parentSlot);
|
|
|
|
/// <summary>
|
|
/// Call internally to close window by slot
|
|
/// </summary>
|
|
internal void Close();
|
|
}
|
|
|
|
public static class WindowInterfaceExtensions
|
|
{
|
|
//Open
|
|
public static void Open(this IWindow window, IWindowSlot slot = null)
|
|
{
|
|
if(slot != null)
|
|
slot.AttachWindow(window);
|
|
else
|
|
UiManager.Instance.CurrentArea.OpenWindow(window);
|
|
}
|
|
public static void Open(this IWindow window, IArea area) => area.OpenWindow(window);
|
|
public static void OpenChildWindow(this IWindow window, IWindow windowToOpen, IWindowSlot slot = null)
|
|
{
|
|
if (window.ChildWindowArea == null)
|
|
{
|
|
Debug.LogError("This window doesn't contain area for child windows");
|
|
return;
|
|
}
|
|
//TODO: DO it
|
|
//window.ChildWindowArea.OpenWindow(windowToOpen, slot);
|
|
}
|
|
|
|
public static void Close(this IWindow window) => window.Parent.DetachWindow(window);
|
|
}
|
|
} |