Neg_Utils/NEG/UI/Popup/PopupData.cs
2023-02-02 16:36:57 +01:00

50 lines
1.4 KiB
C#

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 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;
}
}