Skip to content

Commit

Permalink
Update ITitleScreenMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Critical-Impact committed Jul 2, 2024
1 parent a042ec9 commit 1d8be18
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 43 deletions.
8 changes: 4 additions & 4 deletions Dalamud/Interface/Internal/DalamudInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,24 @@ private DalamudInterface(
{
titleScreenMenu.AddEntryCore(
Loc.Localize("TSMDalamudPlugins", "Plugin Installer"),
dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall),
new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
this.OpenPluginInstaller);
titleScreenMenu.AddEntryCore(
Loc.Localize("TSMDalamudSettings", "Dalamud Settings"),
dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall),
new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
this.OpenSettings);

titleScreenMenu.AddEntryCore(
"Toggle Dev Menu",
dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall),
new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
() => Service<DalamudInterface>.GetNullable()?.ToggleDevMenu(),
VirtualKey.SHIFT);

if (!configuration.DalamudBetaKind.IsNullOrEmpty())
{
titleScreenMenu.AddEntryCore(
Loc.Localize("TSMDalamudDevMenu", "Developer Menu"),
dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall),
new DalamudAssetTexture(dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall)),
() => this.isImGuiDrawDevMenu = true);
}
});
Expand Down
8 changes: 5 additions & 3 deletions Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ private bool DrawEntry(
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 1f);
}

ImGui.Image(entry.Texture.ImGuiHandle, new Vector2(TitleScreenMenu.TextureSize * scale));
// Wrap should always be valid at this point due to us trying to get the wrap in IsShowConditionSatisfied
var dalamudTextureWrap = entry.Texture.GetWrapOrEmpty();
ImGui.Image(dalamudTextureWrap.ImGuiHandle, new Vector2(TitleScreenMenu.TextureSize * scale));
if (overrideAlpha || isFirst)
{
ImGui.PopStyleVar();
Expand All @@ -369,7 +371,7 @@ private bool DrawEntry(
var textHeight = ImGui.GetTextLineHeightWithSpacing();
var cursor = ImGui.GetCursorPos();

cursor.Y += (entry.Texture.Height * scale / 2) - (textHeight / 2);
cursor.Y += (dalamudTextureWrap.Height * scale / 2) - (textHeight / 2);

if (overrideAlpha)
{
Expand All @@ -394,7 +396,7 @@ private bool DrawEntry(
ImGui.PopStyleVar();
}

initialCursor.Y += entry.Texture.Height * scale;
initialCursor.Y += dalamudTextureWrap.Height * scale;
ImGui.SetCursorPos(initialCursor);

return isHover;
Expand Down
38 changes: 10 additions & 28 deletions Dalamud/Interface/TitleScreenMenu/TitleScreenMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Dalamud.Interface;

using Textures;

/// <summary>
/// Class responsible for managing elements in the title screen menu.
/// </summary>
Expand Down Expand Up @@ -76,13 +78,8 @@ public IReadOnlyList<ITitleScreenMenuEntry> PluginEntries
/// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public ITitleScreenMenuEntry AddPluginEntry(string text, IDalamudTextureWrap texture, Action onTriggered)
public ITitleScreenMenuEntry AddPluginEntry(string text, ISharedImmediateTexture texture, Action onTriggered)
{
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}

TitleScreenMenuEntry entry;
lock (this.entries)
{
Expand All @@ -103,13 +100,13 @@ public ITitleScreenMenuEntry AddPluginEntry(string text, IDalamudTextureWrap tex
}

/// <inheritdoc/>
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, IDalamudTextureWrap texture, Action onTriggered)
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, ISharedImmediateTexture texture, Action onTriggered)
{
return this.AddPluginEntry(text, texture, onTriggered);
}

/// <inheritdoc/>
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered)
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered)
{
return this.AddPluginEntry(priority, text, texture, onTriggered);
}
Expand All @@ -123,13 +120,8 @@ public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, IDala
/// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public ITitleScreenMenuEntry AddPluginEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered)
public ITitleScreenMenuEntry AddPluginEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered)
{
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}

TitleScreenMenuEntry entry;
lock (this.entries)
{
Expand Down Expand Up @@ -166,13 +158,8 @@ public void RemoveEntry(IReadOnlyTitleScreenMenuEntry entry)
/// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="TitleScreenMenu"/> object that can be used to manage the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
internal TitleScreenMenuEntry AddEntryCore(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered)
internal TitleScreenMenuEntry AddEntryCore(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered)
{
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}

TitleScreenMenuEntry entry;
lock (this.entries)
{
Expand All @@ -199,15 +186,10 @@ internal TitleScreenMenuEntry AddEntryCore(ulong priority, string text, IDalamud
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
internal TitleScreenMenuEntry AddEntryCore(
string text,
IDalamudTextureWrap texture,
ISharedImmediateTexture texture,
Action onTriggered,
params VirtualKey[] showConditionKeys)
{
if (texture.Height != TextureSize || texture.Width != TextureSize)
{
throw new ArgumentException("Texture must be 64x64");
}

TitleScreenMenuEntry entry;
lock (this.entries)
{
Expand Down Expand Up @@ -256,7 +238,7 @@ void IInternalDisposableService.DisposeService()
}

/// <inheritdoc/>
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, IDalamudTextureWrap texture, Action onTriggered)
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, ISharedImmediateTexture texture, Action onTriggered)
{
var entry = this.titleScreenMenuService.AddPluginEntry(text, texture, onTriggered);
this.pluginEntries.Add(entry);
Expand All @@ -265,7 +247,7 @@ public IReadOnlyTitleScreenMenuEntry AddEntry(string text, IDalamudTextureWrap t
}

/// <inheritdoc/>
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered)
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered)
{
var entry = this.titleScreenMenuService.AddPluginEntry(priority, text, texture, onTriggered);
this.pluginEntries.Add(entry);
Expand Down
11 changes: 7 additions & 4 deletions Dalamud/Interface/TitleScreenMenu/TitleScreenMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Dalamud.Interface;

using Textures;

/// <summary>
/// A interface representing an entry in the title screen menu.
/// </summary>
Expand Down Expand Up @@ -64,7 +66,7 @@ public interface IReadOnlyTitleScreenMenuEntry
/// <summary>
/// Gets the texture of this entry.
/// </summary>
IDalamudTextureWrap Texture { get; }
ISharedImmediateTexture Texture { get; }
}

/// <summary>
Expand All @@ -87,7 +89,7 @@ internal TitleScreenMenuEntry(
Assembly? callingAssembly,
ulong priority,
string text,
IDalamudTextureWrap texture,
ISharedImmediateTexture texture,
Action onTriggered,
IEnumerable<VirtualKey>? showConditionKeys = null)
{
Expand All @@ -106,7 +108,7 @@ internal TitleScreenMenuEntry(
public string Name { get; set; }

/// <inheritdoc/>
public IDalamudTextureWrap Texture { get; set; }
public ISharedImmediateTexture Texture { get; set; }

/// <inheritdoc/>
public bool IsInternal { get; set; }
Expand Down Expand Up @@ -151,7 +153,8 @@ 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.ShowConditionKeys.All(x => Service<KeyState>.GetNullable()?[x] is true)
&& this.Texture.TryGetWrap(out var textureWrap, out _) && textureWrap.Width == 64 && textureWrap.Height == 64;

/// <summary>
/// Trigger the action associated with this entry.
Expand Down
10 changes: 6 additions & 4 deletions Dalamud/Plugin/Services/ITitleScreenMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Dalamud.Plugin.Services;

using Interface.Textures;

/// <summary>
/// Interface for class responsible for managing elements in the title screen menu.
/// </summary>
Expand All @@ -20,22 +22,22 @@ public interface ITitleScreenMenu
/// Adds a new entry to the title screen menu.
/// </summary>
/// <param name="text">The text to show.</param>
/// <param name="texture">The texture to show.</param>
/// <param name="texture">The texture to show. The texture must be 64x64 or the entry will not draw.</param>
/// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="IReadOnlyTitleScreenMenuEntry"/> object that can be reference the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, IDalamudTextureWrap texture, Action onTriggered);
public IReadOnlyTitleScreenMenuEntry AddEntry(string text, ISharedImmediateTexture texture, Action onTriggered);

/// <summary>
/// Adds a new entry to the title screen menu.
/// </summary>
/// <param name="priority">Priority of the entry.</param>
/// <param name="text">The text to show.</param>
/// <param name="texture">The texture to show.</param>
/// <param name="texture">The texture to show. The texture must be 64x64 or the entry will not draw.</param>
/// <param name="onTriggered">The action to execute when the option is selected.</param>
/// <returns>A <see cref="IReadOnlyTitleScreenMenuEntry"/> object that can be used to reference the entry.</returns>
/// <exception cref="ArgumentException">Thrown when the texture provided does not match the required resolution(64x64).</exception>
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, IDalamudTextureWrap texture, Action onTriggered);
public IReadOnlyTitleScreenMenuEntry AddEntry(ulong priority, string text, ISharedImmediateTexture texture, Action onTriggered);

/// <summary>
/// Remove an entry from the title screen menu.
Expand Down
50 changes: 50 additions & 0 deletions Dalamud/Storage/Assets/DalamudAssetTexture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Threading;
using System.Threading.Tasks;

using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;

namespace Dalamud.Storage.Assets;

/// <summary>
/// Wraps a dalamud asset texture allowing interoperability with certain services.
/// </summary>
internal class DalamudAssetTexture : ISharedImmediateTexture
{
private readonly IDalamudTextureWrap textureWrap;

/// <summary>
/// Initializes a new instance of the <see cref="DalamudAssetTexture"/> class.
/// </summary>
/// <param name="textureWrap">A textureWrap loaded by <see cref="DalamudAssetManager"/>.</param>
internal DalamudAssetTexture(IDalamudTextureWrap textureWrap)
{
this.textureWrap = textureWrap;
}

/// <inheritdoc/>
public IDalamudTextureWrap GetWrapOrEmpty()
{
return this.textureWrap;
}

/// <inheritdoc/>
public IDalamudTextureWrap? GetWrapOrDefault(IDalamudTextureWrap? defaultWrap = null)
{
return this.textureWrap;
}

/// <inheritdoc/>
public bool TryGetWrap(out IDalamudTextureWrap? texture, out Exception? exception)
{
texture = this.textureWrap;
exception = null;
return true;
}

/// <inheritdoc/>
public Task<IDalamudTextureWrap> RentAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(this.textureWrap);
}
}

0 comments on commit 1d8be18

Please sign in to comment.