Skip to content

Commit

Permalink
Added Icon to Notification (Cursed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meisterlala committed Jun 29, 2024
1 parent fc3db1c commit 77b1754
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
20 changes: 19 additions & 1 deletion Neko/Drawing/Embedded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Logging;
using Dalamud.Interface.Textures.TextureWraps;
using Neko.Sources;

namespace Neko.Drawing;
Expand All @@ -13,6 +13,8 @@ public class Embedded : ImageSource
{
public static readonly Embedded ImageError = new("error.jpg");
public static readonly Embedded ImageLoading = new("loading.jpg");
public static readonly Embedded ImageIcon = new("icon.png");


public override string Name => "Embedded";
public override string ToString() => $"Embedded Image: {Filename}";
Expand All @@ -23,6 +25,7 @@ public class Embedded : ImageSource
private Download.Response? LoadedBytes;
private readonly object LoadingLock = new();


public Embedded(string filename) => Filename = filename;

public override NekoImage Next(CancellationToken ct = default)
Expand Down Expand Up @@ -101,6 +104,21 @@ public static void LoadAll()
});
}

/// <summary>
/// Gets a DalamudTextureWrap from the embedded icon.
/// </summary>
public async Task<IDalamudTextureWrap?> GetDalamudTextureWrap()
{
if (Image == null) throw new Exception("Embedded image was not loaded yet");

var assembly = Assembly.GetExecutingAssembly();
var resourceName = $"Neko.resources.{Filename}";
var shared = Plugin.TextureProvider.GetFromManifestResource(assembly, resourceName);


return await shared.RentAsync().ConfigureAwait(false);
}

public override bool SameAs(ImageSource other) => other is Embedded e && e.Filename == Filename;

public static implicit operator NekoImage(Embedded e)
Expand Down
11 changes: 8 additions & 3 deletions Neko/Gui/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Numerics;
using Dalamud.Interface.Components;
using ImGuiNET;
using Neko.Drawing;

namespace Neko.Gui;

Expand Down Expand Up @@ -86,18 +87,22 @@ public static bool IconButton(Dalamud.Interface.FontAwesomeIcon icon, string ID
return ret;
}


/// <summary>
/// Shows a Notification to the user
/// </summary>
/// <param name="text"></param>
/// <param name="type"></param>
public static void Notification(string text, Dalamud.Interface.ImGuiNotification.NotificationType type = default) {
// TODO: Add image to notification
public static void Notification(string text, Dalamud.Interface.ImGuiNotification.NotificationType type = default)
{

var notification = new Dalamud.Interface.ImGuiNotification.Notification(){
var notification = new Dalamud.Interface.ImGuiNotification.Notification()
{
Content = text,
Type = type,
IconTextureTask = Embedded.ImageIcon.GetDalamudTextureWrap(),
};

Plugin.NotificationManager.AddNotification(notification);
}

Expand Down
1 change: 1 addition & 0 deletions Neko/Neko.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<ItemGroup>
<EmbeddedResource Include="resources/error.jpg" />
<EmbeddedResource Include="resources/loading.jpg" />
<EmbeddedResource Include="resources/icon.png" />
</ItemGroup>

<!-- Used to manipulate Clipboard -->
Expand Down
2 changes: 2 additions & 0 deletions Neko/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Plugin : IDalamudPlugin
[PluginService] public static IKeyState KeyState { get; private set; } = null!;
[PluginService] public static IPluginLog Log { get; private set; } = null!;
[PluginService] public static INotificationManager NotificationManager { get; private set; } = null!;
[PluginService] public static ITextureProvider TextureProvider { get; private set; } = null!;



public static string Name => "Neko Fans";
Expand Down
Binary file added Neko/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 77b1754

Please sign in to comment.