From 895c4ae443bf88bb24639678606b3654dbdd11e9 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Fri, 23 Jun 2023 17:25:37 -0700
Subject: [PATCH] Add functions to get High Resolution icons (#1259)
Add new methods to retrieve high resolution icons (`_hr1`) from game files.
---
Dalamud/Data/DataManager.cs | 89 +++++++++++++++++++++++++------------
1 file changed, 61 insertions(+), 28 deletions(-)
diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs
index b6570a2ea..9d6a352ca 100644
--- a/Dalamud/Data/DataManager.cs
+++ b/Dalamud/Data/DataManager.cs
@@ -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;
@@ -169,10 +170,8 @@ public sealed class DataManager : IDisposable, IServiceType
///
/// The excel sheet type to get.
/// The , giving access to game rows.
- public ExcelSheet? GetExcelSheet() where T : ExcelRow
- {
- return this.Excel.GetSheet();
- }
+ public ExcelSheet? GetExcelSheet() where T : ExcelRow
+ => this.Excel.GetSheet();
///
/// Get an with the given Excel sheet row type with a specified language.
@@ -180,20 +179,16 @@ public sealed class DataManager : IDisposable, IServiceType
/// Language of the sheet to get.
/// The excel sheet type to get.
/// The , giving access to game rows.
- public ExcelSheet? GetExcelSheet(ClientLanguage language) where T : ExcelRow
- {
- return this.Excel.GetSheet(language.ToLumina());
- }
+ public ExcelSheet? GetExcelSheet(ClientLanguage language) where T : ExcelRow
+ => this.Excel.GetSheet(language.ToLumina());
///
/// Get a with the given path.
///
/// The path inside of the game files.
/// The of the file.
- public FileResource? GetFile(string path)
- {
- return this.GetFile(path);
- }
+ public FileResource? GetFile(string path)
+ => this.GetFile(path);
///
/// Get a with the given path, of the given type.
@@ -214,21 +209,27 @@ public sealed class DataManager : IDisposable, IServiceType
///
/// The path inside of the game files.
/// True if the file exists.
- public bool FileExists(string path)
- {
- return this.GameData.FileExists(path);
- }
+ 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.
- public TexFile? GetIcon(uint iconId)
- {
- return this.GetIcon(this.Language, iconId);
- }
+ /// todo: remove in api9 in favor of GetIcon(uint iconId, bool highResolution)
+ public TexFile? GetIcon(uint iconId)
+ => this.GetIcon(this.Language, iconId, false);
+ ///
+ /// Get a containing the icon with the given ID.
+ ///
+ /// The icon ID.
+ /// Return high resolution version.
+ /// The containing the icon.
+ public TexFile? GetIcon(uint iconId, bool highResolution)
+ => this.GetIcon(this.Language, iconId, highResolution);
+
///
/// Get a containing the icon with the given ID, of the given quality.
///
@@ -247,7 +248,18 @@ public sealed class DataManager : IDisposable, IServiceType
/// The requested language.
/// The icon ID.
/// The containing the icon.
+ /// 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);
+
+ ///
+ /// 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.
+ 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);
}
///
@@ -267,20 +279,33 @@ public sealed class DataManager : IDisposable, IServiceType
/// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon).
/// The icon ID.
/// The containing the icon.
+ /// 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);
+
+ ///
+ /// 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.
+ 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(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(filePath);
return file;
}
@@ -299,9 +324,7 @@ public sealed class DataManager : IDisposable, IServiceType
/// The Lumina .
/// A that can be used to draw the texture.
public TextureWrap? GetImGuiTexture(TexFile? tex)
- {
- return tex == null ? null : Service.Get().LoadImageRaw(tex.GetRgbaImageData(), tex.Header.Width, tex.Header.Height, 4);
- }
+ => tex == null ? null : Service.Get().LoadImageRaw(tex.GetRgbaImageData(), tex.Header.Width, tex.Header.Height, 4);
///
/// Get the passed texture path as a drawable ImGui TextureWrap.
@@ -316,8 +339,18 @@ public sealed class DataManager : IDisposable, IServiceType
///
/// The icon ID.
/// The containing the icon.
- public TextureWrap? GetImGuiTextureIcon(uint iconId)
- => this.GetImGuiTexture(this.GetIcon(iconId));
+ /// todo: remove in api9 in favor of GetImGuiTextureIcon(uint iconId, bool highResolution)
+ public TextureWrap? GetImGuiTextureIcon(uint iconId)
+ => this.GetImGuiTexture(this.GetIcon(iconId, false));
+
+ ///
+ /// Get a containing the icon with the given ID.
+ ///
+ /// The icon ID.
+ /// Return the high resolution version.
+ /// The containing the icon.
+ public TextureWrap? GetImGuiTextureIcon(uint iconId, bool highResolution)
+ => this.GetImGuiTexture(this.GetIcon(iconId, highResolution));
///
/// Get a containing the icon with the given ID, of the given quality.