Skip to content

Commit

Permalink
Make ForwardingSharedImmediateTexture public, remove invalid entries …
Browse files Browse the repository at this point in the history
…on draw and log error
  • Loading branch information
Critical-Impact committed Jul 2, 2024
1 parent 1d8be18 commit 52c71a4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
9 changes: 5 additions & 4 deletions Dalamud/Interface/Internal/DalamudInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,24 +167,24 @@ 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<DalamudInterface>.GetNullable()?.ToggleDevMenu(),
VirtualKey.SHIFT);
if (!configuration.DalamudBetaKind.IsNullOrEmpty())
{
titleScreenMenu.AddEntryCore(
Loc.Localize("TSMDalamudDevMenu", "Developer Menu"),
new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
new ForwardingSharedImmediateTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
() => this.isImGuiDrawDevMenu = true);
}
});
Expand Down
38 changes: 37 additions & 1 deletion Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

namespace Dalamud.Interface.Internal.Windows;

using Serilog;

/// <summary>
/// Class responsible for drawing the main plugin window.
/// </summary>
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// 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.
/// </summary>
internal class DalamudAssetTexture : ISharedImmediateTexture
public class ForwardingSharedImmediateTexture : ISharedImmediateTexture
{
private readonly IDalamudTextureWrap textureWrap;

/// <summary>
/// Initializes a new instance of the <see cref="DalamudAssetTexture"/> class.
/// Initializes a new instance of the <see cref="ForwardingSharedImmediateTexture"/> class.
/// </summary>
/// <param name="textureWrap">A textureWrap loaded by <see cref="DalamudAssetManager"/>.</param>
internal DalamudAssetTexture(IDalamudTextureWrap textureWrap)
public ForwardingSharedImmediateTexture(IDalamudTextureWrap textureWrap)
{
this.textureWrap = textureWrap;
}
Expand Down
3 changes: 1 addition & 2 deletions Dalamud/Interface/TitleScreenMenu/TitleScreenMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ public int CompareTo(TitleScreenMenuEntry? other)
/// </summary>
/// <returns>True if met.</returns>
public bool IsShowConditionSatisfied() =>
this.ShowConditionKeys.All(x => Service<KeyState>.GetNullable()?[x] is true)
&& this.Texture.TryGetWrap(out var textureWrap, out _) && textureWrap.Width == 64 && textureWrap.Height == 64;
this.ShowConditionKeys.All(x => Service<KeyState>.GetNullable()?[x] is true);

/// <summary>
/// Trigger the action associated with this entry.
Expand Down

0 comments on commit 52c71a4

Please sign in to comment.