Skip to content

Commit

Permalink
Notification: add ISIT support
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Jul 2, 2024
1 parent 917affa commit 7df9493
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
13 changes: 11 additions & 2 deletions Dalamud/Interface/ImGuiNotification/INotification.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;

using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Plugin.Services;

Expand All @@ -26,6 +26,13 @@ public interface INotification
/// </summary>
INotificationIcon? Icon { get; set; }

/// <summary>Gets or sets the shared immediate texture to use in place of <see cref="Icon"/> if available.</summary>
/// <remarks>
/// <para>Setting this will not clear <see cref="IconTexture"/> nor <see cref="IconTextureTask"/>.</para>
/// <para>If icon texture is set and valid, then this value is ignored.</para>
/// </remarks>
ISharedImmediateTexture? IconSharedImmediateTexture { 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.
Expand All @@ -37,8 +44,9 @@ public interface INotification
/// <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>
/// <para>Setting this property will not clear <see cref="IconSharedImmediateTexture"/>.</para>
/// </remarks>
public IDalamudTextureWrap? IconTexture { get; set; }
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>
Expand All @@ -49,6 +57,7 @@ public interface INotification
/// <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>
/// <para>Setting this property will not clear <see cref="IconSharedImmediateTexture"/>.</para>
/// </remarks>
Task<IDalamudTextureWrap?>? IconTextureTask { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ private void DrawIcon(Vector2 minCoord, Vector2 size)
if (this.Icon?.DrawIcon(minCoord, maxCoord, iconColor) is true)
return;

if (NotificationUtilities.DrawIconFrom(minCoord, maxCoord, this.IconSharedImmediateTexture?.GetWrapOrDefault()))
return;

if (NotificationUtilities.DrawIconFrom(
minCoord,
maxCoord,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Dalamud.Configuration.Internal;
using Dalamud.Interface.Animation;
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.Utility;
Expand Down Expand Up @@ -118,6 +118,13 @@ public INotificationIcon? Icon
set => this.underlyingNotification.Icon = value;
}

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

/// <inheritdoc/>
public IDalamudTextureWrap? IconTexture
{
Expand Down
5 changes: 4 additions & 1 deletion Dalamud/Interface/ImGuiNotification/Notification.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Threading.Tasks;

using Dalamud.Interface.ImGuiNotification.Internal;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;

namespace Dalamud.Interface.ImGuiNotification;
Expand Down Expand Up @@ -29,6 +29,9 @@ public sealed record Notification : INotification
/// <inheritdoc/>
public INotificationIcon? Icon { get; set; }

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

/// <inheritdoc/>
public IDalamudTextureWrap? IconTexture
{
Expand Down
12 changes: 10 additions & 2 deletions Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public void Draw()
NotificationTemplate.AssetSources,
NotificationTemplate.AssetSources.Length);
break;
case 3 or 7:
case 3 or 7 or 9:
ImGui.InputText(
"Game Path##iconText",
ref this.notificationTemplate.IconText,
255);
break;
case 4 or 8:
case 4 or 8 or 10:
ImGui.InputText(
"File Path##iconText",
ref this.notificationTemplate.IconText,
Expand Down Expand Up @@ -203,6 +203,12 @@ public void Draw()
4 => INotificationIcon.FromFile(this.notificationTemplate.IconText),
_ => null,
},
IconSharedImmediateTexture = this.notificationTemplate.IconInt switch
{
9 => Service<TextureManager>.Get().Shared.GetFromGame(this.notificationTemplate.IconText),
10 => Service<TextureManager>.Get().Shared.GetFromFile(this.notificationTemplate.IconText),
_ => null,
},
});

this.notifications.Add(n);
Expand Down Expand Up @@ -360,6 +366,8 @@ private struct NotificationTemplate
"TextureWrap from DalamudAssets(Async)",
"TextureWrap from GamePath",
"TextureWrap from FilePath",
"ISharedImmediateTexture from GamePath",
"ISharedImmediateTexture from FilePath",
};

public static readonly string[] AssetSources =
Expand Down

0 comments on commit 7df9493

Please sign in to comment.