New componnets
This commit is contained in:
parent
34807988d8
commit
9c91269a9e
@ -1,9 +1,9 @@
|
||||
using NEG.UI.WindowSlot;
|
||||
using NegUtils.NEG.UI;
|
||||
|
||||
namespace NEG.UI.Area
|
||||
{
|
||||
public interface IArea : ISlotsHolder, IUiElement
|
||||
public interface IArea : ISlotsHolder, IUiElement, IControllable
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
23
NEG/UI/IControllable.cs
Normal file
23
NEG/UI/IControllable.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace NegUtils.NEG.UI
|
||||
{
|
||||
public interface IControllable
|
||||
{
|
||||
public class BackUsed
|
||||
{
|
||||
public bool Used { get; set; }
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
3
NEG/UI/IControllable.cs.meta
Normal file
3
NEG/UI/IControllable.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 175798310e4048eda768cf40e6ee6de3
|
||||
timeCreated: 1686596400
|
||||
11
NEG/UI/IController.cs
Normal file
11
NEG/UI/IController.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace NegUtils.NEG.UI
|
||||
{
|
||||
public interface IController
|
||||
{
|
||||
void OnOpened(object data);
|
||||
|
||||
void OnClosed();
|
||||
|
||||
void UseBack(IControllable.BackUsed backUsed);
|
||||
}
|
||||
}
|
||||
3
NEG/UI/IController.cs.meta
Normal file
3
NEG/UI/IController.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b88f4a93020a4bc6bde40e0438d296a9
|
||||
timeCreated: 1686595825
|
||||
@ -3,6 +3,7 @@ using NEG.UI.Area;
|
||||
using NEG.UI.Popup;
|
||||
using NEG.UI.Window;
|
||||
using NEG.Utils;
|
||||
using NegUtils.NEG.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -125,6 +126,17 @@ namespace NEG.UI
|
||||
UpdatePopupsState(forceShow, priority, data);
|
||||
}
|
||||
|
||||
public void UseBack()
|
||||
{
|
||||
IControllable.BackUsed backUsed = new();
|
||||
|
||||
CurrentMainWindow?.FireUseBack(ref backUsed);
|
||||
if(backUsed.Used)
|
||||
return;
|
||||
CurrentArea.FireUseBack(ref backUsed);
|
||||
}
|
||||
|
||||
|
||||
public void RefreshPopups()
|
||||
{
|
||||
if(currentShownPopup.data is { IsValid: true })
|
||||
@ -134,6 +146,16 @@ namespace NEG.UI
|
||||
|
||||
public virtual void Dispose() => Instance = null;
|
||||
|
||||
public void SetMainWindow(IWindow window) => CurrentMainWindow = window;
|
||||
|
||||
public void OnWindowClosed(IWindow window)
|
||||
{
|
||||
if(CurrentMainWindow != window)
|
||||
return;
|
||||
|
||||
//TODO: select new main window
|
||||
}
|
||||
|
||||
protected void PopupClosed(PopupData data)
|
||||
{
|
||||
if (currentShownPopup.data != data)
|
||||
|
||||
27
NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs
Normal file
27
NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using NEG.UI.Window;
|
||||
using NegUtils.NEG.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.Area
|
||||
{
|
||||
public class CloseMainWindowOnBack : MonoBehaviour, IController
|
||||
{
|
||||
private IControllable controllable;
|
||||
|
||||
public void OnOpened(object data) { }
|
||||
|
||||
public void OnClosed() { }
|
||||
|
||||
public void UseBack(IControllable.BackUsed backUsed)
|
||||
{
|
||||
UiManager.Instance.CurrentMainWindow.Close();
|
||||
backUsed.Used = true;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
controllable = GetComponent<IControllable>();
|
||||
controllable.UseBack += UseBack;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs.meta
Normal file
3
NEG/UI/UnityUi/Area/CloseMainWindowOnBack.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ec2bf64cda740a1849d024d4f163a01
|
||||
timeCreated: 1686598066
|
||||
@ -5,12 +5,17 @@ using NEG.UI.UnityUi.Window;
|
||||
using NEG.UI.UnityUi.WindowSlot;
|
||||
using NEG.UI.Window;
|
||||
using NEG.UI.WindowSlot;
|
||||
using NegUtils.NEG.UI;
|
||||
using System;
|
||||
|
||||
namespace NEG.UI.Area
|
||||
{
|
||||
public class MonoArea : MonoBehaviour, IArea
|
||||
{
|
||||
public event Action<object> OnOpened;
|
||||
public event Action OnClosed;
|
||||
public event Action<IControllable.BackUsed> UseBack;
|
||||
|
||||
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
||||
public IWindowSlot DefaultWindowSlot => windowSlots[0];
|
||||
|
||||
@ -20,11 +25,7 @@ namespace NEG.UI.Area
|
||||
|
||||
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
|
||||
|
||||
public virtual void OpenWindow(IWindow window, object data = null)
|
||||
{
|
||||
DefaultWindowSlot.AttachWindow(window);
|
||||
window.SetData(data);
|
||||
}
|
||||
public virtual void OpenWindow(IWindow window, object data = null) => DefaultWindowSlot.AttachWindow(window, data);
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
@ -37,5 +38,12 @@ namespace NEG.UI.Area
|
||||
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);
|
||||
}
|
||||
}
|
||||
15
NEG/UI/UnityUi/Buttons/OpenAsCurrentMainChild.cs
Normal file
15
NEG/UI/UnityUi/Buttons/OpenAsCurrentMainChild.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using KBCore.Refs;
|
||||
using NEG.UI.UnityUi.Window;
|
||||
using NEG.UI.Window;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
public class OpenAsCurrentMainChild : ButtonReaction
|
||||
{
|
||||
[SerializeField]
|
||||
private MonoWindow windowToOpen;
|
||||
|
||||
protected override void OnClicked() => UiManager.Instance.CurrentMainWindow.OpenAsChild(windowToOpen);
|
||||
}
|
||||
}
|
||||
3
NEG/UI/UnityUi/Buttons/OpenAsCurrentMainChild.cs.meta
Normal file
3
NEG/UI/UnityUi/Buttons/OpenAsCurrentMainChild.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 049e222140c94fc28fb36bca4aaddba4
|
||||
timeCreated: 1686595194
|
||||
30
NEG/UI/UnityUi/Window/CloseWindowOnBack.cs
Normal file
30
NEG/UI/UnityUi/Window/CloseWindowOnBack.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using KBCore.Refs;
|
||||
using NEG.UI.Window;
|
||||
using NegUtils.NEG.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Window
|
||||
{
|
||||
public class CloseWindowOnBack : MonoBehaviour, IController
|
||||
{
|
||||
[SerializeField, Self(Flag.Editable)] private MonoWindow window;
|
||||
|
||||
private IControllable controllable;
|
||||
|
||||
public void OnOpened(object data) { }
|
||||
|
||||
public void OnClosed() { }
|
||||
|
||||
public void UseBack(IControllable.BackUsed backUsed)
|
||||
{
|
||||
window.Close();
|
||||
backUsed.Used = true;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
controllable = GetComponent<IControllable>();
|
||||
controllable.UseBack += UseBack;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
NEG/UI/UnityUi/Window/CloseWindowOnBack.cs.meta
Normal file
3
NEG/UI/UnityUi/Window/CloseWindowOnBack.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4a156da6df74abeb281176000738ebb
|
||||
timeCreated: 1686598323
|
||||
@ -3,6 +3,7 @@ using NEG.UI.UnityUi.Buttons;
|
||||
using NEG.UI.UnityUi.WindowSlot;
|
||||
using NEG.UI.Window;
|
||||
using NEG.UI.WindowSlot;
|
||||
using NegUtils.NEG.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -12,8 +13,13 @@ namespace NEG.UI.UnityUi.Window
|
||||
{
|
||||
public class MonoWindow : MonoBehaviour, IWindow
|
||||
{
|
||||
public event Action<object> OnOpened;
|
||||
public event Action OnClosed;
|
||||
public event Action<IControllable.BackUsed> UseBack;
|
||||
|
||||
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
||||
public IWindowSlot Parent { get; private set; }
|
||||
public IController Controller { get; }
|
||||
|
||||
public bool IsMainWindow { get; private set; }
|
||||
|
||||
@ -29,14 +35,8 @@ namespace NEG.UI.UnityUi.Window
|
||||
gameObject.SetActive(true);
|
||||
Parent = parentSlot;
|
||||
EventSystem.current.SetSelectedGameObject(defaultSelectedItem);
|
||||
if (controller != null)
|
||||
controller.OnOpened();
|
||||
}
|
||||
|
||||
public void SetData(object data)
|
||||
{
|
||||
if (controller != null)
|
||||
controller.SetData(data);
|
||||
if (parentSlot.OpenWindowAsMain)
|
||||
UiManager.Instance.SetMainWindow(this);
|
||||
}
|
||||
|
||||
public void SetClosedState()
|
||||
@ -44,6 +44,7 @@ namespace NEG.UI.UnityUi.Window
|
||||
gameObject.SetActive(false);
|
||||
Parent = null;
|
||||
((ISlotsHolder)this).CloseAllWindows();
|
||||
UiManager.Instance.OnWindowClosed(this);
|
||||
if(controller != null)
|
||||
controller.OnClosed();
|
||||
}
|
||||
@ -64,12 +65,14 @@ namespace NEG.UI.UnityUi.Window
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OpenWindow(IWindow window, object data = null)
|
||||
{
|
||||
DefaultWindowSlot.AttachWindow(window);
|
||||
window.SetData(data);
|
||||
}
|
||||
public void OpenWindow(IWindow window, object data = null) => DefaultWindowSlot.AttachWindow(window, data);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -1,20 +1,27 @@
|
||||
using System;
|
||||
using NegUtils.NEG.UI;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Window
|
||||
{
|
||||
[RequireComponent(typeof(MonoWindow))]
|
||||
//Due to prefab variants we need this
|
||||
public abstract class WindowController : MonoBehaviour
|
||||
public abstract class WindowController : MonoBehaviour, IController
|
||||
{
|
||||
protected MonoWindow window;
|
||||
protected IControllable controllable;
|
||||
|
||||
public abstract void SetData(object data);
|
||||
|
||||
public virtual void OnOpened() { }
|
||||
public virtual void OnOpened(object data) { }
|
||||
|
||||
public virtual void OnClosed() { }
|
||||
|
||||
protected virtual void Awake() => window = GetComponent<MonoWindow>();
|
||||
protected virtual void Awake()
|
||||
{
|
||||
controllable = GetComponent<IControllable>();
|
||||
controllable.OnOpened += OnOpened;
|
||||
controllable.OnClosed += OnClosed;
|
||||
controllable.UseBack += UseBack;
|
||||
}
|
||||
|
||||
public void UseBack(IControllable.BackUsed obj)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,7 @@ namespace NEG.UI.UnityUi.WindowSlot
|
||||
[field: SerializeField] public bool OpenWindowAsMain { get; private set; }
|
||||
|
||||
public ISlotsHolder ParentHolder => slotsHolder.Value;
|
||||
public abstract void AttachWindow(IWindow window);
|
||||
public abstract void AttachWindow(IWindow window, object data);
|
||||
public abstract void DetachWindow(IWindow window);
|
||||
public abstract void CloseAllWindows();
|
||||
|
||||
|
||||
@ -19,7 +19,12 @@ namespace NEG.UI.WindowSlot
|
||||
|
||||
private IWindow currentWindow;
|
||||
|
||||
public override void AttachWindow(IWindow window) => CurrentWindow = window;
|
||||
public override void AttachWindow(IWindow window, object data)
|
||||
{
|
||||
CurrentWindow = window;
|
||||
window.FireOpenCallback(data);
|
||||
}
|
||||
|
||||
public override void DetachWindow(IWindow window) => CurrentWindow = null;
|
||||
public override void CloseAllWindows() => CurrentWindow = null;
|
||||
}
|
||||
|
||||
@ -29,7 +29,11 @@ namespace NegUtils.NEG.UI.UnityUi.WindowSlot
|
||||
|
||||
private readonly List<IWindow> windowsHistory = new List<IWindow>();
|
||||
|
||||
public override void AttachWindow(IWindow window) => CurrentWindow = window;
|
||||
public override void AttachWindow(IWindow window, object data)
|
||||
{
|
||||
CurrentWindow = window;
|
||||
CurrentWindow.FireOpenCallback(data);
|
||||
}
|
||||
|
||||
public override void DetachWindow(IWindow window)
|
||||
{
|
||||
|
||||
@ -1,29 +1,26 @@
|
||||
using JetBrains.Annotations;
|
||||
using NEG.UI.Area;
|
||||
using NEG.UI.WindowSlot;
|
||||
using NegUtils.NEG.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.Window
|
||||
{
|
||||
public interface IWindow : ISlotsHolder
|
||||
public interface IWindow : ISlotsHolder, IControllable
|
||||
{
|
||||
/// <summary>
|
||||
/// 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);
|
||||
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
/// Called internally to close window by slot.
|
||||
/// </summary>
|
||||
@ -52,8 +49,7 @@ namespace NEG.UI.Window
|
||||
{
|
||||
if (slot != null)
|
||||
{
|
||||
slot.AttachWindow(window);
|
||||
window.SetData(data);
|
||||
slot.AttachWindow(window, data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -3,11 +3,11 @@ using NEG.UI.Window;
|
||||
|
||||
namespace NEG.UI.WindowSlot
|
||||
{
|
||||
public interface IWindowSlot
|
||||
public interface IWindowSlot
|
||||
{
|
||||
bool OpenWindowAsMain { get; }
|
||||
ISlotsHolder ParentHolder { get; }
|
||||
void AttachWindow(IWindow window);
|
||||
void AttachWindow(IWindow window, object data);
|
||||
void DetachWindow(IWindow window);
|
||||
void CloseAllWindows();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user