Compare commits
1 Commits
main
...
new-window
| Author | SHA1 | Date | |
|---|---|---|---|
| a051415c16 |
3
NEG/UI/AssemblyInfo.cs
Normal file
3
NEG/UI/AssemblyInfo.cs
Normal file
@ -0,0 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("NEG.UI.UnityUi")]
|
||||
3
NEG/UI/AssemblyInfo.cs.meta
Normal file
3
NEG/UI/AssemblyInfo.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bf54cf2dc934c9b85c514bb01057e64
|
||||
timeCreated: 1716843793
|
||||
@ -13,31 +13,6 @@ namespace NEG.UI
|
||||
[PublicAPI]
|
||||
public abstract class UiManager : IDisposable
|
||||
{
|
||||
private IArea currentArea;
|
||||
protected IDefaultPopup currentDefaultPopup;
|
||||
private (PopupData data, int priority) currentShownPopup;
|
||||
|
||||
//TODO: localize
|
||||
private string localizedYes = "Yes", localizedNo = "No", localizedOk = "Ok";
|
||||
|
||||
private List<IWindow> mainWindows;
|
||||
|
||||
private PriorityQueue<PopupData, int> popupsToShow = new();
|
||||
|
||||
protected UiManager(IArea startArea)
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
Debug.LogError("Only one instance od UiManager is allowed");
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
|
||||
CurrentArea = startArea;
|
||||
mainWindows = new List<IWindow>();
|
||||
}
|
||||
|
||||
public static UiManager Instance { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
@ -62,6 +37,31 @@ namespace NEG.UI
|
||||
public IWindow CurrentMainWindow => mainWindows.LastOrDefault();
|
||||
|
||||
public PopupData CurrentPopup => currentShownPopup.data;
|
||||
|
||||
private IArea currentArea;
|
||||
protected IDefaultPopup currentDefaultPopup;
|
||||
private (PopupData data, int priority) currentShownPopup;
|
||||
|
||||
//TODO: localize
|
||||
private string localizedYes = "Yes", localizedNo = "No", localizedOk = "Ok";
|
||||
|
||||
private List<IWindow> mainWindows;
|
||||
|
||||
private PriorityQueue<PopupData, int> popupsToShow = new();
|
||||
private Dictionary<string, IWindow> registeredWindows = new();
|
||||
|
||||
protected UiManager(IArea startArea = default)
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
Debug.LogError("Only one instance od UiManager is allowed");
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
CurrentArea = startArea;
|
||||
mainWindows = new List<IWindow>();
|
||||
}
|
||||
|
||||
public virtual void Dispose() => Instance = null;
|
||||
|
||||
@ -164,6 +164,9 @@ namespace NEG.UI
|
||||
|
||||
public void OnWindowClosed(IWindow window) => MainWindowClosed(window);
|
||||
|
||||
internal void RegisterWindow(IWindow window) => registeredWindows.Add(window.WindowId, window);
|
||||
internal void UnRegisterWindow(IWindow window) => registeredWindows.Remove(window.WindowId);
|
||||
|
||||
//TODO: select new main window
|
||||
protected void PopupClosed(PopupData data)
|
||||
{
|
||||
|
||||
@ -12,18 +12,35 @@ namespace NEG.UI.UnityUi.Window
|
||||
[DefaultExecutionOrder(10)]
|
||||
public class MonoWindow : MonoBehaviour, IWindow
|
||||
{
|
||||
public event Action<object> OnOpened;
|
||||
public event Action OnClosed;
|
||||
public event Action<IControllable.BackUsed> OnBackUsed;
|
||||
|
||||
[field: SerializeField] public string WindowId { get; private set; }
|
||||
|
||||
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
||||
public IWindowSlot Parent { get; private set; }
|
||||
|
||||
public bool IsOpened { get; protected set; }
|
||||
|
||||
public bool IsMainWindow { get; }
|
||||
|
||||
public GameObject DefaultSelectedItem => defaultSelectedItem;
|
||||
|
||||
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
||||
|
||||
[SerializeField] private string windowName;
|
||||
|
||||
[SerializeField] private GameObject defaultSelectedItem;
|
||||
|
||||
public bool IsMainWindow { get; }
|
||||
|
||||
public bool IsOpened { get; protected set; }
|
||||
|
||||
private IWindowSlot DefaultWindowSlot => windowSlots[0];
|
||||
public GameObject DefaultSelectedItem => defaultSelectedItem;
|
||||
|
||||
|
||||
private void Awake() => ((IWindow)this).SetHiddenState();
|
||||
private void Awake()
|
||||
{
|
||||
UiManager.Instance.RegisterWindow(this);
|
||||
((IWindow)this).SetHiddenState();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
@ -31,6 +48,8 @@ namespace NEG.UI.UnityUi.Window
|
||||
return;
|
||||
if (IsOpened)
|
||||
UiManager.Instance.OnWindowClosed(this);
|
||||
UiManager.Instance.UnRegisterWindow(this);
|
||||
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
@ -41,13 +60,6 @@ namespace NEG.UI.UnityUi.Window
|
||||
#endif
|
||||
}
|
||||
|
||||
public event Action<object> OnOpened;
|
||||
public event Action OnClosed;
|
||||
public event Action<IControllable.BackUsed> OnBackUsed;
|
||||
|
||||
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
||||
public IWindowSlot Parent { get; private set; }
|
||||
|
||||
public void SetOpenedState(IWindowSlot parentSlot, object data)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
@ -11,6 +11,8 @@ namespace NEG.UI.Window
|
||||
/// Parent slot of this window.
|
||||
/// </summary>
|
||||
IWindowSlot Parent { get; }
|
||||
|
||||
string WindowId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called internally by slot to open window.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user