From ca986b46a297f9fb7d97245b41200559054683bc Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Wed, 28 Feb 2024 21:17:50 +0900 Subject: [PATCH] cleanup --- Dalamud/Interface/Internal/TextureManager.cs | 4 +- .../Windows/Data/Widgets/TexWidget.cs | 32 +++---- .../FontAtlasFactory.BuildToolkit.cs | 2 +- .../Internals/FontAtlasFactory.cs | 2 +- .../Plugin/Services/ITextureProvider.Api9.cs | 11 +++ Dalamud/Plugin/Services/ITextureProvider.cs | 85 +++++++++---------- 6 files changed, 69 insertions(+), 67 deletions(-) diff --git a/Dalamud/Interface/Internal/TextureManager.cs b/Dalamud/Interface/Internal/TextureManager.cs index 018e55d8b..b0341f36c 100644 --- a/Dalamud/Interface/Internal/TextureManager.cs +++ b/Dalamud/Interface/Internal/TextureManager.cs @@ -343,7 +343,7 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid cancellationToken); /// - public bool SupportsDxgiFormat(int dxgiFormat) + public bool IsDxgiFormatSupported(int dxgiFormat) { if (this.interfaceManager.Scene is not { } scene) { @@ -516,7 +516,7 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid var buffer = file.TextureBuffer; var (dxgiFormat, conversion) = TexFile.GetDxgiFormatFromTextureFormat(file.Header.Format, false); - if (conversion != TexFile.DxgiFormatConversion.NoConversion || !this.SupportsDxgiFormat(dxgiFormat)) + if (conversion != TexFile.DxgiFormatConversion.NoConversion || !this.IsDxgiFormatSupported(dxgiFormat)) { dxgiFormat = (int)Format.B8G8R8A8_UNorm; buffer = buffer.Filter(0, 0, TexFile.TextureFormat.B8G8R8A8); diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/TexWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/TexWidget.cs index 980f32f3c..3fdf72cda 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/TexWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/TexWidget.cs @@ -107,31 +107,31 @@ internal class TexWidget : IDataWindowWidget ImGui.PopID(); } - if (ImGui.CollapsingHeader("Load Game File by Icon ID", ImGuiTreeNodeFlags.DefaultOpen)) + if (ImGui.CollapsingHeader(nameof(ITextureProvider.GetFromGameIcon), ImGuiTreeNodeFlags.DefaultOpen)) { - ImGui.PushID(nameof(this.DrawIconInput)); - this.DrawIconInput(); + ImGui.PushID(nameof(this.DrawGetFromGameIcon)); + this.DrawGetFromGameIcon(); ImGui.PopID(); } - if (ImGui.CollapsingHeader("Load Game File by Path", ImGuiTreeNodeFlags.DefaultOpen)) + if (ImGui.CollapsingHeader(nameof(ITextureProvider.GetFromGame), ImGuiTreeNodeFlags.DefaultOpen)) { - ImGui.PushID(nameof(this.DrawGamePathInput)); - this.DrawGamePathInput(); + ImGui.PushID(nameof(this.DrawGetFromGame)); + this.DrawGetFromGame(); ImGui.PopID(); } - if (ImGui.CollapsingHeader("Load File", ImGuiTreeNodeFlags.DefaultOpen)) + if (ImGui.CollapsingHeader(nameof(ITextureProvider.GetFromFile), ImGuiTreeNodeFlags.DefaultOpen)) { - ImGui.PushID(nameof(this.DrawFileInput)); - this.DrawFileInput(); + ImGui.PushID(nameof(this.DrawGetFromFile)); + this.DrawGetFromFile(); ImGui.PopID(); } - if (ImGui.CollapsingHeader("Load Assembly Manifest Resource", ImGuiTreeNodeFlags.DefaultOpen)) + if (ImGui.CollapsingHeader(nameof(ITextureProvider.GetFromManifestResource), ImGuiTreeNodeFlags.DefaultOpen)) { - ImGui.PushID(nameof(this.DrawAssemblyManifestResourceInput)); - this.DrawAssemblyManifestResourceInput(); + ImGui.PushID(nameof(this.DrawGetFromManifestResource)); + this.DrawGetFromManifestResource(); ImGui.PopID(); } @@ -308,7 +308,7 @@ internal class TexWidget : IDataWindowWidget ImGuiHelpers.ScaledDummy(10); } - private void DrawIconInput() + private void DrawGetFromGameIcon() { ImGui.InputText("Icon ID", ref this.iconId, 32); ImGui.Checkbox("HQ Item", ref this.hq); @@ -342,7 +342,7 @@ internal class TexWidget : IDataWindowWidget ImGuiHelpers.ScaledDummy(10); } - private void DrawGamePathInput() + private void DrawGetFromGame() { ImGui.InputText("Tex Path", ref this.inputTexPath, 255); @@ -362,7 +362,7 @@ internal class TexWidget : IDataWindowWidget ImGuiHelpers.ScaledDummy(10); } - private void DrawFileInput() + private void DrawGetFromFile() { ImGui.InputText("File Path", ref this.inputFilePath, 255); @@ -382,7 +382,7 @@ internal class TexWidget : IDataWindowWidget ImGuiHelpers.ScaledDummy(10); } - private void DrawAssemblyManifestResourceInput() + private void DrawGetFromManifestResource() { if (this.inputManifestResourceAssemblyCandidateNames is null || this.inputManifestResourceAssemblyCandidates is null) diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs index 0e344f450..89a47c552 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs @@ -580,7 +580,7 @@ internal sealed partial class FontAtlasFactory var buf = Array.Empty(); try { - var use4 = this.factory.TextureManager.SupportsDxgiFormat((int)Format.B4G4R4A4_UNorm); + var use4 = this.factory.TextureManager.IsDxgiFormatSupported((int)Format.B4G4R4A4_UNorm); var bpp = use4 ? 2 : 4; var width = this.NewImAtlas.TexWidth; var height = this.NewImAtlas.TexHeight; diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.cs index b3edcc9b2..532e223fc 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.cs @@ -353,7 +353,7 @@ internal sealed partial class FontAtlasFactory var numPixels = texFile.Header.Width * texFile.Header.Height; _ = Service.Get(); - var targetIsB4G4R4A4 = this.TextureManager.SupportsDxgiFormat((int)Format.B4G4R4A4_UNorm); + var targetIsB4G4R4A4 = this.TextureManager.IsDxgiFormatSupported((int)Format.B4G4R4A4_UNorm); var bpp = targetIsB4G4R4A4 ? 2 : 4; var buffer = ArrayPool.Shared.Rent(numPixels * bpp); try diff --git a/Dalamud/Plugin/Services/ITextureProvider.Api9.cs b/Dalamud/Plugin/Services/ITextureProvider.Api9.cs index 2a1a3a9a5..71d1bf928 100644 --- a/Dalamud/Plugin/Services/ITextureProvider.Api9.cs +++ b/Dalamud/Plugin/Services/ITextureProvider.Api9.cs @@ -4,6 +4,8 @@ using Dalamud.Interface; using Dalamud.Interface.Internal; using Dalamud.Utility; +using Lumina.Data.Files; + namespace Dalamud.Plugin.Services; /// @@ -96,4 +98,13 @@ public partial interface ITextureProvider [Obsolete($"Use {nameof(GetFromFile)}.")] [Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)] public IDalamudTextureWrap? GetTextureFromFile(FileInfo file, bool keepAlive = false); + + /// + /// Get a texture handle for the specified Lumina . + /// + /// The texture to obtain a handle to. + /// A texture wrap that can be used to render the texture. Dispose after use. + [Obsolete($"Use {nameof(CreateFromTexFile)}.")] + [Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)] + IDalamudTextureWrap GetTexture(TexFile file) => this.CreateFromTexFile(file); } diff --git a/Dalamud/Plugin/Services/ITextureProvider.cs b/Dalamud/Plugin/Services/ITextureProvider.cs index 031825379..46ad0fb46 100644 --- a/Dalamud/Plugin/Services/ITextureProvider.cs +++ b/Dalamud/Plugin/Services/ITextureProvider.cs @@ -27,27 +27,6 @@ namespace Dalamud.Plugin.Services; /// public partial interface ITextureProvider { - /// Gets a shared texture corresponding to the given game resource icon specifier. - /// A game icon specifier. - /// The shared texture that you may use to obtain the loaded texture wrap and load states. - ISharedImmediateTexture GetFromGameIcon(in GameIconLookup lookup); - - /// Gets a shared texture corresponding to the given path to a game resource. - /// A path to a game resource. - /// The shared texture that you may use to obtain the loaded texture wrap and load states. - ISharedImmediateTexture GetFromGame(string path); - - /// Gets a shared texture corresponding to the given file on the filesystem. - /// A path to a file on the filesystem. - /// The shared texture that you may use to obtain the loaded texture wrap and load states. - ISharedImmediateTexture GetFromFile(string path); - - /// Gets a shared texture corresponding to the given file of the assembly manifest resources. - /// The assembly containing manifest resources. - /// The case-sensitive name of the manifest resource being requested. - /// The shared texture that you may use to obtain the loaded texture wrap and load states. - ISharedImmediateTexture GetFromManifestResource(Assembly assembly, string name); - /// Gets a texture from the given bytes, trying to interpret it as a .tex file or other well-known image /// files, such as .png. /// The bytes to load. @@ -102,31 +81,6 @@ public partial interface ITextureProvider bool leaveOpen = false, CancellationToken cancellationToken = default); - /// - /// Get a path for a specific icon's .tex file. - /// - /// The icon lookup. - /// The path to the icon. - /// If a corresponding file could not be found. - string GetIconPath(in GameIconLookup lookup); - - /// - /// Gets the path of an icon. - /// - /// The icon lookup. - /// The resolved path. - /// true if the corresponding file exists and has been set. - bool TryGetIconPath(in GameIconLookup lookup, [NotNullWhen(true)] out string? path); - - /// - /// Get a texture handle for the specified Lumina . - /// Alias for fetching from . - /// - /// The texture to obtain a handle to. - /// A texture wrap that can be used to render the texture. Dispose after use. - /// Alias for . - IDalamudTextureWrap GetTexture(TexFile file) => this.CreateFromTexFile(file); - /// /// Get a texture handle for the specified Lumina . /// Alias for fetching from . @@ -145,11 +99,48 @@ public partial interface ITextureProvider TexFile file, CancellationToken cancellationToken = default); + /// Gets a shared texture corresponding to the given game resource icon specifier. + /// A game icon specifier. + /// The shared texture that you may use to obtain the loaded texture wrap and load states. + ISharedImmediateTexture GetFromGameIcon(in GameIconLookup lookup); + + /// Gets a shared texture corresponding to the given path to a game resource. + /// A path to a game resource. + /// The shared texture that you may use to obtain the loaded texture wrap and load states. + ISharedImmediateTexture GetFromGame(string path); + + /// Gets a shared texture corresponding to the given file on the filesystem. + /// A path to a file on the filesystem. + /// The shared texture that you may use to obtain the loaded texture wrap and load states. + ISharedImmediateTexture GetFromFile(string path); + + /// Gets a shared texture corresponding to the given file of the assembly manifest resources. + /// The assembly containing manifest resources. + /// The case-sensitive name of the manifest resource being requested. + /// The shared texture that you may use to obtain the loaded texture wrap and load states. + ISharedImmediateTexture GetFromManifestResource(Assembly assembly, string name); + + /// + /// Get a path for a specific icon's .tex file. + /// + /// The icon lookup. + /// The path to the icon. + /// If a corresponding file could not be found. + string GetIconPath(in GameIconLookup lookup); + + /// + /// Gets the path of an icon. + /// + /// The icon lookup. + /// The resolved path. + /// true if the corresponding file exists and has been set. + bool TryGetIconPath(in GameIconLookup lookup, [NotNullWhen(true)] out string? path); + /// /// Determines whether the system supports the given DXGI format. /// For use with . /// /// The DXGI format. /// true if supported. - bool SupportsDxgiFormat(int dxgiFormat); + bool IsDxgiFormatSupported(int dxgiFormat); }