Merge remote-tracking branch 'origin/master' into net9-rollup

This commit is contained in:
github-actions[bot] 2025-03-26 19:36:37 +00:00
commit 3e629393b6
13 changed files with 176 additions and 274 deletions

View file

@ -1,9 +1,6 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Dalamud.Interface.ImGuiNotification.EventArgs; using Dalamud.Interface.ImGuiNotification.EventArgs;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures.TextureWraps;
namespace Dalamud.Interface.ImGuiNotification; namespace Dalamud.Interface.ImGuiNotification;
@ -52,64 +49,6 @@ public interface IActiveNotification : INotification
/// <remarks>This does not override <see cref="INotification.HardExpiry"/>.</remarks> /// <remarks>This does not override <see cref="INotification.HardExpiry"/>.</remarks>
void ExtendBy(TimeSpan extension); void ExtendBy(TimeSpan extension);
/// <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>
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>
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>
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>
void SetIconTexture(Task<IDalamudTextureWrap?>? textureWrapTask, bool leaveOpen);
/// <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> /// <returns>The new value.</returns>
internal static long CreateNewId() => Interlocked.Increment(ref idCounter); internal static long CreateNewId() => Interlocked.Increment(ref idCounter);

View file

@ -1,8 +1,4 @@
using System.Threading.Tasks; using Dalamud.Interface.Textures;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Plugin.Services;
namespace Dalamud.Interface.ImGuiNotification; namespace Dalamud.Interface.ImGuiNotification;
@ -22,35 +18,12 @@ public interface INotification
/// <summary>Gets or sets the type of the notification.</summary> /// <summary>Gets or sets the type of the notification.</summary>
NotificationType Type { get; set; } NotificationType Type { get; set; }
/// <summary>Gets or sets the icon source, in case <see cref="IconTextureTask"/> is not set or the task has faulted. /// <summary>Gets or sets the icon source, in case <see cref="IconTexture"/> is not set.
/// </summary> /// </summary>
INotificationIcon? Icon { get; set; } INotificationIcon? Icon { get; set; }
/// <summary>Gets or sets a texture wrap that will be used in place of <see cref="Icon"/> if set.</summary> /// <summary>Gets or sets a texture that will be used in place of <see cref="Icon"/> if set.</summary>
/// <remarks> public ISharedImmediateTexture? IconTexture { get; set; }
/// <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>
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>
Task<IDalamudTextureWrap?>? IconTextureTask { get; set; }
/// <summary>Gets or sets the hard expiry.</summary> /// <summary>Gets or sets the hard expiry.</summary>
/// <remarks> /// <remarks>

View file

@ -404,7 +404,7 @@ internal sealed partial class ActiveNotification
var maxCoord = minCoord + size; var maxCoord = minCoord + size;
var iconColor = this.Type.ToColor(); var iconColor = this.Type.ToColor();
if (NotificationUtilities.DrawIconFrom(minCoord, maxCoord, this.IconTextureTask)) if (NotificationUtilities.DrawIconFrom(minCoord, maxCoord, this.IconTexture))
return; return;
if (this.Icon?.DrawIcon(minCoord, maxCoord, iconColor) is true) if (this.Icon?.DrawIcon(minCoord, maxCoord, iconColor) is true)
@ -499,7 +499,7 @@ internal sealed partial class ActiveNotification
if (fillStartCw == 0 && fillEndCw == 0) if (fillStartCw == 0 && fillEndCw == 0)
return; return;
var radius = Math.Min(size.X, size.Y) / 3f; var radius = Math.Min(size.X, size.Y) / 3f;
var ifrom = fillStartCw * MathF.PI * 2; var ifrom = fillStartCw * MathF.PI * 2;
var ito = fillEndCw * MathF.PI * 2; var ito = fillEndCw * MathF.PI * 2;

View file

@ -1,11 +1,9 @@
using System.Runtime.Loader; using System.Runtime.Loader;
using System.Threading.Tasks;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Interface.Animation; using Dalamud.Interface.Animation;
using Dalamud.Interface.Animation.EasingFunctions; using Dalamud.Interface.Animation.EasingFunctions;
using Dalamud.Interface.Internal; using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Plugin.Internal.Types; using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility; using Dalamud.Utility;
@ -23,9 +21,6 @@ internal sealed partial class ActiveNotification : IActiveNotification
private readonly Easing progressEasing; private readonly Easing progressEasing;
private readonly Easing expandoEasing; private readonly Easing expandoEasing;
/// <summary>Whether to call <see cref="IDisposable.Dispose"/> on <see cref="DisposeInternal"/>.</summary>
private bool hasIconTextureOwnership;
/// <summary>Gets the time of starting to count the timer for the expiration.</summary> /// <summary>Gets the time of starting to count the timer for the expiration.</summary>
private DateTime lastInterestTime; private DateTime lastInterestTime;
@ -119,31 +114,10 @@ internal sealed partial class ActiveNotification : IActiveNotification
} }
/// <inheritdoc/> /// <inheritdoc/>
public IDalamudTextureWrap? IconTexture public ISharedImmediateTexture? IconTexture
{ {
get => this.underlyingNotification.IconTexture; get => this.underlyingNotification.IconTexture;
set => this.IconTextureTask = value is null ? null : Task.FromResult(value); set => this.underlyingNotification.IconTexture = value;
}
/// <inheritdoc/>
public Task<IDalamudTextureWrap?>? IconTextureTask
{
get => this.underlyingNotification.IconTextureTask;
set
{
// Do nothing if the value did not change.
if (this.underlyingNotification.IconTextureTask == value)
return;
if (this.hasIconTextureOwnership)
{
_ = this.underlyingNotification.IconTextureTask?.ToContentDisposedTask(true);
this.underlyingNotification.IconTextureTask = null;
this.hasIconTextureOwnership = false;
}
this.underlyingNotification.IconTextureTask = value;
}
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -265,39 +239,6 @@ internal sealed partial class ActiveNotification : IActiveNotification
this.extendedExpiry = newExpiry; this.extendedExpiry = newExpiry;
} }
/// <inheritdoc/>
public void SetIconTexture(IDalamudTextureWrap? textureWrap) =>
this.SetIconTexture(textureWrap, false);
/// <inheritdoc/>
public void SetIconTexture(IDalamudTextureWrap? textureWrap, bool leaveOpen) =>
this.SetIconTexture(textureWrap is null ? null : Task.FromResult(textureWrap), leaveOpen);
/// <inheritdoc/>
public void SetIconTexture(Task<IDalamudTextureWrap?>? textureWrapTask) =>
this.SetIconTexture(textureWrapTask, false);
/// <inheritdoc/>
public void SetIconTexture(Task<IDalamudTextureWrap?>? textureWrapTask, bool leaveOpen)
{
// If we're requested to replace the texture with the same texture, do nothing.
if (this.underlyingNotification.IconTextureTask == textureWrapTask)
return;
if (this.DismissReason is not null)
{
if (!leaveOpen)
textureWrapTask?.ToContentDisposedTask(true);
return;
}
if (this.hasIconTextureOwnership)
_ = this.underlyingNotification.IconTextureTask?.ToContentDisposedTask(true);
this.hasIconTextureOwnership = !leaveOpen;
this.underlyingNotification.IconTextureTask = textureWrapTask;
}
/// <summary>Removes non-Dalamud invocation targets from events.</summary> /// <summary>Removes non-Dalamud invocation targets from events.</summary>
/// <remarks> /// <remarks>
/// This is done to prevent references of plugins being unloaded from outliving the plugin itself. /// This is done to prevent references of plugins being unloaded from outliving the plugin itself.
@ -317,10 +258,8 @@ internal sealed partial class ActiveNotification : IActiveNotification
if (this.Icon is { } previousIcon && !IsOwnedByDalamud(previousIcon.GetType())) if (this.Icon is { } previousIcon && !IsOwnedByDalamud(previousIcon.GetType()))
this.Icon = null; this.Icon = null;
// Clear the texture if we don't have the ownership. if (this.IconTexture is { } previousTexture && !IsOwnedByDalamud(previousTexture.GetType()))
// The texture probably was owned by the plugin being unloaded in such case. this.IconTexture = null;
if (!this.hasIconTextureOwnership)
this.IconTextureTask = null;
this.isInitiatorUnloaded = true; this.isInitiatorUnloaded = true;
this.UserDismissable = true; this.UserDismissable = true;
@ -400,13 +339,6 @@ internal sealed partial class ActiveNotification : IActiveNotification
/// <summary>Clears the resources associated with this instance of <see cref="ActiveNotification"/>.</summary> /// <summary>Clears the resources associated with this instance of <see cref="ActiveNotification"/>.</summary>
internal void DisposeInternal() internal void DisposeInternal()
{ {
if (this.hasIconTextureOwnership)
{
_ = this.underlyingNotification.IconTextureTask?.ToContentDisposedTask(true);
this.underlyingNotification.IconTextureTask = null;
this.hasIconTextureOwnership = false;
}
this.Dismiss = null; this.Dismiss = null;
this.Click = null; this.Click = null;
this.DrawActions = null; this.DrawActions = null;

View file

@ -1,11 +1,11 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Dalamud.Interface.ImGuiNotification.Internal; using Dalamud.Interface.ImGuiNotification.Internal;
using Dalamud.Interface.Internal; using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps; using Dalamud.Interface.Textures.TextureWraps;
using Serilog;
namespace Dalamud.Interface.ImGuiNotification; namespace Dalamud.Interface.ImGuiNotification;
/// <summary>Represents a blueprint for a notification.</summary> /// <summary>Represents a blueprint for a notification.</summary>
public sealed record Notification : INotification public sealed record Notification : INotification
{ {
@ -30,14 +30,7 @@ public sealed record Notification : INotification
public INotificationIcon? Icon { get; set; } public INotificationIcon? Icon { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public IDalamudTextureWrap? IconTexture public ISharedImmediateTexture? IconTexture { get; set; }
{
get => this.IconTextureTask?.IsCompletedSuccessfully is true ? this.IconTextureTask.Result : null;
set => this.IconTextureTask = value is null ? null : Task.FromResult(value);
}
/// <inheritdoc/>
public Task<IDalamudTextureWrap?>? IconTextureTask { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public DateTime HardExpiry { get; set; } = DateTime.MaxValue; public DateTime HardExpiry { get; set; } = DateTime.MaxValue;

View file

@ -7,6 +7,7 @@ using Dalamud.Game.Text;
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.Interface.Internal.Windows; using Dalamud.Interface.Internal.Windows;
using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps; using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Plugin.Internal.Types; using Dalamud.Plugin.Internal.Types;
@ -78,6 +79,19 @@ public static class NotificationUtilities
return true; return true;
} }
/// <summary>Draws an icon from an instance of <see cref="ISharedImmediateTexture"/>.</summary>
/// <param name="minCoord">The coordinates of the top left of the icon area.</param>
/// <param name="maxCoord">The coordinates of the bottom right of the icon area.</param>
/// <param name="texture">The texture.</param>
/// <returns><c>true</c> if anything has been drawn.</returns>
internal static bool DrawIconFrom(Vector2 minCoord, Vector2 maxCoord, ISharedImmediateTexture? texture)
{
if (texture is null)
return false;
return DrawIconFrom(minCoord, maxCoord, texture.GetWrapOrEmpty());
}
/// <summary>Draws an icon from an instance of <see cref="IDalamudTextureWrap"/>.</summary> /// <summary>Draws an icon from an instance of <see cref="IDalamudTextureWrap"/>.</summary>
/// <param name="minCoord">The coordinates of the top left of the icon area.</param> /// <param name="minCoord">The coordinates of the top left of the icon area.</param>
/// <param name="maxCoord">The coordinates of the bottom right of the icon area.</param> /// <param name="maxCoord">The coordinates of the bottom right of the icon area.</param>
@ -105,16 +119,6 @@ public static class NotificationUtilities
} }
} }
/// <summary>Draws an icon from an instance of <see cref="Task{TResult}"/> that results in an
/// <see cref="IDalamudTextureWrap"/>.</summary>
/// <param name="minCoord">The coordinates of the top left of the icon area.</param>
/// <param name="maxCoord">The coordinates of the bottom right of the icon area.</param>
/// <param name="textureTask">The task that results in a texture.</param>
/// <returns><c>true</c> if anything has been drawn.</returns>
/// <remarks>Exceptions from the task will be treated as if no texture is provided.</remarks>
internal static bool DrawIconFrom(Vector2 minCoord, Vector2 maxCoord, Task<IDalamudTextureWrap?>? textureTask) =>
textureTask?.IsCompletedSuccessfully is true && DrawIconFrom(minCoord, maxCoord, textureTask.Result);
/// <summary>Draws an icon from an instance of <see cref="LocalPlugin"/>.</summary> /// <summary>Draws an icon from an instance of <see cref="LocalPlugin"/>.</summary>
/// <param name="minCoord">The coordinates of the top left of the icon area.</param> /// <param name="minCoord">The coordinates of the top left of the icon area.</param>
/// <param name="maxCoord">The coordinates of the bottom right of the icon area.</param> /// <param name="maxCoord">The coordinates of the bottom right of the icon area.</param>

View file

@ -26,6 +26,7 @@ using Dalamud.Interface.Internal.Windows.Settings;
using Dalamud.Interface.Internal.Windows.StyleEditor; using Dalamud.Interface.Internal.Windows.StyleEditor;
using Dalamud.Interface.ManagedFontAtlas.Internals; using Dalamud.Interface.ManagedFontAtlas.Internals;
using Dalamud.Interface.Style; using Dalamud.Interface.Style;
using Dalamud.Interface.Textures;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
@ -169,16 +170,16 @@ internal class DalamudInterface : IInternalDisposableService
{ {
titleScreenMenu.AddEntryCore( titleScreenMenu.AddEntryCore(
Loc.Localize("TSMDalamudPlugins", "Plugin Installer"), Loc.Localize("TSMDalamudPlugins", "Plugin Installer"),
dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall), new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
this.OpenPluginInstaller); this.OpenPluginInstaller);
titleScreenMenu.AddEntryCore( titleScreenMenu.AddEntryCore(
Loc.Localize("TSMDalamudSettings", "Dalamud Settings"), Loc.Localize("TSMDalamudSettings", "Dalamud Settings"),
dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall), new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
this.OpenSettings); this.OpenSettings);
titleScreenMenu.AddEntryCore( titleScreenMenu.AddEntryCore(
"Toggle Dev Menu", "Toggle Dev Menu",
dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall), new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
() => Service<DalamudInterface>.GetNullable()?.ToggleDevMenu(), () => Service<DalamudInterface>.GetNullable()?.ToggleDevMenu(),
VirtualKey.SHIFT); VirtualKey.SHIFT);
@ -186,7 +187,7 @@ internal class DalamudInterface : IInternalDisposableService
{ {
titleScreenMenu.AddEntryCore( titleScreenMenu.AddEntryCore(
Loc.Localize("TSMDalamudDevMenu", "Developer Menu"), Loc.Localize("TSMDalamudDevMenu", "Developer Menu"),
dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall), new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
() => this.isImGuiDrawDevMenu = true); () => this.isImGuiDrawDevMenu = true);
} }
}); });

View file

@ -5,11 +5,11 @@ using System.Threading.Tasks;
using Dalamud.Game.Text; using Dalamud.Game.Text;
using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.ImGuiNotification;
using Dalamud.Interface.ImGuiNotification.Internal; using Dalamud.Interface.ImGuiNotification.Internal;
using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.Internal; using Dalamud.Interface.Textures.Internal;
using Dalamud.Interface.Textures.TextureWraps; using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Storage.Assets; using Dalamud.Storage.Assets;
using Dalamud.Utility;
using ImGuiNET; using ImGuiNET;
@ -144,8 +144,6 @@ internal class ImGuiWidget : IDataWindowWidget
"Action Bar (always on if not user dismissable for the example)", "Action Bar (always on if not user dismissable for the example)",
ref this.notificationTemplate.ActionBar); ref this.notificationTemplate.ActionBar);
ImGui.Checkbox("Leave Textures Open", ref this.notificationTemplate.LeaveTexturesOpen);
if (ImGui.Button("Add notification")) if (ImGui.Button("Add notification"))
{ {
var text = var text =
@ -212,35 +210,34 @@ internal class ImGuiWidget : IDataWindowWidget
switch (this.notificationTemplate.IconInt) switch (this.notificationTemplate.IconInt)
{ {
case 5: case 5:
n.SetIconTexture( var textureWrap = DisposeLoggingTextureWrap.Wrap(
DisposeLoggingTextureWrap.Wrap( dam.GetDalamudTextureWrap(
dam.GetDalamudTextureWrap( Enum.Parse<DalamudAsset>(
Enum.Parse<DalamudAsset>( NotificationTemplate.AssetSources[this.notificationTemplate.IconAssetInt])));
NotificationTemplate.AssetSources[this.notificationTemplate.IconAssetInt]))),
this.notificationTemplate.LeaveTexturesOpen); if (textureWrap != null)
break; {
case 6: n.IconTexture = new ForwardingSharedImmediateTexture(textureWrap);
n.SetIconTexture( }
dam.GetDalamudTextureWrapAsync(
Enum.Parse<DalamudAsset>(
NotificationTemplate.AssetSources[this.notificationTemplate.IconAssetInt]))
.ContinueWith(
r => r.IsCompletedSuccessfully
? Task.FromResult<IDalamudTextureWrap>(DisposeLoggingTextureWrap.Wrap(r.Result))
: r).Unwrap(),
this.notificationTemplate.LeaveTexturesOpen);
break; break;
case 7: case 7:
n.SetIconTexture( var textureWrap2 = DisposeLoggingTextureWrap.Wrap(
DisposeLoggingTextureWrap.Wrap( tm.Shared.GetFromGame(this.notificationTemplate.IconText).GetWrapOrDefault());
tm.Shared.GetFromGame(this.notificationTemplate.IconText).GetWrapOrDefault()), if (textureWrap2 != null)
this.notificationTemplate.LeaveTexturesOpen); {
n.IconTexture = new ForwardingSharedImmediateTexture(textureWrap2);
}
break; break;
case 8: case 8:
n.SetIconTexture( var textureWrap3 = DisposeLoggingTextureWrap.Wrap(
DisposeLoggingTextureWrap.Wrap( tm.Shared.GetFromFile(this.notificationTemplate.IconText).GetWrapOrDefault());
tm.Shared.GetFromFile(this.notificationTemplate.IconText).GetWrapOrDefault()), if (textureWrap3 != null)
this.notificationTemplate.LeaveTexturesOpen); {
n.IconTexture = new ForwardingSharedImmediateTexture(textureWrap3);
}
break; break;
} }
@ -303,15 +300,15 @@ internal class ImGuiWidget : IDataWindowWidget
}; };
} }
} }
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button("Replace images using setter")) if (ImGui.Button("Replace images using setter"))
{ {
foreach (var n in this.notifications) foreach (var n in this.notifications)
{ {
var i = (uint)Random.Shared.NextInt64(0, 200000); var i = (uint)Random.Shared.NextInt64(0, 200000);
n.IconTexture = DisposeLoggingTextureWrap.Wrap(
Service<TextureManager>.Get().Shared.GetFromGameIcon(new(i)).GetWrapOrDefault()); n.IconTexture = Service<TextureManager>.Get().Shared.GetFromGameIcon(new(i, false, false));
} }
} }
} }
@ -428,7 +425,6 @@ internal class ImGuiWidget : IDataWindowWidget
public bool Minimized; public bool Minimized;
public bool UserDismissable; public bool UserDismissable;
public bool ActionBar; public bool ActionBar;
public bool LeaveTexturesOpen;
public int ProgressMode; public int ProgressMode;
public void Reset() public void Reset()
@ -450,7 +446,6 @@ internal class ImGuiWidget : IDataWindowWidget
this.Minimized = true; this.Minimized = true;
this.UserDismissable = true; this.UserDismissable = true;
this.ActionBar = true; this.ActionBar = true;
this.LeaveTexturesOpen = true;
this.ProgressMode = 0; this.ProgressMode = 0;
this.RespectUiHidden = true; this.RespectUiHidden = true;
} }

View file

@ -28,6 +28,8 @@ using ImGuiNET;
using Lumina.Text.ReadOnly; using Lumina.Text.ReadOnly;
using Serilog;
using LSeStringBuilder = Lumina.Text.SeStringBuilder; using LSeStringBuilder = Lumina.Text.SeStringBuilder;
namespace Dalamud.Interface.Internal.Windows; namespace Dalamud.Interface.Internal.Windows;
@ -185,6 +187,23 @@ internal class TitleScreenMenuWindow : Window, IDisposable
if (!entry.IsShowConditionSatisfied()) if (!entry.IsShowConditionSatisfied())
continue; continue;
if (entry.Texture.TryGetWrap(out var textureWrap, out var exception))
{
if (textureWrap.Width != 64 && textureWrap.Height != 64)
{
Log.Error("Texture provided for ITitleScreenMenuEntry must be 64x64. Entry will be removed.");
this.titleScreenMenu.RemoveEntry(entry);
continue;
}
}
if (exception != null)
{
Log.Error(exception, "An exception occurred while attempting to get the texture wrap for a ITitleScreenMenuEntry. Entry will be removed.");
this.titleScreenMenu.RemoveEntry(entry);
continue;
}
if (!this.moveEasings.TryGetValue(entry.Id, out var moveEasing)) if (!this.moveEasings.TryGetValue(entry.Id, out var moveEasing))
{ {
moveEasing = new InOutQuint(TimeSpan.FromMilliseconds(400)); moveEasing = new InOutQuint(TimeSpan.FromMilliseconds(400));
@ -259,6 +278,23 @@ internal class TitleScreenMenuWindow : Window, IDisposable
if (!entry.IsShowConditionSatisfied()) if (!entry.IsShowConditionSatisfied())
continue; continue;
if (entry.Texture.TryGetWrap(out var textureWrap, out var exception))
{
if (textureWrap.Width != 64 && textureWrap.Height != 64)
{
Log.Error($"Texture provided for ITitleScreenMenuEntry {entry.Name} must be 64x64. Entry will be removed.");
this.titleScreenMenu.RemoveEntry(entry);
continue;
}
}
if (exception != null)
{
Log.Error(exception, $"An exception occurred while attempting to get the texture wrap for ITitleScreenMenuEntry {entry.Name}. Entry will be removed.");
this.titleScreenMenu.RemoveEntry(entry);
continue;
}
var finalPos = (i + 1) * this.shadeTexture.Value.Height * scale; var finalPos = (i + 1) * this.shadeTexture.Value.Height * scale;
this.DrawEntry(entry, i != 0, true, i == 0, false, false); this.DrawEntry(entry, i != 0, true, i == 0, false, false);
@ -374,7 +410,9 @@ internal class TitleScreenMenuWindow : Window, IDisposable
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 1f); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 1f);
} }
ImGui.Image(entry.Texture.ImGuiHandle, new Vector2(TitleScreenMenu.TextureSize * scale)); // Wrap should always be valid at this point due to us checking the validity of the image each frame
var dalamudTextureWrap = entry.Texture.GetWrapOrEmpty();
ImGui.Image(dalamudTextureWrap.ImGuiHandle, new Vector2(TitleScreenMenu.TextureSize * scale));
if (overrideAlpha || isFirst) if (overrideAlpha || isFirst)
{ {
ImGui.PopStyleVar(); ImGui.PopStyleVar();
@ -388,7 +426,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
var textHeight = ImGui.GetTextLineHeightWithSpacing(); var textHeight = ImGui.GetTextLineHeightWithSpacing();
var cursor = ImGui.GetCursorPos(); var cursor = ImGui.GetCursorPos();
cursor.Y += (entry.Texture.Height * scale / 2) - (textHeight / 2); cursor.Y += (dalamudTextureWrap.Height * scale / 2) - (textHeight / 2);
if (overrideAlpha) if (overrideAlpha)
{ {
@ -411,7 +449,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
ImGui.PopStyleVar(); ImGui.PopStyleVar();
} }
initialCursor.Y += entry.Texture.Height * scale; initialCursor.Y += dalamudTextureWrap.Height * scale;
ImGui.SetCursorPos(initialCursor); ImGui.SetCursorPos(initialCursor);
return isHover; return isHover;

View file

@ -0,0 +1,50 @@
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Storage.Assets;
namespace Dalamud.Interface.Textures;
/// <summary>
/// Wraps a dalamud texture allowing interoperability with certain services. Only use this if you need to provide a texture that has been created or rented as a ISharedImmediateTexture.
/// </summary>
public class ForwardingSharedImmediateTexture : ISharedImmediateTexture
{
private readonly IDalamudTextureWrap textureWrap;
/// <summary>
/// Initializes a new instance of the <see cref="ForwardingSharedImmediateTexture"/> class.
/// </summary>
/// <param name="textureWrap">A textureWrap that has been created or provided by RentAsync.</param>
public ForwardingSharedImmediateTexture(IDalamudTextureWrap textureWrap)
{
this.textureWrap = textureWrap;
}
/// <inheritdoc/>
public IDalamudTextureWrap GetWrapOrEmpty()
{
return this.textureWrap;
}
/// <inheritdoc/>
public IDalamudTextureWrap? GetWrapOrDefault(IDalamudTextureWrap? defaultWrap = null)
{
return this.textureWrap;
}
/// <inheritdoc/>
public bool TryGetWrap(out IDalamudTextureWrap? texture, out Exception? exception)
{
texture = this.textureWrap;
exception = null;
return true;
}
/// <inheritdoc/>
public Task<IDalamudTextureWrap> RentAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(this.textureWrap);
}
}

View file

@ -3,8 +3,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Dalamud.Game.ClientState.Keys; using Dalamud.Game.ClientState.Keys;
using Dalamud.Interface.Internal; using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.IoC.Internal; using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
@ -67,7 +66,7 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
} }
} }
} }
/// <summary> /// <summary>
/// Adds a new entry to the title screen menu. /// Adds a new entry to the title screen menu.
/// </summary> /// </summary>
@ -76,13 +75,8 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
/// <param name="onTriggered">The action to execute when the option is selected.</param> /// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns> /// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception> /// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public ITitleScreenMenuEntry AddPluginEntry(string text, IDalamudTextureWrap texture, Action onTriggered) public ITitleScreenMenuEntry AddPluginEntry(string text, ISharedImmediateTexture texture, Action onTriggered)
{ {
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}
TitleScreenMenuEntry entry; TitleScreenMenuEntry entry;
lock (this.entries) lock (this.entries)
{ {
@ -103,13 +97,13 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
} }
/// <inheritdoc/> /// <inheritdoc/>
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, IDalamudTextureWrap texture, Action onTriggered) public IReadOnlyTitleScreenMenuEntry AddEntry(string text, ISharedImmediateTexture texture, Action onTriggered)
{ {
return this.AddPluginEntry(text, texture, onTriggered); return this.AddPluginEntry(text, texture, onTriggered);
} }
/// <inheritdoc/> /// <inheritdoc/>
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered) public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered)
{ {
return this.AddPluginEntry(priority, text, texture, onTriggered); return this.AddPluginEntry(priority, text, texture, onTriggered);
} }
@ -123,13 +117,8 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
/// <param name="onTriggered">The action to execute when the option is selected.</param> /// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns> /// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception> /// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public ITitleScreenMenuEntry AddPluginEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered) public ITitleScreenMenuEntry AddPluginEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered)
{ {
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}
TitleScreenMenuEntry entry; TitleScreenMenuEntry entry;
lock (this.entries) lock (this.entries)
{ {
@ -166,13 +155,8 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
/// <param name="onTriggered">The action to execute when the option is selected.</param> /// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns> /// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception> /// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
internal TitleScreenMenuEntry AddEntryCore(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered) internal TitleScreenMenuEntry AddEntryCore(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered)
{ {
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}
TitleScreenMenuEntry entry; TitleScreenMenuEntry entry;
lock (this.entries) lock (this.entries)
{ {
@ -199,15 +183,10 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception> /// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
internal TitleScreenMenuEntry AddEntryCore( internal TitleScreenMenuEntry AddEntryCore(
string text, string text,
IDalamudTextureWrap texture, ISharedImmediateTexture texture,
Action onTriggered, Action onTriggered,
params VirtualKey[] showConditionKeys) params VirtualKey[] showConditionKeys)
{ {
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}
TitleScreenMenuEntry entry; TitleScreenMenuEntry entry;
lock (this.entries) lock (this.entries)
{ {
@ -240,7 +219,7 @@ internal class TitleScreenMenuPluginScoped : IInternalDisposableService, ITitleS
{ {
[ServiceManager.ServiceDependency] [ServiceManager.ServiceDependency]
private readonly TitleScreenMenu titleScreenMenuService = Service<TitleScreenMenu>.Get(); private readonly TitleScreenMenu titleScreenMenuService = Service<TitleScreenMenu>.Get();
private readonly List<IReadOnlyTitleScreenMenuEntry> pluginEntries = new(); private readonly List<IReadOnlyTitleScreenMenuEntry> pluginEntries = new();
/// <inheritdoc/> /// <inheritdoc/>
@ -254,25 +233,25 @@ internal class TitleScreenMenuPluginScoped : IInternalDisposableService, ITitleS
this.titleScreenMenuService.RemoveEntry(entry); this.titleScreenMenuService.RemoveEntry(entry);
} }
} }
/// <inheritdoc/> /// <inheritdoc/>
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, IDalamudTextureWrap texture, Action onTriggered) public IReadOnlyTitleScreenMenuEntry AddEntry(string text, ISharedImmediateTexture texture, Action onTriggered)
{ {
var entry = this.titleScreenMenuService.AddPluginEntry(text, texture, onTriggered); var entry = this.titleScreenMenuService.AddPluginEntry(text, texture, onTriggered);
this.pluginEntries.Add(entry); this.pluginEntries.Add(entry);
return entry; return entry;
} }
/// <inheritdoc/> /// <inheritdoc/>
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered) public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered)
{ {
var entry = this.titleScreenMenuService.AddPluginEntry(priority, text, texture, onTriggered); var entry = this.titleScreenMenuService.AddPluginEntry(priority, text, texture, onTriggered);
this.pluginEntries.Add(entry); this.pluginEntries.Add(entry);
return entry; return entry;
} }
/// <inheritdoc/> /// <inheritdoc/>
public void RemoveEntry(IReadOnlyTitleScreenMenuEntry entry) public void RemoveEntry(IReadOnlyTitleScreenMenuEntry entry)
{ {

View file

@ -4,8 +4,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Dalamud.Game.ClientState.Keys; using Dalamud.Game.ClientState.Keys;
using Dalamud.Interface.Internal; using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;
namespace Dalamud.Interface; namespace Dalamud.Interface;
@ -64,7 +63,7 @@ public interface IReadOnlyTitleScreenMenuEntry
/// <summary> /// <summary>
/// Gets the texture of this entry. /// Gets the texture of this entry.
/// </summary> /// </summary>
IDalamudTextureWrap Texture { get; } ISharedImmediateTexture Texture { get; }
} }
/// <summary> /// <summary>
@ -87,7 +86,7 @@ public class TitleScreenMenuEntry : ITitleScreenMenuEntry
Assembly? callingAssembly, Assembly? callingAssembly,
ulong priority, ulong priority,
string text, string text,
IDalamudTextureWrap texture, ISharedImmediateTexture texture,
Action onTriggered, Action onTriggered,
IEnumerable<VirtualKey>? showConditionKeys = null) IEnumerable<VirtualKey>? showConditionKeys = null)
{ {
@ -106,8 +105,8 @@ public class TitleScreenMenuEntry : ITitleScreenMenuEntry
public string Name { get; set; } public string Name { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public IDalamudTextureWrap Texture { get; set; } public ISharedImmediateTexture Texture { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public bool IsInternal { get; set; } public bool IsInternal { get; set; }

View file

@ -1,8 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Internal; using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;
namespace Dalamud.Plugin.Services; namespace Dalamud.Plugin.Services;
@ -20,22 +19,22 @@ public interface ITitleScreenMenu
/// Adds a new entry to the title screen menu. /// Adds a new entry to the title screen menu.
/// </summary> /// </summary>
/// <param name="text">The text to show.</param> /// <param name="text">The text to show.</param>
/// <param name="texture">The texture to show.</param> /// <param name="texture">The texture to show. The texture must be 64x64 or the entry will be removed and an error will be logged.</param>
/// <param name="onTriggered">The action to execute when the option is selected.</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> /// <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> /// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, IDalamudTextureWrap texture, Action onTriggered); public IReadOnlyTitleScreenMenuEntry AddEntry(string text, ISharedImmediateTexture texture, Action onTriggered);
/// <summary> /// <summary>
/// Adds a new entry to the title screen menu. /// Adds a new entry to the title screen menu.
/// </summary> /// </summary>
/// <param name="priority">Priority of the entry.</param> /// <param name="priority">Priority of the entry.</param>
/// <param name="text">The text to show.</param> /// <param name="text">The text to show.</param>
/// <param name="texture">The texture to show.</param> /// <param name="texture">The texture to show. The texture must be 64x64 or the entry will be removed and an error will be logged.</param>
/// <param name="onTriggered">The action to execute when the option is selected.</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> /// <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> /// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered); public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered);
/// <summary> /// <summary>
/// Remove an entry from the title screen menu. /// Remove an entry from the title screen menu.