From 63d3d908e8baa5a7a7ac03dadfc641b0905c25f3 Mon Sep 17 00:00:00 2001 From: Kamila Stawarska Date: Sun, 20 Aug 2023 14:07:45 +0200 Subject: [PATCH] Naming update --- NEG/UI/UnityUi/Area/MonoArea.cs | 4 ++- NEG/UI/UnityUi/MonoController.cs | 29 +++++++++++++++++++ ...troller.cs.meta => MonoController.cs.meta} | 0 NEG/UI/UnityUi/Window/MonoWindow.cs | 11 +++---- NEG/UI/UnityUi/Window/WindowController.cs | 27 ----------------- 5 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 NEG/UI/UnityUi/MonoController.cs rename NEG/UI/UnityUi/{Window/WindowController.cs.meta => MonoController.cs.meta} (100%) delete mode 100644 NEG/UI/UnityUi/Window/WindowController.cs diff --git a/NEG/UI/UnityUi/Area/MonoArea.cs b/NEG/UI/UnityUi/Area/MonoArea.cs index b79a409..e603e89 100644 --- a/NEG/UI/UnityUi/Area/MonoArea.cs +++ b/NEG/UI/UnityUi/Area/MonoArea.cs @@ -10,7 +10,7 @@ using System; namespace NEG.UI.Area { - public class MonoArea : MonoBehaviour, IArea + public class MonoArea : MonoBehaviour, IArea, IControllable { public event Action OnOpened; public event Action OnClosed; @@ -31,6 +31,8 @@ namespace NEG.UI.Area { if (setAsDefaultArea) UiManager.Instance.CurrentArea = this; + else + SetEnabled(false); } protected virtual void OnDestroy() diff --git a/NEG/UI/UnityUi/MonoController.cs b/NEG/UI/UnityUi/MonoController.cs new file mode 100644 index 0000000..d2d6640 --- /dev/null +++ b/NEG/UI/UnityUi/MonoController.cs @@ -0,0 +1,29 @@ +using KBCore.Refs; +using NegUtils.NEG.UI; +using System; +using UnityEngine; + +namespace NEG.UI.UnityUi +{ + public abstract class MonoController : MonoBehaviour, IController + { + [SerializeField, Self] protected InterfaceRef controllable; + + public virtual void OnOpened(object data) { } + + public virtual void OnClosed() { } + + protected virtual void Awake() + { + controllable.Value.OnOpened += OnOpened; + controllable.Value.OnClosed += OnClosed; + controllable.Value.UseBack += UseBack; + } + + private void OnValidate() => this.ValidateRefs(); + + public virtual void UseBack(IControllable.BackUsed obj) + { + } + } +} \ No newline at end of file diff --git a/NEG/UI/UnityUi/Window/WindowController.cs.meta b/NEG/UI/UnityUi/MonoController.cs.meta similarity index 100% rename from NEG/UI/UnityUi/Window/WindowController.cs.meta rename to NEG/UI/UnityUi/MonoController.cs.meta diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs b/NEG/UI/UnityUi/Window/MonoWindow.cs index 219265e..8027e00 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; +using UnityEngine.Serialization; namespace NEG.UI.UnityUi.Window { @@ -26,7 +27,7 @@ namespace NEG.UI.UnityUi.Window private IWindowSlot DefaultWindowSlot => windowSlots[0]; [SerializeField] private List windowSlots; - [SerializeField] private WindowController controller; + [SerializeField] private MonoController monoController; [SerializeField] private GameObject defaultSelectedItem; @@ -45,8 +46,8 @@ namespace NEG.UI.UnityUi.Window Parent = null; ((ISlotsHolder)this).CloseAllWindows(); UiManager.Instance.OnWindowClosed(this); - if(controller != null) - controller.OnClosed(); + if(monoController != null) + monoController.OnClosed(); } public void SetHiddenState() => gameObject.SetActive(false); @@ -57,8 +58,8 @@ namespace NEG.UI.UnityUi.Window private void OnValidate() { - if (controller == null) - controller = GetComponent(); + if (monoController == null) + monoController = GetComponent(); #if !NEG_UI_DISABLE_WARNING_DEFAULT_SELECTION if(defaultSelectedItem == null) Debug.LogWarning($"Window {name} should have default selected item set"); diff --git a/NEG/UI/UnityUi/Window/WindowController.cs b/NEG/UI/UnityUi/Window/WindowController.cs deleted file mode 100644 index 4be335c..0000000 --- a/NEG/UI/UnityUi/Window/WindowController.cs +++ /dev/null @@ -1,27 +0,0 @@ -using NegUtils.NEG.UI; -using System; -using UnityEngine; - -namespace NEG.UI.UnityUi.Window -{ - public abstract class WindowController : MonoBehaviour, IController - { - protected IControllable controllable; - - public virtual void OnOpened(object data) { } - - public virtual void OnClosed() { } - - protected virtual void Awake() - { - controllable = GetComponent(); - controllable.OnOpened += OnOpened; - controllable.OnClosed += OnClosed; - controllable.UseBack += UseBack; - } - - public void UseBack(IControllable.BackUsed obj) - { - } - } -} \ No newline at end of file