mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-01 05:13:40 +01:00
Implement INotificationManager
This commit is contained in:
parent
8e5a84792e
commit
3ba395bd70
12 changed files with 1064 additions and 307 deletions
109
Dalamud/Interface/ImGuiNotification/IActiveNotification.cs
Normal file
109
Dalamud/Interface/ImGuiNotification/IActiveNotification.cs
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
using System.Threading;
|
||||
|
||||
namespace Dalamud.Interface.ImGuiNotification;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an active notification.
|
||||
/// </summary>
|
||||
public interface IActiveNotification : INotification
|
||||
{
|
||||
/// <summary>
|
||||
/// The counter for <see cref="Id"/> field.
|
||||
/// </summary>
|
||||
private static long idCounter;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked upon dismissing the notification.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The event callback will not be called, if a user interacts with the notification after the plugin is unloaded.
|
||||
/// </remarks>
|
||||
event NotificationDismissedDelegate Dismiss;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked upon clicking on the notification.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This event is not applicable when <see cref="INotification.Interactible"/> is set to <c>false</c>.
|
||||
/// Note that this function may be called even after <see cref="Dismiss"/> has been invoked.
|
||||
/// Refer to <see cref="IsDismissed"/>.
|
||||
/// </remarks>
|
||||
event Action<IActiveNotification> Click;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the mouse enters the notification window.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This event is applicable regardless of <see cref="INotification.Interactible"/>.
|
||||
/// Note that this function may be called even after <see cref="Dismiss"/> has been invoked.
|
||||
/// Refer to <see cref="IsDismissed"/>.
|
||||
/// </remarks>
|
||||
event Action<IActiveNotification> MouseEnter;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the mouse leaves the notification window.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This event is applicable regardless of <see cref="INotification.Interactible"/>.
|
||||
/// Note that this function may be called even after <see cref="Dismiss"/> has been invoked.
|
||||
/// Refer to <see cref="IsDismissed"/>.
|
||||
/// </remarks>
|
||||
event Action<IActiveNotification> MouseLeave;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked upon drawing the action bar of the notification.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This event is applicable regardless of <see cref="INotification.Interactible"/>.
|
||||
/// Note that this function may be called even after <see cref="Dismiss"/> has been invoked.
|
||||
/// Refer to <see cref="IsDismissed"/>.
|
||||
/// </remarks>
|
||||
event Action<IActiveNotification> DrawActions;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of this notification.
|
||||
/// </summary>
|
||||
long Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the mouse cursor is on the notification window.
|
||||
/// </summary>
|
||||
bool IsMouseHovered { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the notification has been dismissed.
|
||||
/// This includes when the hide animation is being played.
|
||||
/// </summary>
|
||||
bool IsDismissed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Clones this notification as a <see cref="Notification"/>.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of <see cref="Notification"/>.</returns>
|
||||
Notification CloneNotification();
|
||||
|
||||
/// <summary>
|
||||
/// Dismisses this notification.
|
||||
/// </summary>
|
||||
void DismissNow();
|
||||
|
||||
/// <summary>
|
||||
/// Updates the notification data.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Call <see cref="UpdateIcon"/> to update the icon using the new <see cref="INotification.IconCreator"/>.
|
||||
/// </remarks>
|
||||
/// <param name="newNotification">The new notification entry.</param>
|
||||
void Update(INotification newNotification);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the icon again using <see cref="INotification.IconCreator"/>.
|
||||
/// </summary>
|
||||
void UpdateIcon();
|
||||
|
||||
/// <summary>
|
||||
/// Generates a new value to use for <see cref="Id"/>.
|
||||
/// </summary>
|
||||
/// <returns>The new value.</returns>
|
||||
internal static long CreateNewId() => Interlocked.Increment(ref idCounter);
|
||||
}
|
||||
75
Dalamud/Interface/ImGuiNotification/INotification.cs
Normal file
75
Dalamud/Interface/ImGuiNotification/INotification.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Interface.Internal;
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
|
||||
namespace Dalamud.Interface.ImGuiNotification;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a notification.
|
||||
/// </summary>
|
||||
public interface INotification
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the content body of the notification.
|
||||
/// </summary>
|
||||
string Content { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the notification.
|
||||
/// </summary>
|
||||
string? Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the notification.
|
||||
/// </summary>
|
||||
NotificationType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon creator function for the notification.<br />
|
||||
/// Currently <see cref="IDalamudTextureWrap"/>, <see cref="SeIconChar"/>, and <see cref="FontAwesomeIcon"/> types
|
||||
/// are accepted.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The icon created by the task returned will be owned by Dalamud,
|
||||
/// i.e. it will be <see cref="IDisposable.Dispose"/>d automatically as needed.<br />
|
||||
/// If <c>null</c> is supplied for this property or <see cref="Task.IsCompletedSuccessfully"/> of the returned task
|
||||
/// is <c>false</c>, then the corresponding icon with <see cref="Type"/> will be used.<br />
|
||||
/// Use <see cref="Task.FromResult{TResult}"/> if you have an instance of <see cref="IDalamudTextureWrap"/> that you
|
||||
/// can transfer ownership to Dalamud and is available for use right away.
|
||||
/// </remarks>
|
||||
Func<Task<object>>? IconCreator { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the expiry.
|
||||
/// </summary>
|
||||
DateTime Expiry { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this notification may be interacted.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Set this value to <c>true</c> if you want to respond to user inputs from
|
||||
/// <see cref="IActiveNotification.DrawActions"/>.
|
||||
/// Note that the close buttons for notifications are always provided and interactible.
|
||||
/// </remarks>
|
||||
bool Interactible { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether clicking on the notification window counts as dismissing the notification.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property has no effect if <see cref="Interactible"/> is <c>false</c>.
|
||||
/// </remarks>
|
||||
bool ClickIsDismiss { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the new duration for this notification if mouse cursor is on the notification window.
|
||||
/// If set to <see cref="TimeSpan.Zero"/> or less, then this feature is turned off.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property is applicable regardless of <see cref="Interactible"/>.
|
||||
/// </remarks>
|
||||
TimeSpan HoverExtendDuration { get; }
|
||||
}
|
||||
35
Dalamud/Interface/ImGuiNotification/Notification.cs
Normal file
35
Dalamud/Interface/ImGuiNotification/Notification.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
|
||||
namespace Dalamud.Interface.ImGuiNotification;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a blueprint for a notification.
|
||||
/// </summary>
|
||||
public sealed record Notification : INotification
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public NotificationType Type { get; set; } = NotificationType.None;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Func<Task<object>>? IconCreator { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime Expiry { get; set; } = DateTime.Now + NotificationConstants.DefaultDisplayDuration;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Interactible { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool ClickIsDismiss { get; set; } = true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TimeSpan HoverExtendDuration { get; set; } = NotificationConstants.DefaultHoverExtendDuration;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
namespace Dalamud.Interface.ImGuiNotification;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the reason of dismissal for a notification.
|
||||
/// </summary>
|
||||
public enum NotificationDismissReason
|
||||
{
|
||||
/// <summary>
|
||||
/// The notification is dismissed because the expiry specified from <see cref="INotification.Expiry"/> is met.
|
||||
/// </summary>
|
||||
Timeout = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The notification is dismissed because the user clicked on the close button on a notification window.
|
||||
/// </summary>
|
||||
Manual = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The notification is dismissed from calling <see cref="IActiveNotification.DismissNow"/>.
|
||||
/// </summary>
|
||||
Programmatical = 3,
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
namespace Dalamud.Interface.ImGuiNotification;
|
||||
|
||||
/// <summary>
|
||||
/// Delegate representing the dismissal of an active notification.
|
||||
/// </summary>
|
||||
/// <param name="notification">The notification being dismissed.</param>
|
||||
/// <param name="dismissReason">The reason of dismissal.</param>
|
||||
public delegate void NotificationDismissedDelegate(
|
||||
IActiveNotification notification,
|
||||
NotificationDismissReason dismissReason);
|
||||
Loading…
Add table
Add a link
Reference in a new issue