From 829de37cd6cf3e3675b1ea6ce3412aed392815bb Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Thu, 2 Feb 2023 16:36:57 +0100 Subject: [PATCH] final touches --- NEG/UI/Area/IArea.cs | 12 ++-------- NEG/UI/IUiElement.cs | 4 ++++ NEG/UI/Popup/IDefaultPopup.cs | 8 ++++++- NEG/UI/Popup/IPopup.cs | 1 - NEG/UI/Popup/PopupData.cs | 26 +++++++++++++++++++-- NEG/UI/UnityUi/Area/AutoWindowOpen.cs | 1 + NEG/UI/UnityUi/Area/MonoArea.cs | 10 -------- NEG/UI/UnityUi/Buttons/CloseWindow.cs | 1 - NEG/UI/UnityUi/CarouselList/CarouselList.cs | 23 +++++++++++++++--- NEG/UI/Window/IWindow.cs | 23 ++++++++++++------ 10 files changed, 74 insertions(+), 35 deletions(-) diff --git a/NEG/UI/Area/IArea.cs b/NEG/UI/Area/IArea.cs index e9942f9..4c84e27 100644 --- a/NEG/UI/Area/IArea.cs +++ b/NEG/UI/Area/IArea.cs @@ -1,17 +1,9 @@ -using System.Collections.Generic; -using NEG.UI.Popup; -using NEG.UI.Window; -using NEG.UI.WindowSlot; +using NEG.UI.WindowSlot; namespace NEG.UI.Area { public interface IArea : ISlotsHolder, IUiElement { - /// - /// Open window as child of - /// - /// - /// - void OpenChildWindow(IWindow window, object data = null); + } } \ No newline at end of file diff --git a/NEG/UI/IUiElement.cs b/NEG/UI/IUiElement.cs index f41a14e..6cfde2b 100644 --- a/NEG/UI/IUiElement.cs +++ b/NEG/UI/IUiElement.cs @@ -2,6 +2,10 @@ { public interface IUiElement { + /// + /// Sets only visible state of element + /// + /// void SetEnabled(bool setEnabled); } } \ No newline at end of file diff --git a/NEG/UI/Popup/IDefaultPopup.cs b/NEG/UI/Popup/IDefaultPopup.cs index 89ac826..6a9216d 100644 --- a/NEG/UI/Popup/IDefaultPopup.cs +++ b/NEG/UI/Popup/IDefaultPopup.cs @@ -5,6 +5,12 @@ namespace NEG.UI.Popup { public interface IDefaultPopup : IPopup { - public void SetContent(string title, string content, List<(string, Action)> options); + /// + /// Sets content based on provided data. + /// + /// popup title + /// popup content + /// list of tuples (name, action on click), to set buttons. Do not pass here popup closing logic, implementing class should do it + public void SetContent(string title, string content, List<(string name, Action action)> options); } } \ No newline at end of file diff --git a/NEG/UI/Popup/IPopup.cs b/NEG/UI/Popup/IPopup.cs index 7d33066..1813467 100644 --- a/NEG/UI/Popup/IPopup.cs +++ b/NEG/UI/Popup/IPopup.cs @@ -1,5 +1,4 @@ using JetBrains.Annotations; -using NEG.UI.Area; using System; namespace NEG.UI.Popup diff --git a/NEG/UI/Popup/PopupData.cs b/NEG/UI/Popup/PopupData.cs index a936b2a..6bf528a 100644 --- a/NEG/UI/Popup/PopupData.cs +++ b/NEG/UI/Popup/PopupData.cs @@ -1,28 +1,50 @@ -using System; +using JetBrains.Annotations; +using System; namespace NEG.UI.Popup { + [PublicAPI] public class PopupData { + /// + /// Event that is fired on closing popup. + /// public event Action PopupClosedEvent { add => popup.OnPopupClosed += value; remove => popup.OnPopupClosed -= value; } + /// + /// Is this data is still valid. If set to false, popup will not show. + /// public bool IsValid { get; protected set; } - private IPopup popup; + private readonly IPopup popup; + /// + /// PopupData constructor. + /// + /// attached to this data, can be used by different data instances public PopupData(IPopup popup) { this.popup = popup; IsValid = true; } + /// + /// Show popup and pass needed data. + /// public virtual void Show() => popup.Show(this); + + /// + /// Hide popup. Close visuals without firing events; + /// public virtual void Hide() => popup.Close(true); + /// + /// Invalidate popup, will automatically skip this popup + /// public virtual void Invalidate() => IsValid = false; } } \ No newline at end of file diff --git a/NEG/UI/UnityUi/Area/AutoWindowOpen.cs b/NEG/UI/UnityUi/Area/AutoWindowOpen.cs index 1f87e17..b19f017 100644 --- a/NEG/UI/UnityUi/Area/AutoWindowOpen.cs +++ b/NEG/UI/UnityUi/Area/AutoWindowOpen.cs @@ -5,6 +5,7 @@ using UnityEngine; namespace NEG.UI.Area { + [Tooltip(tooltip: "Automatically open attached window on start")] public class AutoWindowOpen : MonoBehaviour { [SerializeField] private MonoWindow window; diff --git a/NEG/UI/UnityUi/Area/MonoArea.cs b/NEG/UI/UnityUi/Area/MonoArea.cs index 77b2166..e5f92b0 100644 --- a/NEG/UI/UnityUi/Area/MonoArea.cs +++ b/NEG/UI/UnityUi/Area/MonoArea.cs @@ -18,18 +18,8 @@ namespace NEG.UI.Area [SerializeField] private List windowSlots; - private Queue currentPopups = new(); - public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled); - public void OpenChildWindow(IWindow window, object data = null) - { - foreach (var slot in AvailableSlots) - { - - } - } - public virtual void OpenWindow(IWindow window, object data = null) { DefaultWindowSlot.AttachWindow(window); diff --git a/NEG/UI/UnityUi/Buttons/CloseWindow.cs b/NEG/UI/UnityUi/Buttons/CloseWindow.cs index 2fdc9ae..529b255 100644 --- a/NEG/UI/UnityUi/Buttons/CloseWindow.cs +++ b/NEG/UI/UnityUi/Buttons/CloseWindow.cs @@ -8,7 +8,6 @@ namespace NEG.UI.UnityUi.Buttons [RequireComponent(typeof(BaseButton))] public class CloseWindow : MonoBehaviour { - [Header("Set by hand or use editor button")] [SerializeField] private MonoWindow windowToClose; private void Awake() => GetComponent().OnButtonPressed += OnClicked; diff --git a/NEG/UI/UnityUi/CarouselList/CarouselList.cs b/NEG/UI/UnityUi/CarouselList/CarouselList.cs index e9e08b9..708c069 100644 --- a/NEG/UI/UnityUi/CarouselList/CarouselList.cs +++ b/NEG/UI/UnityUi/CarouselList/CarouselList.cs @@ -1,4 +1,5 @@ -using NEG.UI.UnityUi.Buttons; +using JetBrains.Annotations; +using NEG.UI.UnityUi.Buttons; using System.Collections.Generic; using TMPro; using UnityEngine; @@ -6,9 +7,17 @@ using UnityEngine; namespace NEG.UI.UnityUi { + [PublicAPI] public class CarouselList : MonoBehaviour { + /// + /// Current option + /// public string CurrentOption { get; private set; } + + /// + /// Current selected option id + /// public int CurrentOptionId { get; private set; } [SerializeField] private BaseButton nextButton; @@ -17,6 +26,10 @@ namespace NEG.UI.UnityUi private List options; + /// + /// Sets new options list, automatically first will be selected. + /// + /// list of options names public void SetOptions(List options) { this.options = options; @@ -25,7 +38,11 @@ namespace NEG.UI.UnityUi public void SelectNextOption() => ChangeOption(true); public void SelectPrevOption() => ChangeOption(false); - + + /// + /// Selects option with provided id. + /// + /// option number public void SelectOption(int option) { if (option < 0 || option >= options.Count) @@ -39,7 +56,7 @@ namespace NEG.UI.UnityUi } /// - /// Select option with provided value. Use with caution, better use + /// Select option with provided value. Use with caution, better use . /// /// option value to select public void SelectOption(string option) diff --git a/NEG/UI/Window/IWindow.cs b/NEG/UI/Window/IWindow.cs index ad866fb..567bc7f 100644 --- a/NEG/UI/Window/IWindow.cs +++ b/NEG/UI/Window/IWindow.cs @@ -75,23 +75,32 @@ namespace NEG.UI.Window } /// - /// Open window as child of provided window. If is null, as child of current main window in + /// Open window as child of provided window. If is null, as child of current main window in . If there is no main window, open on current area. /// /// window to open - /// - /// + /// parent window + /// data to send to window public static void OpenAsChild(this IWindow window, IWindow parentWindow = null, object data = null) { if (parentWindow != null) { - parentWindow.OpenWindow(window); + parentWindow.OpenWindow(window, data); return; } - UiManager.Instance.CurrentArea.OpenChildWindow(window, data); + if (UiManager.Instance.CurrentMainWindow != null) + { + UiManager.Instance.CurrentMainWindow.OpenWindow(window, data); + return; + } + + UiManager.Instance.CurrentArea.OpenWindow(window, data); } - + + /// + /// Close window. + /// + /// window to close public static void Close(this IWindow window) => window.Parent.DetachWindow(window); - } } \ No newline at end of file