forked from Caraxi/RemindMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIconManager.cs
66 lines (57 loc) · 2.36 KB
/
IconManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dalamud.Logging;
using Dalamud.Plugin;
using Dalamud.Utility;
using ImGuiScene;
using Action = Lumina.Excel.GeneratedSheets.Action;
namespace RemindMe {
public class IconManager : IDisposable {
private bool disposed;
private readonly Dictionary<uint, TextureWrap> iconTextures = new Dictionary<uint, TextureWrap>();
private readonly Dictionary<uint, uint> actionCustomIcons = new Dictionary<uint, uint>() {
{3, 104}, // Sprint
};
public void Dispose() {
disposed = true;
var c = 0;
PluginLog.Log("Disposing icon textures");
foreach (var texture in iconTextures.Values.Where(texture => texture != null)) {
c++;
texture.Dispose();
}
PluginLog.Log($"Disposed {c} icon textures.");
iconTextures.Clear();
}
private void LoadIconTexture(uint iconId) {
Task.Run(() => {
try {
var iconTex = Service.Data.GetIcon(iconId);
var tex = Service.UiBuilder.LoadImageRaw(iconTex.GetRgbaImageData(), iconTex.Header.Width, iconTex.Header.Height, 4);
if (tex.ImGuiHandle != IntPtr.Zero) {
this.iconTextures[iconId] = tex;
} else {
tex.Dispose();
}
} catch (Exception ex) {
PluginLog.LogError($"Failed loading texture for icon {iconId} - {ex.Message}");
}
});
}
public TextureWrap GetActionIcon(Action action) {
return GetIconTexture(actionCustomIcons.ContainsKey(action.RowId) ? actionCustomIcons[action.RowId] : action.Icon);
}
public uint GetActionIconId(Action action) {
return actionCustomIcons.ContainsKey(action.RowId) ? actionCustomIcons[action.RowId] : action.Icon;
}
public TextureWrap GetIconTexture(uint iconId) {
if (this.disposed) return null;
if (this.iconTextures.ContainsKey(iconId)) return this.iconTextures[iconId];
this.iconTextures.Add(iconId, null);
LoadIconTexture(iconId);
return this.iconTextures[iconId];
}
}
}