final touches
This commit is contained in:
parent
d3327c4360
commit
829de37cd6
@ -1,17 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using NEG.UI.WindowSlot;
|
||||||
using NEG.UI.Popup;
|
|
||||||
using NEG.UI.Window;
|
|
||||||
using NEG.UI.WindowSlot;
|
|
||||||
|
|
||||||
namespace NEG.UI.Area
|
namespace NEG.UI.Area
|
||||||
{
|
{
|
||||||
public interface IArea : ISlotsHolder, IUiElement
|
public interface IArea : ISlotsHolder, IUiElement
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Open window as child of
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="window"></param>
|
|
||||||
/// <param name="data"></param>
|
|
||||||
void OpenChildWindow(IWindow window, object data = null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,6 +2,10 @@
|
|||||||
{
|
{
|
||||||
public interface IUiElement
|
public interface IUiElement
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets only visible state of element
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="setEnabled"></param>
|
||||||
void SetEnabled(bool setEnabled);
|
void SetEnabled(bool setEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5,6 +5,12 @@ namespace NEG.UI.Popup
|
|||||||
{
|
{
|
||||||
public interface IDefaultPopup : IPopup
|
public interface IDefaultPopup : IPopup
|
||||||
{
|
{
|
||||||
public void SetContent(string title, string content, List<(string, Action)> options);
|
/// <summary>
|
||||||
|
/// Sets content based on provided data.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title">popup title</param>
|
||||||
|
/// <param name="content">popup content</param>
|
||||||
|
/// <param name="options">list of tuples (name, action on click), to set buttons. Do not pass here popup closing logic, implementing class should do it</param>
|
||||||
|
public void SetContent(string title, string content, List<(string name, Action action)> options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using NEG.UI.Area;
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace NEG.UI.Popup
|
namespace NEG.UI.Popup
|
||||||
|
|||||||
@ -1,28 +1,50 @@
|
|||||||
using System;
|
using JetBrains.Annotations;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace NEG.UI.Popup
|
namespace NEG.UI.Popup
|
||||||
{
|
{
|
||||||
|
[PublicAPI]
|
||||||
public class PopupData
|
public class PopupData
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Event that is fired on closing popup.
|
||||||
|
/// </summary>
|
||||||
public event Action<PopupData> PopupClosedEvent
|
public event Action<PopupData> PopupClosedEvent
|
||||||
{
|
{
|
||||||
add => popup.OnPopupClosed += value;
|
add => popup.OnPopupClosed += value;
|
||||||
remove => popup.OnPopupClosed -= value;
|
remove => popup.OnPopupClosed -= value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is this data is still valid. If set to false, popup will not show.
|
||||||
|
/// </summary>
|
||||||
public bool IsValid { get; protected set; }
|
public bool IsValid { get; protected set; }
|
||||||
|
|
||||||
private IPopup popup;
|
private readonly IPopup popup;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// PopupData constructor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="popup">attached to this data, can be used by different data instances</param>
|
||||||
public PopupData(IPopup popup)
|
public PopupData(IPopup popup)
|
||||||
{
|
{
|
||||||
this.popup = popup;
|
this.popup = popup;
|
||||||
IsValid = true;
|
IsValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Show popup and pass needed data.
|
||||||
|
/// </summary>
|
||||||
public virtual void Show() => popup.Show(this);
|
public virtual void Show() => popup.Show(this);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hide popup. Close visuals without firing events;
|
||||||
|
/// </summary>
|
||||||
public virtual void Hide() => popup.Close(true);
|
public virtual void Hide() => popup.Close(true);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invalidate popup, <see cref="UiManager"/> will automatically skip this popup
|
||||||
|
/// </summary>
|
||||||
public virtual void Invalidate() => IsValid = false;
|
public virtual void Invalidate() => IsValid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5,6 +5,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace NEG.UI.Area
|
namespace NEG.UI.Area
|
||||||
{
|
{
|
||||||
|
[Tooltip(tooltip: "Automatically open attached window on start")]
|
||||||
public class AutoWindowOpen : MonoBehaviour
|
public class AutoWindowOpen : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private MonoWindow window;
|
[SerializeField] private MonoWindow window;
|
||||||
|
|||||||
@ -18,18 +18,8 @@ namespace NEG.UI.Area
|
|||||||
|
|
||||||
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
||||||
|
|
||||||
private Queue<IPopup> currentPopups = new();
|
|
||||||
|
|
||||||
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
|
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)
|
public virtual void OpenWindow(IWindow window, object data = null)
|
||||||
{
|
{
|
||||||
DefaultWindowSlot.AttachWindow(window);
|
DefaultWindowSlot.AttachWindow(window);
|
||||||
|
|||||||
@ -8,7 +8,6 @@ namespace NEG.UI.UnityUi.Buttons
|
|||||||
[RequireComponent(typeof(BaseButton))]
|
[RequireComponent(typeof(BaseButton))]
|
||||||
public class CloseWindow : MonoBehaviour
|
public class CloseWindow : MonoBehaviour
|
||||||
{
|
{
|
||||||
[Header("Set by hand or use editor button")]
|
|
||||||
[SerializeField] private MonoWindow windowToClose;
|
[SerializeField] private MonoWindow windowToClose;
|
||||||
|
|
||||||
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked;
|
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using NEG.UI.UnityUi.Buttons;
|
using JetBrains.Annotations;
|
||||||
|
using NEG.UI.UnityUi.Buttons;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -6,9 +7,17 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace NEG.UI.UnityUi
|
namespace NEG.UI.UnityUi
|
||||||
{
|
{
|
||||||
|
[PublicAPI]
|
||||||
public class CarouselList : MonoBehaviour
|
public class CarouselList : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Current option
|
||||||
|
/// </summary>
|
||||||
public string CurrentOption { get; private set; }
|
public string CurrentOption { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Current selected option id
|
||||||
|
/// </summary>
|
||||||
public int CurrentOptionId { get; private set; }
|
public int CurrentOptionId { get; private set; }
|
||||||
|
|
||||||
[SerializeField] private BaseButton nextButton;
|
[SerializeField] private BaseButton nextButton;
|
||||||
@ -17,6 +26,10 @@ namespace NEG.UI.UnityUi
|
|||||||
|
|
||||||
private List<string> options;
|
private List<string> options;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets new options list, automatically first will be selected.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="options">list of options names</param>
|
||||||
public void SetOptions(List<string> options)
|
public void SetOptions(List<string> options)
|
||||||
{
|
{
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -25,7 +38,11 @@ namespace NEG.UI.UnityUi
|
|||||||
|
|
||||||
public void SelectNextOption() => ChangeOption(true);
|
public void SelectNextOption() => ChangeOption(true);
|
||||||
public void SelectPrevOption() => ChangeOption(false);
|
public void SelectPrevOption() => ChangeOption(false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Selects option with provided id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="option">option number</param>
|
||||||
public void SelectOption(int option)
|
public void SelectOption(int option)
|
||||||
{
|
{
|
||||||
if (option < 0 || option >= options.Count)
|
if (option < 0 || option >= options.Count)
|
||||||
@ -39,7 +56,7 @@ namespace NEG.UI.UnityUi
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Select option with provided value. Use with caution, better use <see cref="SelectOption(int)"/>
|
/// Select option with provided value. Use with caution, better use <see cref="SelectOption(int)"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="option">option value to select</param>
|
/// <param name="option">option value to select</param>
|
||||||
public void SelectOption(string option)
|
public void SelectOption(string option)
|
||||||
|
|||||||
@ -75,23 +75,32 @@ namespace NEG.UI.Window
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Open window as child of provided window. If <typeparamref name="parentWindow"/> is null, as child of current main window in <see cref="UiManager"/>
|
/// Open window as child of provided window. If <typeparamref name="parentWindow"/> is null, as child of current main window in <see cref="UiManager"/>. If there is no main window, open on current area.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="window">window to open</param>
|
/// <param name="window">window to open</param>
|
||||||
/// <param name="parentWindow"></param>
|
/// <param name="parentWindow">parent window</param>
|
||||||
/// <param name="data"></param>
|
/// <param name="data">data to send to window</param>
|
||||||
public static void OpenAsChild(this IWindow window, IWindow parentWindow = null, object data = null)
|
public static void OpenAsChild(this IWindow window, IWindow parentWindow = null, object data = null)
|
||||||
{
|
{
|
||||||
if (parentWindow != null)
|
if (parentWindow != null)
|
||||||
{
|
{
|
||||||
parentWindow.OpenWindow(window);
|
parentWindow.OpenWindow(window, data);
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Close window.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="window">window to close</param>
|
||||||
public static void Close(this IWindow window) => window.Parent.DetachWindow(window);
|
public static void Close(this IWindow window) => window.Parent.DetachWindow(window);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user