mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +01:00
Show plugin icons as fallback icon
This commit is contained in:
parent
0343897113
commit
2935d18c37
2 changed files with 53 additions and 23 deletions
|
|
@ -7,9 +7,11 @@ using Dalamud.Interface.Animation;
|
||||||
using Dalamud.Interface.Animation.EasingFunctions;
|
using Dalamud.Interface.Animation.EasingFunctions;
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.ImGuiNotification;
|
using Dalamud.Interface.ImGuiNotification;
|
||||||
|
using Dalamud.Interface.Internal.Windows;
|
||||||
using Dalamud.Interface.ManagedFontAtlas;
|
using Dalamud.Interface.ManagedFontAtlas;
|
||||||
using Dalamud.Interface.Utility;
|
using Dalamud.Interface.Utility;
|
||||||
using Dalamud.Plugin.Internal.Types;
|
using Dalamud.Plugin.Internal.Types;
|
||||||
|
using Dalamud.Storage.Assets;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
|
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
|
@ -383,23 +385,14 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable
|
||||||
|
|
||||||
private void DrawIcon(NotificationManager notificationManager, Vector2 minCoord, Vector2 maxCoord)
|
private void DrawIcon(NotificationManager notificationManager, Vector2 minCoord, Vector2 maxCoord)
|
||||||
{
|
{
|
||||||
string? iconString;
|
string? iconString = null;
|
||||||
IFontHandle? fontHandle;
|
IFontHandle? fontHandle = null;
|
||||||
|
IDalamudTextureWrap? iconTexture = null;
|
||||||
switch (this.IconTask?.IsCompletedSuccessfully is true ? this.IconTask.Result : null)
|
switch (this.IconTask?.IsCompletedSuccessfully is true ? this.IconTask.Result : null)
|
||||||
{
|
{
|
||||||
case IDalamudTextureWrap wrap:
|
case IDalamudTextureWrap wrap:
|
||||||
{
|
iconTexture = wrap;
|
||||||
var size = wrap.Size;
|
break;
|
||||||
if (size.X > maxCoord.X - minCoord.X)
|
|
||||||
size *= (maxCoord.X - minCoord.X) / size.X;
|
|
||||||
if (size.Y > maxCoord.Y - minCoord.Y)
|
|
||||||
size *= (maxCoord.Y - minCoord.Y) / size.Y;
|
|
||||||
var pos = ((minCoord + maxCoord) - size) / 2;
|
|
||||||
ImGui.SetCursorPos(pos);
|
|
||||||
ImGui.Image(wrap.ImGuiHandle, size);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SeIconChar icon:
|
case SeIconChar icon:
|
||||||
iconString = string.Empty + (char)icon;
|
iconString = string.Empty + (char)icon;
|
||||||
fontHandle = notificationManager.IconAxisFontHandle;
|
fontHandle = notificationManager.IconAxisFontHandle;
|
||||||
|
|
@ -415,16 +408,52 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(iconString))
|
if (string.IsNullOrWhiteSpace(iconString))
|
||||||
return;
|
|
||||||
|
|
||||||
using (fontHandle.Push())
|
|
||||||
{
|
{
|
||||||
var size = ImGui.CalcTextSize(iconString);
|
var dam = Service<DalamudAssetManager>.Get();
|
||||||
|
if (this.InitiatorPlugin is null)
|
||||||
|
{
|
||||||
|
iconTexture = dam.GetDalamudTextureWrap(DalamudAsset.LogoSmall);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!Service<PluginImageCache>.Get().TryGetIcon(
|
||||||
|
this.InitiatorPlugin,
|
||||||
|
this.InitiatorPlugin.Manifest,
|
||||||
|
this.InitiatorPlugin.IsThirdParty,
|
||||||
|
out iconTexture) || iconTexture is null)
|
||||||
|
{
|
||||||
|
iconTexture = this.InitiatorPlugin switch
|
||||||
|
{
|
||||||
|
{ IsDev: true } => dam.GetDalamudTextureWrap(DalamudAsset.DevPluginIcon),
|
||||||
|
{ IsThirdParty: true } => dam.GetDalamudTextureWrap(DalamudAsset.ThirdInstalledIcon),
|
||||||
|
_ => dam.GetDalamudTextureWrap(DalamudAsset.InstalledIcon),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iconTexture is not null)
|
||||||
|
{
|
||||||
|
var size = iconTexture.Size;
|
||||||
|
if (size.X > maxCoord.X - minCoord.X)
|
||||||
|
size *= (maxCoord.X - minCoord.X) / size.X;
|
||||||
|
if (size.Y > maxCoord.Y - minCoord.Y)
|
||||||
|
size *= (maxCoord.Y - minCoord.Y) / size.Y;
|
||||||
var pos = ((minCoord + maxCoord) - size) / 2;
|
var pos = ((minCoord + maxCoord) - size) / 2;
|
||||||
ImGui.SetCursorPos(pos);
|
ImGui.SetCursorPos(pos);
|
||||||
ImGui.PushStyleColor(ImGuiCol.Text, this.DefaultIconColor);
|
ImGui.Image(iconTexture.ImGuiHandle, size);
|
||||||
ImGui.TextUnformatted(iconString);
|
}
|
||||||
ImGui.PopStyleColor();
|
else if (fontHandle is not null)
|
||||||
|
{
|
||||||
|
using (fontHandle.Push())
|
||||||
|
{
|
||||||
|
var size = ImGui.CalcTextSize(iconString);
|
||||||
|
var pos = ((minCoord + maxCoord) - size) / 2;
|
||||||
|
ImGui.SetCursorPos(pos);
|
||||||
|
ImGui.PushStyleColor(ImGuiCol.Text, this.DefaultIconColor);
|
||||||
|
ImGui.TextUnformatted(iconString);
|
||||||
|
ImGui.PopStyleColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ internal class ImGuiWidget : IDataWindowWidget
|
||||||
Type = type,
|
Type = type,
|
||||||
Interactible = true,
|
Interactible = true,
|
||||||
ClickIsDismiss = false,
|
ClickIsDismiss = false,
|
||||||
|
Expiry = DateTime.MaxValue,
|
||||||
});
|
});
|
||||||
|
|
||||||
var nclick = 0;
|
var nclick = 0;
|
||||||
|
|
@ -85,7 +86,7 @@ internal class ImGuiWidget : IDataWindowWidget
|
||||||
{
|
{
|
||||||
var rand = new Random();
|
var rand = new Random();
|
||||||
|
|
||||||
title = rand.Next(0, 5) switch
|
title = rand.Next(0, 7) switch
|
||||||
{
|
{
|
||||||
0 => "This is a toast",
|
0 => "This is a toast",
|
||||||
1 => "Truly, a toast",
|
1 => "Truly, a toast",
|
||||||
|
|
@ -96,7 +97,7 @@ internal class ImGuiWidget : IDataWindowWidget
|
||||||
_ => null,
|
_ => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
type = rand.Next(0, 4) switch
|
type = rand.Next(0, 5) switch
|
||||||
{
|
{
|
||||||
0 => NotificationType.Error,
|
0 => NotificationType.Error,
|
||||||
1 => NotificationType.Warning,
|
1 => NotificationType.Warning,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue