Add progressbar

This commit is contained in:
Soreepeong 2024-02-25 23:42:01 +09:00
parent 199722d29a
commit 04c6be5671
6 changed files with 698 additions and 286 deletions

View file

@ -1,28 +1,24 @@
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Game.Text;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Internal.Notifications;
namespace Dalamud.Interface.ImGuiNotification;
/// <summary>
/// Represents an active notification.
/// </summary>
/// <summary>Represents an active notification.</summary>
public interface IActiveNotification : INotification
{
/// <summary>
/// The counter for <see cref="Id"/> field.
/// </summary>
/// <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>
/// <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>
/// <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.
@ -30,9 +26,7 @@ public interface IActiveNotification : INotification
/// </remarks>
event Action<IActiveNotification> Click;
/// <summary>
/// Invoked when the mouse enters the notification window.
/// </summary>
/// <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.
@ -40,9 +34,7 @@ public interface IActiveNotification : INotification
/// </remarks>
event Action<IActiveNotification> MouseEnter;
/// <summary>
/// Invoked when the mouse leaves the notification window.
/// </summary>
/// <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.
@ -50,9 +42,7 @@ public interface IActiveNotification : INotification
/// </remarks>
event Action<IActiveNotification> MouseLeave;
/// <summary>
/// Invoked upon drawing the action bar of the notification.
/// </summary>
/// <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.
@ -60,50 +50,60 @@ public interface IActiveNotification : INotification
/// </remarks>
event Action<IActiveNotification> DrawActions;
/// <summary>
/// Gets the ID of this notification.
/// </summary>
/// <inheritdoc cref="INotification.Content"/>
new string Content { get; set; }
/// <inheritdoc cref="INotification.Title"/>
new string? Title { get; set; }
/// <inheritdoc cref="INotification.Type"/>
new NotificationType Type { get; set; }
/// <inheritdoc cref="INotification.IconCreator"/>
new Func<Task<object>>? IconCreator { get; set; }
/// <inheritdoc cref="INotification.Expiry"/>
new DateTime Expiry { get; set; }
/// <inheritdoc cref="INotification.Interactible"/>
new bool Interactible { get; set; }
/// <inheritdoc cref="INotification.HoverExtendDuration"/>
new TimeSpan HoverExtendDuration { get; set; }
/// <inheritdoc cref="INotification.Progress"/>
new float Progress { get; set; }
/// <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>
/// <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>
/// <summary>Gets a value indicating whether the notification has been dismissed.</summary>
/// <remarks>This includes when the hide animation is being played.</remarks>
bool IsDismissed { get; }
/// <summary>
/// Clones this notification as a <see cref="Notification"/>.
/// </summary>
/// <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>
/// <summary>Dismisses this notification.</summary>
void DismissNow();
/// <summary>
/// Updates the notification data.
/// </summary>
/// <summary>Updates the notification data.</summary>
/// <remarks>
/// Call <see cref="UpdateIcon"/> to update the icon using the new <see cref="INotification.IconCreator"/>.
/// If <see cref="IsDismissed"/> is <c>true</c>, then this function is a no-op.
/// </remarks>
/// <param name="newNotification">The new notification entry.</param>
void Update(INotification newNotification);
/// <summary>
/// Loads the icon again using <see cref="INotification.IconCreator"/>.
/// </summary>
/// <summary>Loads the icon again using <see cref="INotification.IconCreator"/>.</summary>
/// <remarks>If <see cref="IsDismissed"/> is <c>true</c>, then this function is a no-op.</remarks>
void UpdateIcon();
/// <summary>
/// Generates a new value to use for <see cref="Id"/>.
/// </summary>
/// <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);
}

View file

@ -6,31 +6,21 @@ using Dalamud.Interface.Internal.Notifications;
namespace Dalamud.Interface.ImGuiNotification;
/// <summary>
/// Represents a notification.
/// </summary>
/// <summary>Represents a notification.</summary>
public interface INotification
{
/// <summary>
/// Gets the content body of the notification.
/// </summary>
/// <summary>Gets the content body of the notification.</summary>
string Content { get; }
/// <summary>
/// Gets the title of the notification.
/// </summary>
/// <summary>Gets the title of the notification.</summary>
string? Title { get; }
/// <summary>
/// Gets the type of the notification.
/// </summary>
/// <summary>Gets the type of the notification.</summary>
NotificationType Type { get; }
/// <summary>
/// Gets the icon creator function for the notification.<br />
/// <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>
/// 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 />
@ -41,35 +31,30 @@ public interface INotification
/// </remarks>
Func<Task<object>>? IconCreator { get; }
/// <summary>
/// Gets the expiry.
/// </summary>
/// <summary>Gets the expiry.</summary>
/// <remarks>Set to <see cref="DateTime.MaxValue"/> to make the notification not have an expiry time
/// (sticky, indeterminate, permanent, or persistent).</remarks>
DateTime Expiry { get; }
/// <summary>
/// Gets a value indicating whether this notification may be interacted.
/// </summary>
/// <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.
/// If set to <c>true</c>, then clicking on the notification itself will be interpreted as user-initiated dismissal,
/// unless <see cref="IActiveNotification.Click"/> is set.
/// </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>
/// <summary>Gets the new duration for this notification if mouse cursor is on the notification window.</summary>
/// <remarks>
/// If set to <see cref="TimeSpan.Zero"/> or less, then this feature is turned off.
/// This property is applicable regardless of <see cref="Interactible"/>.
/// </remarks>
TimeSpan HoverExtendDuration { get; }
/// <summary>Gets the progress for the progress bar of the notification.
/// The progress should either be in the range between 0 and 1 or be a negative value.
/// Specifying a negative value will show an indeterminate progress bar.</summary>
float Progress { get; }
}

View file

@ -28,8 +28,8 @@ public sealed record Notification : INotification
public bool Interactible { get; set; }
/// <inheritdoc/>
public bool ClickIsDismiss { get; set; } = true;
public TimeSpan HoverExtendDuration { get; set; } = NotificationConstants.DefaultHoverExtendDuration;
/// <inheritdoc/>
public TimeSpan HoverExtendDuration { get; set; } = NotificationConstants.DefaultHoverExtendDuration;
public float Progress { get; set; } = 1f;
}