2023-11-01 09:09:37 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Dalamud.Interface.Internal;
|
2024-07-02 15:35:40 +00:00
|
|
|
|
using Dalamud.Interface.Textures;
|
|
|
|
|
using Dalamud.Interface.Textures.TextureWraps;
|
2023-11-01 09:09:37 +00:00
|
|
|
|
using Dalamud.Plugin.Services;
|
|
|
|
|
|
|
|
|
|
namespace LLib;
|
|
|
|
|
|
|
|
|
|
public sealed class IconCache : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private readonly ITextureProvider _textureProvider;
|
2024-07-02 15:35:40 +00:00
|
|
|
|
private readonly Dictionary<uint, ISharedImmediateTexture> _textureWraps = new();
|
2023-11-01 09:09:37 +00:00
|
|
|
|
|
|
|
|
|
public IconCache(ITextureProvider textureProvider)
|
|
|
|
|
{
|
|
|
|
|
_textureProvider = textureProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-03 16:58:01 +00:00
|
|
|
|
public IDalamudTextureWrap? GetIcon(uint iconId)
|
2023-11-01 09:09:37 +00:00
|
|
|
|
{
|
2024-07-03 16:58:01 +00:00
|
|
|
|
if (!_textureWraps.TryGetValue(iconId, out ISharedImmediateTexture? iconTex))
|
|
|
|
|
{
|
|
|
|
|
iconTex = _textureProvider.GetFromGameIcon(new GameIconLookup(iconId));
|
|
|
|
|
_textureWraps[iconId] = iconTex;
|
|
|
|
|
}
|
2023-11-01 09:09:37 +00:00
|
|
|
|
|
2024-07-03 16:58:01 +00:00
|
|
|
|
return iconTex.TryGetWrap(out IDalamudTextureWrap? wrap, out _) ? wrap : null;
|
2023-11-01 09:09:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_textureWraps.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|