final touches
This commit is contained in:
parent
d3327c4360
commit
829de37cd6
@ -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
|
||||
{
|
||||
/// <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
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets only visible state of element
|
||||
/// </summary>
|
||||
/// <param name="setEnabled"></param>
|
||||
void SetEnabled(bool setEnabled);
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,12 @@ namespace NEG.UI.Popup
|
||||
{
|
||||
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 NEG.UI.Area;
|
||||
using System;
|
||||
|
||||
namespace NEG.UI.Popup
|
||||
|
||||
@ -1,28 +1,50 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
|
||||
namespace NEG.UI.Popup
|
||||
{
|
||||
[PublicAPI]
|
||||
public class PopupData
|
||||
{
|
||||
/// <summary>
|
||||
/// Event that is fired on closing popup.
|
||||
/// </summary>
|
||||
public event Action<PopupData> PopupClosedEvent
|
||||
{
|
||||
add => 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; }
|
||||
|
||||
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)
|
||||
{
|
||||
this.popup = popup;
|
||||
IsValid = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show popup and pass needed data.
|
||||
/// </summary>
|
||||
public virtual void Show() => popup.Show(this);
|
||||
|
||||
/// <summary>
|
||||
/// Hide popup. Close visuals without firing events;
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -18,18 +18,8 @@ namespace NEG.UI.Area
|
||||
|
||||
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
||||
|
||||
private Queue<IPopup> 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);
|
||||
|
||||
@ -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<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 TMPro;
|
||||
using UnityEngine;
|
||||
@ -6,9 +7,17 @@ using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi
|
||||
{
|
||||
[PublicAPI]
|
||||
public class CarouselList : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Current option
|
||||
/// </summary>
|
||||
public string CurrentOption { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current selected option id
|
||||
/// </summary>
|
||||
public int CurrentOptionId { get; private set; }
|
||||
|
||||
[SerializeField] private BaseButton nextButton;
|
||||
@ -17,6 +26,10 @@ namespace NEG.UI.UnityUi
|
||||
|
||||
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)
|
||||
{
|
||||
this.options = options;
|
||||
@ -26,6 +39,10 @@ namespace NEG.UI.UnityUi
|
||||
public void SelectNextOption() => ChangeOption(true);
|
||||
public void SelectPrevOption() => ChangeOption(false);
|
||||
|
||||
/// <summary>
|
||||
/// Selects option with provided id.
|
||||
/// </summary>
|
||||
/// <param name="option">option number</param>
|
||||
public void SelectOption(int option)
|
||||
{
|
||||
if (option < 0 || option >= options.Count)
|
||||
@ -39,7 +56,7 @@ namespace NEG.UI.UnityUi
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <param name="option">option value to select</param>
|
||||
public void SelectOption(string option)
|
||||
|
||||
@ -75,23 +75,32 @@ namespace NEG.UI.Window
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <param name="window">window to open</param>
|
||||
/// <param name="parentWindow"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="parentWindow">parent window</param>
|
||||
/// <param name="data">data to send to window</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close window.
|
||||
/// </summary>
|
||||
/// <param name="window">window to close</param>
|
||||
public static void Close(this IWindow window) => window.Parent.DetachWindow(window);
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user