mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-31 21:03:43 +01:00
Remove texture-related IDataManager functions
This commit is contained in:
parent
5c654ba178
commit
758ae7c097
4 changed files with 22 additions and 268 deletions
|
|
@ -36,9 +36,6 @@ namespace Dalamud.Data;
|
||||||
#pragma warning restore SA1015
|
#pragma warning restore SA1015
|
||||||
public sealed class DataManager : IDisposable, IServiceType, IDataManager
|
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 Thread luminaResourceThread;
|
||||||
private readonly CancellationTokenSource luminaCancellationTokenSource;
|
private readonly CancellationTokenSource luminaCancellationTokenSource;
|
||||||
|
|
||||||
|
|
@ -185,158 +182,6 @@ public sealed class DataManager : IDisposable, IServiceType, IDataManager
|
||||||
public bool FileExists(string path)
|
public bool FileExists(string path)
|
||||||
=> this.GameData.FileExists(path);
|
=> this.GameData.FileExists(path);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TexFile"/> containing the icon with the given ID.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(uint iconId)
|
|
||||||
=> this.GetIcon(this.Language, iconId, false);
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(uint iconId, bool highResolution)
|
|
||||||
=> this.GetIcon(this.Language, iconId, highResolution);
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(bool isHq, uint iconId)
|
|
||||||
{
|
|
||||||
var type = isHq ? "hq/" : string.Empty;
|
|
||||||
return this.GetIcon(type, iconId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TexFile"/> containing the icon with the given ID, of the given language.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconLanguage">The requested language.</param>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId)
|
|
||||||
=> this.GetIcon(iconLanguage, iconId, false);
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TexFile"/> containing the icon with the given ID, of the given type.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">The type of the icon (e.g. 'hq' to get the HQ variant of an item icon).</param>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(string? type, uint iconId)
|
|
||||||
=> this.GetIcon(type, iconId, false);
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[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<TexFile>(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<TexFile>(filePath);
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetHqIcon(uint iconId)
|
|
||||||
=> this.GetIcon(true, iconId);
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
[return: NotNullIfNotNull(nameof(tex))]
|
|
||||||
public TextureWrap? GetImGuiTexture(TexFile? tex)
|
|
||||||
{
|
|
||||||
if (tex is null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var im = Service<InterfaceManager>.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTexture(string path)
|
|
||||||
=> this.GetImGuiTexture(this.GetFile<TexFile>(path));
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TextureWrap"/> containing the icon with the given ID.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TextureWrap"/> containing the icon.</returns>
|
|
||||||
/// 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));
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureIcon(uint iconId, bool highResolution)
|
|
||||||
=> this.GetImGuiTexture(this.GetIcon(iconId, highResolution));
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureIcon(bool isHq, uint iconId)
|
|
||||||
=> this.GetImGuiTexture(this.GetIcon(isHq, iconId));
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureIcon(ClientLanguage iconLanguage, uint iconId)
|
|
||||||
=> this.GetImGuiTexture(this.GetIcon(iconLanguage, iconId));
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureIcon(string type, uint iconId)
|
|
||||||
=> this.GetImGuiTexture(this.GetIcon(type, iconId));
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureHqIcon(uint iconId)
|
|
||||||
=> this.GetImGuiTexture(this.GetHqIcon(iconId));
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
|
||||||
|
|
@ -325,7 +325,7 @@ internal class InterfaceManager : IDisposable, IServiceType
|
||||||
/// <param name="height">The height in pixels.</param>
|
/// <param name="height">The height in pixels.</param>
|
||||||
/// <param name="dxgiFormat">Format of the texture.</param>
|
/// <param name="dxgiFormat">Format of the texture.</param>
|
||||||
/// <returns>A texture, ready to use in ImGui.</returns>
|
/// <returns>A texture, ready to use in ImGui.</returns>
|
||||||
public TextureWrap LoadImageFromDxgiFormat(Span<byte> data, int pitch, int width, int height, Format dxgiFormat)
|
public DalamudTextureWrap LoadImageFromDxgiFormat(Span<byte> data, int pitch, int width, int height, Format dxgiFormat)
|
||||||
{
|
{
|
||||||
if (this.scene == null)
|
if (this.scene == null)
|
||||||
throw new InvalidOperationException("Scene isn't ready.");
|
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
|
// 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
|
#nullable restore
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ using Dalamud.Logging.Internal;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using ImGuiScene;
|
using ImGuiScene;
|
||||||
using Lumina.Data.Files;
|
using Lumina.Data.Files;
|
||||||
|
using Lumina.Data.Parsing.Tex.Buffers;
|
||||||
|
using SharpDX.DXGI;
|
||||||
|
|
||||||
namespace Dalamud.Interface.Internal;
|
namespace Dalamud.Interface.Internal;
|
||||||
|
|
||||||
|
|
@ -208,9 +210,23 @@ internal class TextureManager : IDisposable, IServiceType, ITextureSubstitutionP
|
||||||
if (!this.im.IsReady)
|
if (!this.im.IsReady)
|
||||||
throw new InvalidOperationException("Cannot create textures before scene is ready");
|
throw new InvalidOperationException("Cannot create textures before scene is ready");
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
var buffer = file.TextureBuffer;
|
||||||
return this.dataManager.GetImGuiTexture(file) as IDalamudTextureWrap;
|
var bpp = 1 << (((int)file.Header.Format & (int)TexFile.TextureFormat.BppMask) >>
|
||||||
#pragma warning restore CS0618
|
(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
|
||||||
|
|
@ -81,111 +81,4 @@ public interface IDataManager
|
||||||
/// <param name="path">The path inside of the game files.</param>
|
/// <param name="path">The path inside of the game files.</param>
|
||||||
/// <returns>True if the file exists.</returns>
|
/// <returns>True if the file exists.</returns>
|
||||||
public bool FileExists(string path);
|
public bool FileExists(string path);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TexFile"/> containing the icon with the given ID.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <param name="highResolution">Return high resolution version.</param>
|
|
||||||
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(uint iconId, bool highResolution = false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TexFile"/> containing the icon with the given ID, of the given language.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconLanguage">The requested language.</param>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <param name="highResolution">Return high resolution version.</param>
|
|
||||||
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution = false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TexFile"/> containing the icon with the given ID, of the given type.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">The type of the icon (e.g. 'hq' to get the HQ variant of an item icon).</param>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <param name="highResolution">Return high resolution version.</param>
|
|
||||||
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(string? type, uint iconId, bool highResolution = false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TextureWrap"/> containing the icon with the given ID.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <param name="highResolution">Return the high resolution version.</param>
|
|
||||||
/// <returns>The <see cref="TextureWrap"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureIcon(uint iconId, bool highResolution = false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TexFile"/> containing the icon with the given ID, of the given quality.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="isHq">A value indicating whether the icon should be HQ.</param>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetIcon(bool isHq, uint iconId);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TexFile"/> containing the HQ icon with the given ID.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TexFile? GetHqIcon(uint iconId);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the passed <see cref="TexFile"/> as a drawable ImGui TextureWrap.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tex">The Lumina <see cref="TexFile"/>.</param>
|
|
||||||
/// <returns>A <see cref="TextureWrap"/> that can be used to draw the texture.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
[return: NotNullIfNotNull(nameof(tex))]
|
|
||||||
public TextureWrap? GetImGuiTexture(TexFile? tex);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the passed texture path as a drawable ImGui TextureWrap.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">The internal path to the texture.</param>
|
|
||||||
/// <returns>A <see cref="TextureWrap"/> that can be used to draw the texture.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTexture(string path);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TextureWrap"/> containing the icon with the given ID, of the given quality.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="isHq">A value indicating whether the icon should be HQ.</param>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TextureWrap"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureIcon(bool isHq, uint iconId);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TextureWrap"/> containing the icon with the given ID, of the given language.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconLanguage">The requested language.</param>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TextureWrap"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureIcon(ClientLanguage iconLanguage, uint iconId);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TextureWrap"/> containing the icon with the given ID, of the given type.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">The type of the icon (e.g. 'hq' to get the HQ variant of an item icon).</param>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TextureWrap"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureIcon(string type, uint iconId);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a <see cref="TextureWrap"/> containing the HQ icon with the given ID.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="iconId">The icon ID.</param>
|
|
||||||
/// <returns>The <see cref="TextureWrap"/> containing the icon.</returns>
|
|
||||||
[Obsolete("Use ITextureProvider instead")]
|
|
||||||
public TextureWrap? GetImGuiTextureHqIcon(uint iconId);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue