Add functions to get High Resolution icons (#1259)

Add new methods to retrieve high resolution icons (`_hr1`) from game files.
This commit is contained in:
MidoriKami 2023-06-23 17:25:37 -07:00 committed by GitHub
parent b80d9da1aa
commit 895c4ae443
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,7 @@ namespace Dalamud.Data;
public sealed class DataManager : IDisposable, IServiceType
{
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;
@ -170,9 +171,7 @@ public sealed class DataManager : IDisposable, IServiceType
/// <typeparam name="T">The excel sheet type to get.</typeparam>
/// <returns>The <see cref="ExcelSheet{T}"/>, giving access to game rows.</returns>
public ExcelSheet<T>? GetExcelSheet<T>() where T : ExcelRow
{
return this.Excel.GetSheet<T>();
}
=> this.Excel.GetSheet<T>();
/// <summary>
/// Get an <see cref="ExcelSheet{T}"/> with the given Excel sheet row type with a specified language.
@ -181,9 +180,7 @@ public sealed class DataManager : IDisposable, IServiceType
/// <typeparam name="T">The excel sheet type to get.</typeparam>
/// <returns>The <see cref="ExcelSheet{T}"/>, giving access to game rows.</returns>
public ExcelSheet<T>? GetExcelSheet<T>(ClientLanguage language) where T : ExcelRow
{
return this.Excel.GetSheet<T>(language.ToLumina());
}
=> this.Excel.GetSheet<T>(language.ToLumina());
/// <summary>
/// Get a <see cref="FileResource"/> with the given path.
@ -191,9 +188,7 @@ public sealed class DataManager : IDisposable, IServiceType
/// <param name="path">The path inside of the game files.</param>
/// <returns>The <see cref="FileResource"/> of the file.</returns>
public FileResource? GetFile(string path)
{
return this.GetFile<FileResource>(path);
}
=> this.GetFile<FileResource>(path);
/// <summary>
/// Get a <see cref="FileResource"/> with the given path, of the given type.
@ -215,19 +210,25 @@ public sealed class DataManager : IDisposable, IServiceType
/// <param name="path">The path inside of the game files.</param>
/// <returns>True if the file exists.</returns>
public bool FileExists(string path)
{
return 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>
/// todo: remove in api9 in favor of GetIcon(uint iconId, bool highResolution)
public TexFile? GetIcon(uint iconId)
{
return this.GetIcon(this.Language, iconId);
}
=> this.GetIcon(this.Language, iconId, false);
/// <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>
public TexFile? GetIcon(uint iconId, bool highResolution)
=> this.GetIcon(this.Language, iconId, highResolution);
/// <summary>
/// Get a <see cref="TexFile"/> containing the icon with the given ID, of the given quality.
@ -247,7 +248,18 @@ public sealed class DataManager : IDisposable, IServiceType
/// <param name="iconLanguage">The requested language.</param>
/// <param name="iconId">The icon ID.</param>
/// <returns>The <see cref="TexFile"/> containing the icon.</returns>
/// todo: remove in api9 in favor of GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution)
public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId)
=> this.GetIcon(iconLanguage, iconId, 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>
public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution)
{
var type = iconLanguage switch
{
@ -258,7 +270,7 @@ public sealed class DataManager : IDisposable, IServiceType
_ => throw new ArgumentOutOfRangeException(nameof(iconLanguage), $"Unknown Language: {iconLanguage}"),
};
return this.GetIcon(type, iconId);
return this.GetIcon(type, iconId, highResolution);
}
/// <summary>
@ -267,20 +279,33 @@ public sealed class DataManager : IDisposable, IServiceType
/// <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>
/// todo: remove in api9 in favor of GetIcon(string? type, uint iconId, bool highResolution)
public TexFile? GetIcon(string? type, uint iconId)
=> this.GetIcon(type, iconId, 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>
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(IconFileFormat, iconId / 1000, type, iconId);
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(IconFileFormat, iconId / 1000, string.Empty, iconId);
filePath = string.Format(format, iconId / 1000, string.Empty, iconId);
file = this.GetFile<TexFile>(filePath);
return file;
}
@ -299,9 +324,7 @@ public sealed class DataManager : IDisposable, IServiceType
/// <param name="tex">The Lumina <see cref="TexFile"/>.</param>
/// <returns>A <see cref="TextureWrap"/> that can be used to draw the texture.</returns>
public TextureWrap? GetImGuiTexture(TexFile? tex)
{
return tex == null ? null : Service<InterfaceManager>.Get().LoadImageRaw(tex.GetRgbaImageData(), tex.Header.Width, tex.Header.Height, 4);
}
=> tex == null ? null : Service<InterfaceManager>.Get().LoadImageRaw(tex.GetRgbaImageData(), tex.Header.Width, tex.Header.Height, 4);
/// <summary>
/// Get the passed texture path as a drawable ImGui TextureWrap.
@ -316,8 +339,18 @@ public sealed class DataManager : IDisposable, IServiceType
/// </summary>
/// <param name="iconId">The icon ID.</param>
/// <returns>The <see cref="TextureWrap"/> containing the icon.</returns>
/// todo: remove in api9 in favor of GetImGuiTextureIcon(uint iconId, bool highResolution)
public TextureWrap? GetImGuiTextureIcon(uint iconId)
=> this.GetImGuiTexture(this.GetIcon(iconId));
=> this.GetImGuiTexture(this.GetIcon(iconId, 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>
public TextureWrap? GetImGuiTextureIcon(uint iconId, bool highResolution)
=> this.GetImGuiTexture(this.GetIcon(iconId, highResolution));
/// <summary>
/// Get a <see cref="TextureWrap"/> containing the icon with the given ID, of the given quality.