Skip to content

Commit

Permalink
Restore missing interface methods/properties as wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Critical-Impact committed Jul 4, 2024
1 parent c7d91e0 commit 25565b4
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 9 deletions.
62 changes: 62 additions & 0 deletions Dalamud/Interface/ImGuiNotification/IActiveNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,68 @@ public interface IActiveNotification : INotification
/// </remarks>
void SetIconTexture(ISharedImmediateTexture? sharedImmediateTexture);

/// <summary>Sets the icon from <see cref="IDalamudTextureWrap"/>, overriding the icon.</summary>
/// <param name="textureWrap">The new texture wrap to use, or null to clear and revert back to the icon specified
/// from <see cref="INotification.Icon"/>.</param>
/// <remarks>
/// <para>The texture passed will be disposed when the notification is dismissed or a new different texture is set
/// via another call to this function or overwriting the property. You do not have to dispose it yourself.</para>
/// <para>If <see cref="DismissReason"/> is not <c>null</c>, then calling this function will simply dispose the
/// passed <paramref name="textureWrap"/> without actually updating the icon.</para>
/// </remarks>
[Obsolete("Will be removed in API11")]
void SetIconTexture(IDalamudTextureWrap? textureWrap);

/// <summary>Sets the icon from <see cref="IDalamudTextureWrap"/>, overriding the icon, once the given task
/// completes.</summary>
/// <param name="textureWrapTask">The task that will result in a new texture wrap to use, or null to clear and
/// revert back to the icon specified from <see cref="INotification.Icon"/>.</param>
/// <remarks>
/// <para>The texture resulted from the passed <see cref="Task{TResult}"/> will be disposed when the notification
/// is dismissed or a new different texture is set via another call to this function over overwriting the property.
/// You do not have to dispose the resulted instance of <see cref="IDalamudTextureWrap"/> yourself.</para>
/// <para>If the task fails for any reason, the exception will be silently ignored and the icon specified from
/// <see cref="INotification.Icon"/> will be used instead.</para>
/// <para>If <see cref="DismissReason"/> is not <c>null</c>, then calling this function will simply dispose the
/// result of the passed <paramref name="textureWrapTask"/> without actually updating the icon.</para>
/// </remarks>
[Obsolete("Will be removed in API11")]
void SetIconTexture(Task<IDalamudTextureWrap?>? textureWrapTask);

/// <summary>Sets the icon from <see cref="IDalamudTextureWrap"/>, overriding the icon.</summary>
/// <param name="textureWrap">The new texture wrap to use, or null to clear and revert back to the icon specified
/// from <see cref="INotification.Icon"/>.</param>
/// <param name="leaveOpen">Whether to keep the passed <paramref name="textureWrap"/> not disposed.</param>
/// <remarks>
/// <para>If <paramref name="leaveOpen"/> is <c>false</c>, the texture passed will be disposed when the
/// notification is dismissed or a new different texture is set via another call to this function. You do not have
/// to dispose it yourself.</para>
/// <para>If <see cref="DismissReason"/> is not <c>null</c> and <paramref name="leaveOpen"/> is <c>false</c>, then
/// calling this function will simply dispose the passed <paramref name="textureWrap"/> without actually updating
/// the icon.</para>
/// </remarks>
[Obsolete("Will be removed in API11")]
void SetIconTexture(IDalamudTextureWrap? textureWrap, bool leaveOpen);

/// <summary>Sets the icon from <see cref="IDalamudTextureWrap"/>, overriding the icon, once the given task
/// completes.</summary>
/// <param name="textureWrapTask">The task that will result in a new texture wrap to use, or null to clear and
/// revert back to the icon specified from <see cref="INotification.Icon"/>.</param>
/// <param name="leaveOpen">Whether to keep the result from the passed <paramref name="textureWrapTask"/> not
/// disposed.</param>
/// <remarks>
/// <para>If <paramref name="leaveOpen"/> is <c>false</c>, the texture resulted from the passed
/// <see cref="Task{TResult}"/> will be disposed when the notification is dismissed or a new different texture is
/// set via another call to this function. You do not have to dispose the resulted instance of
/// <see cref="IDalamudTextureWrap"/> yourself.</para>
/// <para>If the task fails for any reason, the exception will be silently ignored and the icon specified from
/// <see cref="INotification.Icon"/> will be used instead.</para>
/// <para>If <see cref="DismissReason"/> is not <c>null</c>, then calling this function will simply dispose the
/// result of the passed <paramref name="textureWrapTask"/> without actually updating the icon.</para>
/// </remarks>
[Obsolete("Will be removed in API11")]
void SetIconTexture(Task<IDalamudTextureWrap?>? textureWrapTask, bool leaveOpen);

/// <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);
Expand Down
30 changes: 29 additions & 1 deletion Dalamud/Interface/ImGuiNotification/INotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,35 @@ public interface INotification
/// the property will return <c>null</c>. Setting this property will set <see cref="IconTextureTask"/> to a new
/// completed <see cref="Task{TResult}"/> with the new value as its result.</para>
/// </remarks>
public ISharedImmediateTexture? IconTexture { get; set; }
public ISharedImmediateTexture? ImmediateIconTexture { get; set; }

/// <summary>Gets or sets a texture wrap that will be used in place of <see cref="Icon"/> if set.</summary>
/// <remarks>
/// <para>A texture wrap set via this property will <b>NOT</b> be disposed when the notification is dismissed.
/// Use <see cref="IActiveNotification.SetIconTexture(IDalamudTextureWrap?)"/> or
/// <see cref="IActiveNotification.SetIconTexture(Task{IDalamudTextureWrap?}?)"/> to use a texture, after calling
/// <see cref="INotificationManager.AddNotification"/>. Call either of those functions with <c>null</c> to revert
/// the effective icon back to this property.</para>
/// <para>This property and <see cref="IconTextureTask"/> are bound together. If the task is not <c>null</c> but
/// <see cref="Task.IsCompletedSuccessfully"/> is <c>false</c> (because the task is still in progress or faulted,)
/// the property will return <c>null</c>. Setting this property will set <see cref="IconTextureTask"/> to a new
/// completed <see cref="Task{TResult}"/> with the new value as its result.</para>
/// </remarks>
[Obsolete("Will be removed in API11")]
public IDalamudTextureWrap? IconTexture { get; set; }

/// <summary>Gets or sets a task that results in a texture wrap that will be used in place of <see cref="Icon"/> if
/// available.</summary>
/// <remarks>
/// <para>A texture wrap set via this property will <b>NOT</b> be disposed when the notification is dismissed.
/// Use <see cref="IActiveNotification.SetIconTexture(IDalamudTextureWrap?)"/> or
/// <see cref="IActiveNotification.SetIconTexture(Task{IDalamudTextureWrap?}?)"/> to use a texture, after calling
/// <see cref="INotificationManager.AddNotification"/>. Call either of those functions with <c>null</c> to revert
/// the effective icon back to this property.</para>
/// <para>This property and <see cref="IconTexture"/> are bound together.</para>
/// </remarks>
[Obsolete("Will be removed in API11")]
Task<IDalamudTextureWrap?>? IconTextureTask { get; set; }

/// <summary>Gets or sets the hard expiry.</summary>
/// <remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private void DrawIcon(Vector2 minCoord, Vector2 size)
var maxCoord = minCoord + size;
var iconColor = this.Type.ToColor();

if (NotificationUtilities.DrawIconFrom(minCoord, maxCoord, this.IconTexture))
if (NotificationUtilities.DrawIconFrom(minCoord, maxCoord, this.ImmediateIconTexture))
return;

if (this.Icon?.DrawIcon(minCoord, maxCoord, iconColor) is true)
Expand Down
54 changes: 50 additions & 4 deletions Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,26 @@ public INotificationIcon? Icon
}

/// <inheritdoc/>
public ISharedImmediateTexture? IconTexture
public ISharedImmediateTexture? ImmediateIconTexture
{
get => this.underlyingNotification.ImmediateIconTexture;
set => this.underlyingNotification.ImmediateIconTexture = value;
}

/// <inheritdoc/>
public IDalamudTextureWrap? IconTexture
{
get => this.underlyingNotification.IconTexture;
set => this.underlyingNotification.IconTexture = value;
}

/// <inheritdoc/>
public Task<IDalamudTextureWrap?>? IconTextureTask
{
get => this.underlyingNotification.IconTextureTask;
set => this.underlyingNotification.IconTextureTask = value;
}

/// <inheritdoc/>
public DateTime HardExpiry
{
Expand Down Expand Up @@ -246,7 +260,38 @@ public void ExtendBy(TimeSpan extension)
/// <inheritdoc/>
public void SetIconTexture(ISharedImmediateTexture? sharedImmediateTexture)
{
this.underlyingNotification.IconTexture = sharedImmediateTexture;
this.underlyingNotification.ImmediateIconTexture = sharedImmediateTexture;
}


/// <inheritdoc/>
[Obsolete("Will be removed in API11")]
public void SetIconTexture(IDalamudTextureWrap? textureWrap)
{
this.SetIconTexture(textureWrap != null ? new ForwardingSharedImmediateTexture(textureWrap) : null);
}

/// <inheritdoc/>
[Obsolete("Will be removed in API11")]
public void SetIconTexture(Task<IDalamudTextureWrap?>? textureWrapTask)
{
var result = textureWrapTask?.Result;
this.SetIconTexture(result != null ? new ForwardingSharedImmediateTexture(result) : null);
}

/// <inheritdoc/>
[Obsolete("Will be removed in API11")]
public void SetIconTexture(IDalamudTextureWrap? textureWrap, bool leaveOpen)
{
this.SetIconTexture(textureWrap != null ? new ForwardingSharedImmediateTexture(textureWrap) : null);
}

/// <inheritdoc/>
[Obsolete("Will be removed in API11")]
public void SetIconTexture(Task<IDalamudTextureWrap?>? textureWrapTask, bool leaveOpen)
{
var result = textureWrapTask?.Result;
this.SetIconTexture(result != null ? new ForwardingSharedImmediateTexture(result) : null);
}

/// <summary>Removes non-Dalamud invocation targets from events.</summary>
Expand All @@ -268,8 +313,9 @@ internal void RemoveNonDalamudInvocations()
if (this.Icon is { } previousIcon && !IsOwnedByDalamud(previousIcon.GetType()))
this.Icon = null;

if (this.IconTexture is { } iconTexture && iconTexture.TryGetWrap(out var wrap, out _) && !IsOwnedByDalamud(wrap.GetType()))
this.IconTexture = null;

if (this.ImmediateIconTexture is { } iconTexture && (!IsOwnedByDalamud(iconTexture.GetType()) || (iconTexture.TryGetWrap(out var wrap, out _) && !IsOwnedByDalamud(wrap.GetType()))))
this.ImmediateIconTexture = null;

this.isInitiatorUnloaded = true;
this.UserDismissable = true;
Expand Down
28 changes: 27 additions & 1 deletion Dalamud/Interface/ImGuiNotification/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,33 @@ public sealed record Notification : INotification
public INotificationIcon? Icon { get; set; }

/// <inheritdoc/>
public ISharedImmediateTexture? IconTexture { get; set; }
public ISharedImmediateTexture? ImmediateIconTexture { get; set; }

/// <inheritdoc/>
public IDalamudTextureWrap? IconTexture
{
get => this.ImmediateIconTexture?.GetWrapOrDefault();
set => this.ImmediateIconTexture = value != null ? new ForwardingSharedImmediateTexture(value) : null;
}

/// <inheritdoc/>
public Task<IDalamudTextureWrap?>? IconTextureTask
{
get => Task.FromResult(this.ImmediateIconTexture?.GetWrapOrDefault());

set
{
if (value == null)
{
this.ImmediateIconTexture = null;
}
else
{
var dalamudTextureWrap = value.Result;
this.ImmediateIconTexture = dalamudTextureWrap == null ? null : new ForwardingSharedImmediateTexture(dalamudTextureWrap);
}
}
}

/// <inheritdoc/>
public DateTime HardExpiry { get; set; } = DateTime.MaxValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void Draw()
{
var i = (uint)Random.Shared.NextInt64(0, 200000);

n.IconTexture = Service<TextureManager>.Get().Shared.GetFromGameIcon(new(i, false, false));
n.ImmediateIconTexture = Service<TextureManager>.Get().Shared.GetFromGameIcon(new(i, false, false));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ForwardingSharedImmediateTexture : ISharedImmediateTexture
/// <summary>
/// Initializes a new instance of the <see cref="ForwardingSharedImmediateTexture"/> class.
/// </summary>
/// <param name="textureWrap">A textureWrap loaded by <see cref="DalamudAssetManager"/>.</param>
/// <param name="textureWrap">A textureWrap that has been created or provided by RentAsync.</param>
public ForwardingSharedImmediateTexture(IDalamudTextureWrap textureWrap)
{
this.textureWrap = textureWrap;
Expand Down
29 changes: 29 additions & 0 deletions Dalamud/Plugin/Services/ITitleScreenMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ public interface ITitleScreenMenu
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered);

/// <summary>
/// Adds a new entry to the title screen menu.
/// </summary>
/// <param name="text">The text to show.</param>
/// <param name="texture">The texture to show. The texture must be 64x64 or the entry will not draw. Please use ISharedImmediateTexture or a ForwardingSharedImmediateTexture if possible.</param>
/// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="IReadOnlyTitleScreenMenuEntry"/> object that can be reference the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
[Obsolete("Will be removed in API11")]
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, IDalamudTextureWrap texture, Action onTriggered)
{
return this.AddEntry(text, new ForwardingSharedImmediateTexture(texture), onTriggered);
}

/// <summary>
/// Adds a new entry to the title screen menu.
/// </summary>
/// <param name="priority">Priority of the entry.</param>
/// <param name="text">The text to show.</param>
/// <param name="texture">The texture to show. The texture must be 64x64 or the entry will not draw. Please use ISharedImmediateTexture or a ForwardingSharedImmediateTexture if possible.</param>
/// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="IReadOnlyTitleScreenMenuEntry"/> object that can be used to reference the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
[Obsolete("Will be removed in API11")]
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered)
{
return this.AddEntry(priority, text, new ForwardingSharedImmediateTexture(texture), onTriggered);
}

/// <summary>
/// Remove an entry from the title screen menu.
/// </summary>
Expand Down

0 comments on commit 25565b4

Please sign in to comment.