diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 83b94147be..1d68745202 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -25,6 +25,7 @@ using Dalamud.Interface.Internal.Windows.StyleEditor; using Dalamud.Interface.ManagedFontAtlas.Internals; using Dalamud.Interface.Style; +using Dalamud.Interface.Textures; using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; @@ -166,16 +167,16 @@ private DalamudInterface( { titleScreenMenu.AddEntryCore( Loc.Localize("TSMDalamudPlugins", "Plugin Installer"), - new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)), + new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)), this.OpenPluginInstaller); titleScreenMenu.AddEntryCore( Loc.Localize("TSMDalamudSettings", "Dalamud Settings"), - new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)), + new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)), this.OpenSettings); titleScreenMenu.AddEntryCore( "Toggle Dev Menu", - new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)), + new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)), () => Service.GetNullable()?.ToggleDevMenu(), VirtualKey.SHIFT); @@ -183,7 +184,7 @@ private DalamudInterface( { titleScreenMenu.AddEntryCore( Loc.Localize("TSMDalamudDevMenu", "Developer Menu"), - new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)), + new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)), () => this.isImGuiDrawDevMenu = true); } }); diff --git a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs index 5b851e02b8..b5ad77fb64 100644 --- a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs +++ b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs @@ -22,6 +22,8 @@ namespace Dalamud.Interface.Internal.Windows; +using Serilog; + /// /// Class responsible for drawing the main plugin window. /// @@ -166,6 +168,23 @@ public override void Draw() if (!entry.IsShowConditionSatisfied()) 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)) { moveEasing = new InOutQuint(TimeSpan.FromMilliseconds(400)); @@ -240,6 +259,23 @@ public override void Draw() if (!entry.IsShowConditionSatisfied()) 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; this.DrawEntry(entry, i != 0, true, i == 0, false, false); @@ -355,7 +391,7 @@ private bool DrawEntry( ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 1f); } - // Wrap should always be valid at this point due to us trying to get the wrap in IsShowConditionSatisfied + // 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) diff --git a/Dalamud/Storage/Assets/DalamudAssetTexture.cs b/Dalamud/Interface/Textures/ForwardingSharedImmediateTexture.cs similarity index 67% rename from Dalamud/Storage/Assets/DalamudAssetTexture.cs rename to Dalamud/Interface/Textures/ForwardingSharedImmediateTexture.cs index d553538f8e..bb4c9c2b53 100644 --- a/Dalamud/Storage/Assets/DalamudAssetTexture.cs +++ b/Dalamud/Interface/Textures/ForwardingSharedImmediateTexture.cs @@ -1,23 +1,23 @@ using System.Threading; using System.Threading.Tasks; -using Dalamud.Interface.Textures; using Dalamud.Interface.Textures.TextureWraps; +using Dalamud.Storage.Assets; -namespace Dalamud.Storage.Assets; +namespace Dalamud.Interface.Textures; /// -/// Wraps a dalamud asset texture allowing interoperability with certain services. +/// 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. /// -internal class DalamudAssetTexture : ISharedImmediateTexture +public class ForwardingSharedImmediateTexture : ISharedImmediateTexture { private readonly IDalamudTextureWrap textureWrap; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// A textureWrap loaded by . - internal DalamudAssetTexture(IDalamudTextureWrap textureWrap) + public ForwardingSharedImmediateTexture(IDalamudTextureWrap textureWrap) { this.textureWrap = textureWrap; } diff --git a/Dalamud/Interface/TitleScreenMenu/TitleScreenMenuEntry.cs b/Dalamud/Interface/TitleScreenMenu/TitleScreenMenuEntry.cs index e619ea7c71..1d66680049 100644 --- a/Dalamud/Interface/TitleScreenMenu/TitleScreenMenuEntry.cs +++ b/Dalamud/Interface/TitleScreenMenu/TitleScreenMenuEntry.cs @@ -153,8 +153,7 @@ public int CompareTo(TitleScreenMenuEntry? other) /// /// True if met. public bool IsShowConditionSatisfied() => - this.ShowConditionKeys.All(x => Service.GetNullable()?[x] is true) - && this.Texture.TryGetWrap(out var textureWrap, out _) && textureWrap.Width == 64 && textureWrap.Height == 64; + this.ShowConditionKeys.All(x => Service.GetNullable()?[x] is true); /// /// Trigger the action associated with this entry.