Adding documentation + cleanup
This commit is contained in:
parent
7bbc03cdbf
commit
d3327c4360
@ -7,6 +7,11 @@ namespace NEG.UI.Area
|
|||||||
{
|
{
|
||||||
public interface IArea : ISlotsHolder, IUiElement
|
public interface IArea : ISlotsHolder, IUiElement
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Open window as child of
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="window"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
void OpenChildWindow(IWindow window, object data = null);
|
void OpenChildWindow(IWindow window, object data = null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,16 +7,21 @@ namespace NEG.UI.Popup
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public interface IPopup
|
public interface IPopup
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Event to fire when popup is closed
|
||||||
|
/// </summary>
|
||||||
|
event Action<PopupData> OnPopupClosed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Show popup
|
/// Show popup
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">data assigned to popup, used to give info that popup is closed</param>
|
/// <param name="data">data assigned to popup, used to give info that popup is closed</param>
|
||||||
void Show(PopupData data);
|
public void Show(PopupData data);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Close popup or mark as closed if not visible
|
/// Close popup or mark as closed if not visible
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="silence">if true hide visually, without firing callbacks</param>
|
/// <param name="silence">if true hide visually, without firing callbacks to properly close</param>
|
||||||
void Close(bool silence = false);
|
void Close(bool silence = false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,15 @@
|
|||||||
namespace NEG.UI.Popup
|
using System;
|
||||||
|
|
||||||
|
namespace NEG.UI.Popup
|
||||||
{
|
{
|
||||||
public class PopupData
|
public class PopupData
|
||||||
{
|
{
|
||||||
|
public event Action<PopupData> PopupClosedEvent
|
||||||
|
{
|
||||||
|
add => popup.OnPopupClosed += value;
|
||||||
|
remove => popup.OnPopupClosed -= value;
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsValid { get; protected set; }
|
public bool IsValid { get; protected set; }
|
||||||
|
|
||||||
private IPopup popup;
|
private IPopup popup;
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
using NEG.UI.Area;
|
using NEG.UI.Area;
|
||||||
using NEG.UI.Popup;
|
using NEG.UI.Popup;
|
||||||
|
using NEG.UI.Window;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NEG.UI
|
namespace NEG.UI
|
||||||
{
|
{
|
||||||
|
[PublicAPI]
|
||||||
public abstract class UiManager
|
public abstract class UiManager
|
||||||
{
|
{
|
||||||
//TODO: use default unity selection
|
|
||||||
//TODO: window snaping to slots
|
|
||||||
//TODO: Default prefabs?
|
|
||||||
|
|
||||||
public static UiManager Instance { get; private set; }
|
public static UiManager Instance { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Current area shown on screen.
|
||||||
|
/// </summary>
|
||||||
public IArea CurrentArea
|
public IArea CurrentArea
|
||||||
{
|
{
|
||||||
get => currentArea;
|
get => currentArea;
|
||||||
@ -26,10 +28,15 @@ namespace NEG.UI
|
|||||||
currentArea?.SetEnabled(true);
|
currentArea?.SetEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Current window that is considered main (focused, lastly opened). Can be null.
|
||||||
|
/// </summary>
|
||||||
|
public IWindow CurrentMainWindow { get; protected set; }
|
||||||
|
|
||||||
private IArea currentArea;
|
private IArea currentArea;
|
||||||
protected IDefaultPopup currentDefaultPopup;
|
|
||||||
private (PopupData data, int priority) currentShownPopup;
|
private (PopupData data, int priority) currentShownPopup;
|
||||||
|
protected IDefaultPopup currentDefaultPopup;
|
||||||
|
|
||||||
private PriorityQueue<PopupData, int> popupsToShow = new();
|
private PriorityQueue<PopupData, int> popupsToShow = new();
|
||||||
|
|
||||||
@ -114,8 +121,8 @@ namespace NEG.UI
|
|||||||
popupsToShow.Enqueue(data, priority);
|
popupsToShow.Enqueue(data, priority);
|
||||||
UpdatePopupsState(forceShow, priority, data);
|
UpdatePopupsState(forceShow, priority, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PopupClosed(PopupData data)
|
protected void PopupClosed(PopupData data)
|
||||||
{
|
{
|
||||||
if (currentShownPopup.data != data)
|
if (currentShownPopup.data != data)
|
||||||
{
|
{
|
||||||
@ -124,7 +131,7 @@ namespace NEG.UI
|
|||||||
}
|
}
|
||||||
UpdatePopupsState(false);
|
UpdatePopupsState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetDefaultPopup(IDefaultPopup popup) => currentDefaultPopup = popup;
|
protected void SetDefaultPopup(IDefaultPopup popup) => currentDefaultPopup = popup;
|
||||||
|
|
||||||
private void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null)
|
private void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null)
|
||||||
@ -147,8 +154,14 @@ namespace NEG.UI
|
|||||||
|
|
||||||
private void ShowPopup(PopupData data, int priority)
|
private void ShowPopup(PopupData data, int priority)
|
||||||
{
|
{
|
||||||
|
if (currentShownPopup.data != null)
|
||||||
|
{
|
||||||
|
currentShownPopup.data.PopupClosedEvent -= PopupClosed;
|
||||||
|
currentShownPopup.data.Hide();
|
||||||
|
}
|
||||||
currentShownPopup = (data, priority);
|
currentShownPopup = (data, priority);
|
||||||
data.Show();
|
data.Show();
|
||||||
|
data.PopupClosedEvent += PopupClosed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,12 +13,12 @@ namespace NEG.UI.Area
|
|||||||
{
|
{
|
||||||
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
||||||
public IWindowSlot DefaultWindowSlot => windowSlots[0];
|
public IWindowSlot DefaultWindowSlot => windowSlots[0];
|
||||||
|
|
||||||
[SerializeField] private bool setAsDefaultArea;
|
[SerializeField] private bool setAsDefaultArea;
|
||||||
|
|
||||||
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
||||||
|
|
||||||
[SerializeField] private Queue<IPopup> currentPopups = new();
|
private Queue<IPopup> currentPopups = new();
|
||||||
|
|
||||||
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
|
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,9 @@ namespace NEG.UI.UnityUi
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MonoUiManager : UiManager
|
public class MonoUiManager : UiManager
|
||||||
{
|
{
|
||||||
|
//TODO: use default unity selection
|
||||||
|
//TODO: window snaping to slots
|
||||||
|
|
||||||
private readonly MonoDefaultPopup defaultPopupPrefab;
|
private readonly MonoDefaultPopup defaultPopupPrefab;
|
||||||
private readonly GameObject canvasPrefab;
|
private readonly GameObject canvasPrefab;
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,8 @@ namespace NEG.UI.UnityUi.Popup
|
|||||||
{
|
{
|
||||||
public class MonoPopup : MonoBehaviour, IPopup
|
public class MonoPopup : MonoBehaviour, IPopup
|
||||||
{
|
{
|
||||||
|
public event Action<PopupData> OnPopupClosed;
|
||||||
|
|
||||||
protected PopupData data;
|
protected PopupData data;
|
||||||
|
|
||||||
public void Show(PopupData data)
|
public void Show(PopupData data)
|
||||||
@ -21,7 +23,7 @@ namespace NEG.UI.UnityUi.Popup
|
|||||||
if(silence)
|
if(silence)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UiManager.Instance.PopupClosed(data);
|
OnPopupClosed?.Invoke(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using NEG.UI.Area;
|
using NEG.UI.Area;
|
||||||
|
using NEG.UI.UnityUi.Buttons;
|
||||||
using NEG.UI.UnityUi.WindowSlot;
|
using NEG.UI.UnityUi.WindowSlot;
|
||||||
using NEG.UI.Window;
|
using NEG.UI.Window;
|
||||||
using NEG.UI.WindowSlot;
|
using NEG.UI.WindowSlot;
|
||||||
@ -10,13 +11,17 @@ namespace NEG.UI.UnityUi.Window
|
|||||||
{
|
{
|
||||||
public class MonoWindow : MonoBehaviour, IWindow
|
public class MonoWindow : MonoBehaviour, IWindow
|
||||||
{
|
{
|
||||||
|
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
||||||
public IWindowSlot Parent { get; private set; }
|
public IWindowSlot Parent { get; private set; }
|
||||||
public IWindowSlot ChildWindowSlot => childWindowArea;
|
|
||||||
|
|
||||||
[SerializeField] private MonoWindowSlot childWindowArea;
|
public bool IsMainWindow { get; private set; }
|
||||||
|
|
||||||
|
private IWindowSlot DefaultWindowSlot => windowSlots[0];
|
||||||
|
|
||||||
|
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
||||||
[SerializeField] private WindowController controller;
|
[SerializeField] private WindowController controller;
|
||||||
|
|
||||||
void IWindow.SetOpenedState(IWindowSlot parentSlot)
|
public void SetOpenedState(IWindowSlot parentSlot)
|
||||||
{
|
{
|
||||||
gameObject.SetActive(true);
|
gameObject.SetActive(true);
|
||||||
Parent = parentSlot;
|
Parent = parentSlot;
|
||||||
@ -30,12 +35,11 @@ namespace NEG.UI.UnityUi.Window
|
|||||||
controller.SetData(data);
|
controller.SetData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IWindow.SetClosedState()
|
public void SetClosedState()
|
||||||
{
|
{
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
Parent = null;
|
Parent = null;
|
||||||
if(childWindowArea != null)
|
((ISlotsHolder)this).CloseAllWindows();
|
||||||
ChildWindowSlot.CloseAllWindows();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Awake() => ((IWindow)this).SetClosedState();
|
private void Awake() => ((IWindow)this).SetClosedState();
|
||||||
@ -46,7 +50,10 @@ namespace NEG.UI.UnityUi.Window
|
|||||||
controller = GetComponent<WindowController>();
|
controller = GetComponent<WindowController>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IWindowSlot> AvailableSlots { get; }
|
public void OpenWindow(IWindow window, object data = null)
|
||||||
public void OpenWindow(IWindow window, object data = null) => throw new NotImplementedException();
|
{
|
||||||
|
DefaultWindowSlot.AttachWindow(window);
|
||||||
|
window.SetData(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -16,6 +16,5 @@ namespace NEG.UI.UnityUi.WindowSlot
|
|||||||
public abstract void CloseAllWindows();
|
public abstract void CloseAllWindows();
|
||||||
|
|
||||||
[SerializeField] private SerializableInterface<ISlotsHolder> slotsHolder;
|
[SerializeField] private SerializableInterface<ISlotsHolder> slotsHolder;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,6 +7,9 @@ namespace NEG.UI.Window
|
|||||||
{
|
{
|
||||||
public interface IWindow : ISlotsHolder
|
public interface IWindow : ISlotsHolder
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Parent slot of this window.
|
||||||
|
/// </summary>
|
||||||
IWindowSlot Parent { get; }
|
IWindowSlot Parent { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -15,6 +18,10 @@ namespace NEG.UI.Window
|
|||||||
/// <param name="parentSlot">slot that opens window</param>
|
/// <param name="parentSlot">slot that opens window</param>
|
||||||
void SetOpenedState(IWindowSlot parentSlot);
|
void SetOpenedState(IWindowSlot parentSlot);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets data for window, usually used for dynamic content set by external logic controller.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">can be any type, window should cast for expected type</param>
|
||||||
void SetData(object data);
|
void SetData(object data);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -25,7 +32,12 @@ namespace NEG.UI.Window
|
|||||||
|
|
||||||
public static class WindowInterfaceExtensions
|
public static class WindowInterfaceExtensions
|
||||||
{
|
{
|
||||||
//Open
|
/// <summary>
|
||||||
|
/// Opens window as slot child. If slot is null or not provided, as child of current area.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="window">window to open</param>
|
||||||
|
/// <param name="slot">slot to attach window</param>
|
||||||
|
/// <param name="data">data to send to window</param>
|
||||||
public static void Open(this IWindow window, IWindowSlot slot = null, object data = null)
|
public static void Open(this IWindow window, IWindowSlot slot = null, object data = null)
|
||||||
{
|
{
|
||||||
if (slot != null)
|
if (slot != null)
|
||||||
@ -37,8 +49,21 @@ namespace NEG.UI.Window
|
|||||||
|
|
||||||
UiManager.Instance.CurrentArea.OpenWindow(window, data);
|
UiManager.Instance.CurrentArea.OpenWindow(window, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens window as child of selected area.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="window">window to open</param>
|
||||||
|
/// <param name="area">area to attach window</param>
|
||||||
|
/// <param name="data">data to send to window</param>
|
||||||
public static void Open(this IWindow window, IArea area, object data = null) => area.OpenWindow(window, data);
|
public static void Open(this IWindow window, IArea area, object data = null) => area.OpenWindow(window, data);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Open passed window as child of this window.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="window">parent window</param>
|
||||||
|
/// <param name="windowToOpen">window to open</param>
|
||||||
|
/// <param name="data">data to send to window</param>
|
||||||
public static void OpenChild(this IWindow window, IWindow windowToOpen, object data = null)
|
public static void OpenChild(this IWindow window, IWindow windowToOpen, object data = null)
|
||||||
{
|
{
|
||||||
if (windowToOpen == null)
|
if (windowToOpen == null)
|
||||||
@ -48,7 +73,13 @@ namespace NEG.UI.Window
|
|||||||
}
|
}
|
||||||
window.OpenWindow(windowToOpen, data);
|
window.OpenWindow(windowToOpen, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Open window as child of provided window. If <typeparamref name="parentWindow"/> is null, as child of current main window in <see cref="UiManager"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="window">window to open</param>
|
||||||
|
/// <param name="parentWindow"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
public static void OpenAsChild(this IWindow window, IWindow parentWindow = null, object data = null)
|
public static void OpenAsChild(this IWindow window, IWindow parentWindow = null, object data = null)
|
||||||
{
|
{
|
||||||
if (parentWindow != null)
|
if (parentWindow != null)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user