66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using JetBrains.Annotations;
|
|
using NEG.UI.Area;
|
|
using NEG.UI.WindowSlot;
|
|
using UnityEngine;
|
|
|
|
namespace NEG.UI.Window
|
|
{
|
|
public interface IWindow : ISlotsHolder
|
|
{
|
|
IWindowSlot Parent { 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);
|
|
return;
|
|
}
|
|
|
|
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 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);
|
|
}
|
|
|
|
public static void OpenAsChild(this IWindow window, IWindow parentWindow = null, object data = null)
|
|
{
|
|
if (parentWindow != null)
|
|
{
|
|
parentWindow.OpenWindow(window);
|
|
return;
|
|
}
|
|
|
|
UiManager.Instance.CurrentArea.OpenChildWindow(window, data);
|
|
}
|
|
|
|
public static void Close(this IWindow window) => window.Parent.DetachWindow(window);
|
|
|
|
}
|
|
} |