area changes

This commit is contained in:
Hubert Mattusch 2023-01-15 14:54:43 +01:00
parent fcc98eb41d
commit 266d199b48
2 changed files with 18 additions and 11 deletions

View File

@ -19,17 +19,11 @@ namespace NEG.UI
get => currentArea; get => currentArea;
set set
{ {
if (value == null)
{
Debug.LogError("CurrentArea can't be null");
return;
}
currentArea?.SetEnabled(false); currentArea?.SetEnabled(false);
currentArea = value; currentArea = value;
currentArea.SetEnabled(true); currentArea?.SetEnabled(true);
} }
} }
@ -51,6 +45,7 @@ namespace NEG.UI
} }
Instance = this; Instance = this;
CurrentArea = startArea; CurrentArea = startArea;
} }

View File

@ -4,6 +4,7 @@ using NEG.UI.Popup;
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;
using System;
namespace NEG.UI.Area namespace NEG.UI.Area
{ {
@ -11,20 +12,31 @@ namespace NEG.UI.Area
{ {
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots; public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
public IWindowSlot DefaultWindowSlot => windowSlots[0]; public IWindowSlot DefaultWindowSlot => windowSlots[0];
public IEnumerable<IWindow> CurrentWindows { get; }
[SerializeField] private bool setAsDefaultArea;
[SerializeField] private List<MonoWindowSlot> windowSlots; [SerializeField] private List<MonoWindowSlot> windowSlots;
[SerializeField] private Queue<IPopup> currentPopups = new(); [SerializeField] private Queue<IPopup> currentPopups = new();
public void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled); public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
public void OpenWindow(IWindow window, object data = null) public virtual void OpenWindow(IWindow window, object data = null)
{ {
DefaultWindowSlot.AttachWindow(window); DefaultWindowSlot.AttachWindow(window);
window.SetData(data); window.SetData(data);
} }
protected virtual void Awake()
{
if (setAsDefaultArea)
UiManager.Instance.CurrentArea = this;
}
protected virtual void OnDestroy()
{
if (ReferenceEquals(UiManager.Instance.CurrentArea, this))
UiManager.Instance.CurrentArea = null;
}
} }
} }