final update befor pr

This commit is contained in:
Hubert Mattusch 2023-09-01 21:42:37 +02:00
parent 33d0a9078f
commit fb90337a3f
14 changed files with 55 additions and 102 deletions

View File

@ -3,7 +3,9 @@ using NegUtils.NEG.UI;
namespace NEG.UI.Area
{
public interface IArea : ISlotsHolder, IUiElement, IControllable
public interface IArea : ISlotsHolder, IControllable
{
void Open();
void Close();
}
}

View File

@ -11,13 +11,8 @@ namespace NegUtils.NEG.UI
event Action<object> OnOpened;
event Action OnClosed;
/// <summary>
///
/// </summary>
event Action<BackUsed> UseBack;
public void FireOpenCallback(object data);
public void FireOnClosed();
public void FireUseBack(ref BackUsed backUsed);
public void TryUseBack(ref BackUsed backUsed);
}
}

View File

@ -2,10 +2,6 @@
{
public interface IController
{
void OnOpened(object data);
void OnClosed();
void UseBack(IControllable.BackUsed backUsed);
IControllable Controllable { get; }
}
}

View File

@ -1,11 +0,0 @@
namespace NEG.UI
{
public interface IUiElement
{
/// <summary>
/// Sets only visible state of element
/// </summary>
/// <param name="setEnabled"></param>
void SetEnabled(bool setEnabled);
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 296bf6969a6347f8aea788a7bdd086af
timeCreated: 1670693177

View File

@ -23,11 +23,11 @@ namespace NEG.UI
get => currentArea;
set
{
currentArea?.SetEnabled(false);
currentArea?.Close();
currentArea = value;
currentArea?.SetEnabled(true);
currentArea?.Open();
}
}
@ -130,10 +130,10 @@ namespace NEG.UI
{
IControllable.BackUsed backUsed = new();
CurrentMainWindow?.FireUseBack(ref backUsed);
CurrentMainWindow?.TryUseBack(ref backUsed);
if(backUsed.Used)
return;
CurrentArea.FireUseBack(ref backUsed);
CurrentArea.TryUseBack(ref backUsed);
}

View File

@ -1,27 +1,19 @@
using NEG.UI.Window;
using KBCore.Refs;
using NEG.UI.UnityUi;
using NEG.UI.Window;
using NegUtils.NEG.UI;
using System;
using UnityEngine;
namespace NEG.UI.Area
{
public class CloseMainWindowOnBack : MonoBehaviour, IController
public class CloseMainWindowOnBack : MonoController
{
private IControllable controllable;
public void OnOpened(object data) { }
public void OnClosed() { }
public void UseBack(IControllable.BackUsed backUsed)
protected override void UseBack(IControllable.BackUsed backUsed)
{
base.UseBack(backUsed);
UiManager.Instance.CurrentMainWindow.Close();
backUsed.Used = true;
}
private void Awake()
{
controllable = GetComponent<IControllable>();
controllable.UseBack += UseBack;
}
}
}

View File

@ -10,7 +10,7 @@ using System;
namespace NEG.UI.Area
{
public class MonoArea : MonoBehaviour, IArea, IControllable
public class MonoArea : MonoBehaviour, IArea
{
public event Action<object> OnOpened;
public event Action OnClosed;
@ -22,34 +22,38 @@ namespace NEG.UI.Area
[SerializeField] private bool setAsDefaultArea;
[SerializeField] private List<MonoWindowSlot> windowSlots;
public void Open()
{
gameObject.SetActive(true);
OnOpened?.Invoke(null);
}
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
public void Close(){
gameObject.SetActive(false);
OnClosed?.Invoke();
}
public void OpenWindow(IWindow window, object data = null) => DefaultWindowSlot.AttachWindow(window, data);
public virtual void OpenWindow(IWindow window, object data = null) => DefaultWindowSlot.AttachWindow(window, data);
protected virtual void Awake()
private void Awake()
{
if (setAsDefaultArea)
UiManager.Instance.CurrentArea = this;
}
protected void Start()
private void Start()
{
if(!setAsDefaultArea)
SetEnabled(false);
Close();
}
protected virtual void OnDestroy()
private void OnDestroy()
{
if (ReferenceEquals(UiManager.Instance.CurrentArea, this))
UiManager.Instance.CurrentArea = null;
}
public void FireOpenCallback(object data) => OnOpened?.Invoke(data);
public void FireOnClosed() => OnClosed?.Invoke();
public void FireUseBack(ref IControllable.BackUsed backUsed) => UseBack?.Invoke(backUsed);
public void TryUseBack(ref IControllable.BackUsed backUsed) => UseBack?.Invoke(backUsed);
}
}

View File

@ -7,12 +7,10 @@ namespace NEG.UI.UnityUi
{
public abstract class MonoController : MonoBehaviour, IController
{
public IControllable Controllable => controllable.Value;
[SerializeField, Self] protected InterfaceRef<IControllable> controllable;
public virtual void OnOpened(object data) { }
public virtual void OnClosed() { }
protected virtual void Awake()
{
controllable.Value.OnOpened += OnOpened;
@ -21,9 +19,11 @@ namespace NEG.UI.UnityUi
}
private void OnValidate() => this.ValidateRefs();
protected virtual void OnOpened(object data) { }
public virtual void UseBack(IControllable.BackUsed obj)
{
}
protected virtual void OnClosed() { }
protected virtual void UseBack(IControllable.BackUsed obj) { }
}
}

View File

@ -5,26 +5,15 @@ using UnityEngine;
namespace NEG.UI.UnityUi.Window
{
public class CloseWindowOnBack : MonoBehaviour, IController
public class CloseWindowOnBack : MonoController
{
[SerializeField, Self(Flag.Editable)] private MonoWindow window;
private IControllable controllable;
public void OnOpened(object data) { }
public void OnClosed() { }
public void UseBack(IControllable.BackUsed backUsed)
protected override void UseBack(IControllable.BackUsed backUsed)
{
base.UseBack(backUsed);
window.Close();
backUsed.Used = true;
}
private void Awake()
{
controllable = GetComponent<IControllable>();
controllable.UseBack += UseBack;
}
}
}

View File

@ -20,24 +20,23 @@ namespace NEG.UI.UnityUi.Window
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
public IWindowSlot Parent { get; private set; }
public IController Controller { get; }
public bool IsMainWindow { get; private set; }
private IWindowSlot DefaultWindowSlot => windowSlots[0];
[SerializeField] private List<MonoWindowSlot> windowSlots;
[SerializeField] private MonoController monoController;
[SerializeField] private GameObject defaultSelectedItem;
public void SetOpenedState(IWindowSlot parentSlot)
public void SetOpenedState(IWindowSlot parentSlot, object data)
{
gameObject.SetActive(true);
Parent = parentSlot;
EventSystem.current.SetSelectedGameObject(defaultSelectedItem);
if (parentSlot.OpenWindowAsMain)
UiManager.Instance.SetMainWindow(this);
OnOpened?.Invoke(data);
}
public void SetClosedState()
@ -46,8 +45,7 @@ namespace NEG.UI.UnityUi.Window
Parent = null;
((ISlotsHolder)this).CloseAllWindows();
UiManager.Instance.OnWindowClosed(this);
if(monoController != null)
monoController.OnClosed();
OnClosed?.Invoke();
}
public void SetHiddenState() => gameObject.SetActive(false);
@ -58,8 +56,6 @@ namespace NEG.UI.UnityUi.Window
private void OnValidate()
{
if (monoController == null)
monoController = GetComponent<MonoController>();
#if !NEG_UI_DISABLE_WARNING_DEFAULT_SELECTION
if(defaultSelectedItem == null)
Debug.LogWarning($"Window {name} should have default selected item set");
@ -70,10 +66,6 @@ namespace NEG.UI.UnityUi.Window
public void SetDefaultSelectedItem(GameObject item) => defaultSelectedItem = item;
public void FireOpenCallback(object data) => OnOpened?.Invoke(data);
public void FireOnClosed() => OnClosed?.Invoke();
public void FireUseBack(ref IControllable.BackUsed backUsed) => UseBack?.Invoke(backUsed);
public void TryUseBack(ref IControllable.BackUsed backUsed) => UseBack?.Invoke(backUsed);
}
}

View File

@ -9,11 +9,10 @@ namespace NEG.UI.WindowSlot
public IWindow CurrentWindow
{
get => currentWindow;
set
protected set
{
currentWindow?.SetClosedState();
currentWindow = value;
currentWindow?.SetOpenedState(this);
}
}
@ -22,7 +21,7 @@ namespace NEG.UI.WindowSlot
public override void AttachWindow(IWindow window, object data)
{
CurrentWindow = window;
window.FireOpenCallback(data);
window.SetOpenedState(this, data);
}
public override void DetachWindow(IWindow window) => CurrentWindow = null;

View File

@ -21,7 +21,6 @@ namespace NegUtils.NEG.UI.UnityUi.WindowSlot
currentWindow?.SetHiddenState();
currentWindow = value;
windowsHistory.Add(currentWindow);
currentWindow?.SetOpenedState(this);
}
}
@ -32,7 +31,7 @@ namespace NegUtils.NEG.UI.UnityUi.WindowSlot
public override void AttachWindow(IWindow window, object data)
{
CurrentWindow = window;
CurrentWindow.FireOpenCallback(data);
CurrentWindow.SetOpenedState(this, data);
}
public override void DetachWindow(IWindow window)

View File

@ -12,14 +12,13 @@ namespace NEG.UI.Window
/// Parent slot of this window.
/// </summary>
IWindowSlot Parent { get; }
IController Controller { get; }
/// <summary>
/// Called internally by slot to open window.
/// </summary>
/// <param name="parentSlot">slot that opens window</param>
void SetOpenedState(IWindowSlot parentSlot);
/// <param name="data">data</param>
void SetOpenedState(IWindowSlot parentSlot, object data);
/// <summary>
/// Called internally to close window by slot.