feat: add ITextureProvider.GetIconPath() function to allow for icon path lookups by plugins

This commit is contained in:
goat 2023-08-03 19:18:38 +02:00
parent 389ff91097
commit 8df154c1a9
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
2 changed files with 43 additions and 5 deletions

View file

@ -83,6 +83,25 @@ internal class TextureManager : IDisposable, IServiceType, ITextureSubstitutionP
/// to render the icon.
/// </returns>
public TextureManagerTextureWrap? GetIcon(uint iconId, ITextureProvider.IconFlags flags = ITextureProvider.IconFlags.HiRes, ClientLanguage? language = null, bool keepAlive = false)
{
var path = this.GetIconPath(iconId, flags, language);
return path == null ? null : this.CreateWrap(path, keepAlive);
}
/// <summary>
/// Get a path for a specific icon's .tex file.
/// </summary>
/// <param name="iconId">The ID of the icon to look up.</param>
/// <param name="flags">Options to be considered when loading the icon.</param>
/// <param name="language">
/// The language to be considered when loading the icon, if the icon has versions for multiple languages.
/// If null, default to the game's current language.
/// </param>
/// <returns>
/// Null, if the icon does not exist in the specified configuration, or the path to the texture's .tex file,
/// which can be loaded via IDataManager.
/// </returns>
public string? GetIconPath(uint iconId, ITextureProvider.IconFlags flags = ITextureProvider.IconFlags.HiRes, ClientLanguage? language = null)
{
var hiRes = flags.HasFlag(ITextureProvider.IconFlags.HiRes);
@ -92,7 +111,7 @@ internal class TextureManager : IDisposable, IServiceType, ITextureSubstitutionP
flags.HasFlag(ITextureProvider.IconFlags.ItemHighQuality) ? "hq/" : string.Empty,
hiRes);
if (this.dataManager.FileExists(path))
return this.CreateWrap(path, keepAlive);
return path;
language ??= this.startInfo.Language;
var languageFolder = language switch
@ -110,7 +129,7 @@ internal class TextureManager : IDisposable, IServiceType, ITextureSubstitutionP
languageFolder,
hiRes);
if (this.dataManager.FileExists(path))
return this.CreateWrap(path, keepAlive);
return path;
if (hiRes)
{
@ -120,7 +139,7 @@ internal class TextureManager : IDisposable, IServiceType, ITextureSubstitutionP
languageFolder,
false);
if (this.dataManager.FileExists(path))
return this.CreateWrap(path, keepAlive);
return path;
}
// 4. Regular icon, without language, hi-res
@ -129,7 +148,7 @@ internal class TextureManager : IDisposable, IServiceType, ITextureSubstitutionP
null,
hiRes);
if (this.dataManager.FileExists(path))
return this.CreateWrap(path, keepAlive);
return path;
// 4. Regular icon, without language, no hi-res
if (hiRes)
@ -139,7 +158,7 @@ internal class TextureManager : IDisposable, IServiceType, ITextureSubstitutionP
null,
false);
if (this.dataManager.FileExists(path))
return this.CreateWrap(path, keepAlive);
return path;
}
return null;
@ -480,6 +499,10 @@ internal class TextureManagerPluginScoped : ITextureProvider, IServiceType, IDis
return wrap;
}
/// <inheritdoc/>
public string? GetIconPath(uint iconId, ITextureProvider.IconFlags flags = ITextureProvider.IconFlags.HiRes, ClientLanguage? language = null)
=> this.textureManager.GetIconPath(iconId, flags, language);
/// <inheritdoc/>
public IDalamudTextureWrap? GetTextureFromGame(string path, bool keepAlive = false)
{

View file

@ -52,6 +52,21 @@ public interface ITextureProvider
/// </returns>
public IDalamudTextureWrap? GetIcon(uint iconId, IconFlags flags = IconFlags.HiRes, ClientLanguage? language = null, bool keepAlive = false);
/// <summary>
/// Get a path for a specific icon's .tex file.
/// </summary>
/// <param name="iconId">The ID of the icon to look up.</param>
/// <param name="flags">Options to be considered when loading the icon.</param>
/// <param name="language">
/// The language to be considered when loading the icon, if the icon has versions for multiple languages.
/// If null, default to the game's current language.
/// </param>
/// <returns>
/// Null, if the icon does not exist in the specified configuration, or the path to the texture's .tex file,
/// which can be loaded via IDataManager.
/// </returns>
public string? GetIconPath(uint iconId, IconFlags flags = IconFlags.HiRes, ClientLanguage? language = null);
/// <summary>
/// Get a texture handle for the texture at the specified path.
/// You may only specify paths in the game's VFS.