From 758ae7c0979ec176a2cc98c6f9cd906d31c723de Mon Sep 17 00:00:00 2001 From: goat Date: Thu, 3 Aug 2023 20:32:31 +0200 Subject: [PATCH] Remove texture-related IDataManager functions --- Dalamud/Data/DataManager.cs | 155 ------------------ .../Interface/Internal/InterfaceManager.cs | 4 +- Dalamud/Interface/Internal/TextureManager.cs | 24 ++- Dalamud/Plugin/Services/IDataManager.cs | 107 ------------ 4 files changed, 22 insertions(+), 268 deletions(-) diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index 831b25cbc..8c8a2de29 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -36,9 +36,6 @@ namespace Dalamud.Data; #pragma warning restore SA1015 public sealed class DataManager : IDisposable, IServiceType, IDataManager { - private const string IconFileFormat = "ui/icon/{0:D3}000/{1}{2:D6}.tex"; - private const string HighResolutionIconFileFormat = "ui/icon/{0:D3}000/{1}{2:D6}_hr1.tex"; - private readonly Thread luminaResourceThread; private readonly CancellationTokenSource luminaCancellationTokenSource; @@ -185,158 +182,6 @@ public sealed class DataManager : IDisposable, IServiceType, IDataManager public bool FileExists(string path) => this.GameData.FileExists(path); - /// - /// Get a containing the icon with the given ID. - /// - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(uint iconId) - => this.GetIcon(this.Language, iconId, false); - - /// - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(uint iconId, bool highResolution) - => this.GetIcon(this.Language, iconId, highResolution); - - /// - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(bool isHq, uint iconId) - { - var type = isHq ? "hq/" : string.Empty; - return this.GetIcon(type, iconId); - } - - /// - /// Get a containing the icon with the given ID, of the given language. - /// - /// The requested language. - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId) - => this.GetIcon(iconLanguage, iconId, false); - - /// - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution) - { - var type = iconLanguage switch - { - ClientLanguage.Japanese => "ja/", - ClientLanguage.English => "en/", - ClientLanguage.German => "de/", - ClientLanguage.French => "fr/", - _ => throw new ArgumentOutOfRangeException(nameof(iconLanguage), $"Unknown Language: {iconLanguage}"), - }; - - return this.GetIcon(type, iconId, highResolution); - } - - /// - /// Get a containing the icon with the given ID, of the given type. - /// - /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(string? type, uint iconId) - => this.GetIcon(type, iconId, false); - - /// - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(string? type, uint iconId, bool highResolution) - { - var format = highResolution ? HighResolutionIconFileFormat : IconFileFormat; - - type ??= string.Empty; - if (type.Length > 0 && !type.EndsWith("/")) - type += "/"; - - var filePath = string.Format(format, iconId / 1000, type, iconId); - var file = this.GetFile(filePath); - - if (type == string.Empty || file != default) - return file; - - // Couldn't get specific type, try for generic version. - filePath = string.Format(format, iconId / 1000, string.Empty, iconId); - file = this.GetFile(filePath); - return file; - } - - /// - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetHqIcon(uint iconId) - => this.GetIcon(true, iconId); - - /// - [Obsolete("Use ITextureProvider instead")] - [return: NotNullIfNotNull(nameof(tex))] - public TextureWrap? GetImGuiTexture(TexFile? tex) - { - if (tex is null) - return null; - - var im = Service.Get(); - var buffer = tex.TextureBuffer; - var bpp = 1 << (((int)tex.Header.Format & (int)TexFile.TextureFormat.BppMask) >> - (int)TexFile.TextureFormat.BppShift); - - var (dxgiFormat, conversion) = TexFile.GetDxgiFormatFromTextureFormat(tex.Header.Format, false); - if (conversion != TexFile.DxgiFormatConversion.NoConversion || !im.SupportsDxgiFormat((Format)dxgiFormat)) - { - dxgiFormat = (int)Format.B8G8R8A8_UNorm; - buffer = buffer.Filter(0, 0, TexFile.TextureFormat.B8G8R8A8); - bpp = 32; - } - - var pitch = buffer is BlockCompressionTextureBuffer - ? Math.Max(1, (buffer.Width + 3) / 4) * 2 * bpp - : ((buffer.Width * bpp) + 7) / 8; - return im.LoadImageFromDxgiFormat(buffer.RawData, pitch, buffer.Width, buffer.Height, (Format)dxgiFormat); - } - - /// - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTexture(string path) - => this.GetImGuiTexture(this.GetFile(path)); - - /// - /// Get a containing the icon with the given ID. - /// - /// The icon ID. - /// The containing the icon. - /// TODO(v9): remove in api9 in favor of GetImGuiTextureIcon(uint iconId, bool highResolution) - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(uint iconId) - => this.GetImGuiTexture(this.GetIcon(iconId, false)); - - /// - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(uint iconId, bool highResolution) - => this.GetImGuiTexture(this.GetIcon(iconId, highResolution)); - - /// - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(bool isHq, uint iconId) - => this.GetImGuiTexture(this.GetIcon(isHq, iconId)); - - /// - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(ClientLanguage iconLanguage, uint iconId) - => this.GetImGuiTexture(this.GetIcon(iconLanguage, iconId)); - - /// - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(string type, uint iconId) - => this.GetImGuiTexture(this.GetIcon(type, iconId)); - - /// - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureHqIcon(uint iconId) - => this.GetImGuiTexture(this.GetHqIcon(iconId)); - #endregion /// diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index 841511f55..ad1e514c7 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -325,7 +325,7 @@ internal class InterfaceManager : IDisposable, IServiceType /// The height in pixels. /// Format of the texture. /// A texture, ready to use in ImGui. - public TextureWrap LoadImageFromDxgiFormat(Span data, int pitch, int width, int height, Format dxgiFormat) + public DalamudTextureWrap LoadImageFromDxgiFormat(Span data, int pitch, int width, int height, Format dxgiFormat) { if (this.scene == null) throw new InvalidOperationException("Scene isn't ready."); @@ -360,7 +360,7 @@ internal class InterfaceManager : IDisposable, IServiceType } // no sampler for now because the ImGui implementation we copied doesn't allow for changing it - return new D3DTextureWrap(resView, width, height); + return new DalamudTextureWrap(new D3DTextureWrap(resView, width, height)); } #nullable restore diff --git a/Dalamud/Interface/Internal/TextureManager.cs b/Dalamud/Interface/Internal/TextureManager.cs index 4b2f1f362..de5613eed 100644 --- a/Dalamud/Interface/Internal/TextureManager.cs +++ b/Dalamud/Interface/Internal/TextureManager.cs @@ -13,6 +13,8 @@ using Dalamud.Logging.Internal; using Dalamud.Plugin.Services; using ImGuiScene; using Lumina.Data.Files; +using Lumina.Data.Parsing.Tex.Buffers; +using SharpDX.DXGI; namespace Dalamud.Interface.Internal; @@ -207,10 +209,24 @@ internal class TextureManager : IDisposable, IServiceType, ITextureSubstitutionP if (!this.im.IsReady) throw new InvalidOperationException("Cannot create textures before scene is ready"); - -#pragma warning disable CS0618 - return this.dataManager.GetImGuiTexture(file) as IDalamudTextureWrap; -#pragma warning restore CS0618 + + var buffer = file.TextureBuffer; + var bpp = 1 << (((int)file.Header.Format & (int)TexFile.TextureFormat.BppMask) >> + (int)TexFile.TextureFormat.BppShift); + + var (dxgiFormat, conversion) = TexFile.GetDxgiFormatFromTextureFormat(file.Header.Format, false); + if (conversion != TexFile.DxgiFormatConversion.NoConversion || !im.SupportsDxgiFormat((Format)dxgiFormat)) + { + dxgiFormat = (int)Format.B8G8R8A8_UNorm; + buffer = buffer.Filter(0, 0, TexFile.TextureFormat.B8G8R8A8); + bpp = 32; + } + + var pitch = buffer is BlockCompressionTextureBuffer + ? Math.Max(1, (buffer.Width + 3) / 4) * 2 * bpp + : ((buffer.Width * bpp) + 7) / 8; + + return this.im.LoadImageFromDxgiFormat(buffer.RawData, pitch, buffer.Width, buffer.Height, (Format)dxgiFormat); } /// diff --git a/Dalamud/Plugin/Services/IDataManager.cs b/Dalamud/Plugin/Services/IDataManager.cs index a47303ea6..3ae10b0c7 100644 --- a/Dalamud/Plugin/Services/IDataManager.cs +++ b/Dalamud/Plugin/Services/IDataManager.cs @@ -81,111 +81,4 @@ public interface IDataManager /// The path inside of the game files. /// True if the file exists. public bool FileExists(string path); - - /// - /// Get a containing the icon with the given ID. - /// - /// The icon ID. - /// Return high resolution version. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(uint iconId, bool highResolution = false); - - /// - /// Get a containing the icon with the given ID, of the given language. - /// - /// The requested language. - /// The icon ID. - /// Return high resolution version. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution = false); - - /// - /// Get a containing the icon with the given ID, of the given type. - /// - /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). - /// The icon ID. - /// Return high resolution version. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(string? type, uint iconId, bool highResolution = false); - - /// - /// Get a containing the icon with the given ID. - /// - /// The icon ID. - /// Return the high resolution version. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(uint iconId, bool highResolution = false); - - /// - /// Get a containing the icon with the given ID, of the given quality. - /// - /// A value indicating whether the icon should be HQ. - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetIcon(bool isHq, uint iconId); - - /// - /// Get a containing the HQ icon with the given ID. - /// - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TexFile? GetHqIcon(uint iconId); - - /// - /// Get the passed as a drawable ImGui TextureWrap. - /// - /// The Lumina . - /// A that can be used to draw the texture. - [Obsolete("Use ITextureProvider instead")] - [return: NotNullIfNotNull(nameof(tex))] - public TextureWrap? GetImGuiTexture(TexFile? tex); - - /// - /// Get the passed texture path as a drawable ImGui TextureWrap. - /// - /// The internal path to the texture. - /// A that can be used to draw the texture. - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTexture(string path); - - /// - /// Get a containing the icon with the given ID, of the given quality. - /// - /// A value indicating whether the icon should be HQ. - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(bool isHq, uint iconId); - - /// - /// Get a containing the icon with the given ID, of the given language. - /// - /// The requested language. - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(ClientLanguage iconLanguage, uint iconId); - - /// - /// Get a containing the icon with the given ID, of the given type. - /// - /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureIcon(string type, uint iconId); - - /// - /// Get a containing the HQ icon with the given ID. - /// - /// The icon ID. - /// The containing the icon. - [Obsolete("Use ITextureProvider instead")] - public TextureWrap? GetImGuiTextureHqIcon(uint iconId); }