Neg_Utils/NEG/UI/Window/IWindow.cs

55 lines
1.7 KiB
C#

using JetBrains.Annotations;
using NEG.UI.Area;
using NEG.UI.WindowSlot;
using UnityEngine;
namespace NEG.UI.Window
{
public interface IWindow
{
IWindowSlot Parent { get; }
IWindowSlot ChildWindowSlot { get; }
/// <summary>
/// Called internally by slot to open window.
/// </summary>
/// <param name="parentSlot">slot that opens window</param>
void SetOpenedState(IWindowSlot parentSlot);
void SetData(object data);
/// <summary>
/// Called internally to close window by slot.
/// </summary>
void SetClosedState();
}
public static class WindowInterfaceExtensions
{
//Open
public static void Open(this IWindow window, IWindowSlot slot = null, object data = null)
{
if (slot != null)
{
slot.AttachWindow(window);
window.SetData(data);
}
else
UiManager.Instance.CurrentArea.OpenWindow(window, data);
}
public static void Open(this IWindow window, IArea area, object data = null) => area.OpenWindow(window, data);
public static void OpenChildWindow(this IWindow window, IWindow windowToOpen, object data = null)
{
if (window.ChildWindowSlot == 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);
}
}