Switch to dalamuds texture cache
This commit is contained in:
@@ -31,3 +31,6 @@ changelog: |-
|
||||
**LiteDB**
|
||||
- Migration option removed
|
||||
- Old files can still be deleted in the database tab
|
||||
|
||||
**Textures**
|
||||
- Switch to dalamuds internal texture cache
|
||||
|
||||
+20
-19
@@ -10,6 +10,7 @@ using Dalamud.Game.Config;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
using Dalamud.Interface.ImGuiNotification;
|
||||
using Dalamud.Interface.Textures;
|
||||
using Dalamud.Interface.Textures.TextureWraps;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
@@ -32,10 +33,10 @@ public sealed class PayloadHandler {
|
||||
private ChatLogWindow LogWindow { get; }
|
||||
private (Chunk, Payload?)? Popup { get; set; }
|
||||
|
||||
public bool _handleTooltips;
|
||||
public uint _hoveredItem;
|
||||
public uint _hoverCounter;
|
||||
public uint _lastHoverCounter;
|
||||
public bool HandleTooltips;
|
||||
public uint HoveredItem;
|
||||
public uint HoverCounter;
|
||||
public uint LastHoverCounter;
|
||||
|
||||
private readonly ExcelSheet<Item> ItemSheet;
|
||||
private readonly ExcelSheet<EventItem> EventItemSheet;
|
||||
@@ -58,12 +59,12 @@ public sealed class PayloadHandler {
|
||||
{
|
||||
DrawPopups();
|
||||
|
||||
if (_handleTooltips && ++_hoverCounter - _lastHoverCounter > 1)
|
||||
if (HandleTooltips && ++HoverCounter - LastHoverCounter > 1)
|
||||
{
|
||||
GameFunctions.GameFunctions.CloseItemTooltip();
|
||||
_hoveredItem = 0;
|
||||
_hoverCounter = _lastHoverCounter = 0;
|
||||
_handleTooltips = false;
|
||||
HoveredItem = 0;
|
||||
HoverCounter = LastHoverCounter = 0;
|
||||
HandleTooltips = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,17 +233,17 @@ public sealed class PayloadHandler {
|
||||
case ItemPayload item:
|
||||
if (Plugin.Config.NativeItemTooltips)
|
||||
{
|
||||
if (!_handleTooltips || _hoveredItem != item.RawItemId)
|
||||
if (!HandleTooltips || HoveredItem != item.RawItemId)
|
||||
{
|
||||
_handleTooltips = true;
|
||||
_hoveredItem = item.RawItemId;
|
||||
_hoverCounter = _lastHoverCounter = 0;
|
||||
HandleTooltips = true;
|
||||
HoveredItem = item.RawItemId;
|
||||
HoverCounter = LastHoverCounter = 0;
|
||||
|
||||
GameFunctions.GameFunctions.OpenItemTooltip(item.RawItemId, item.Kind);
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastHoverCounter = _hoverCounter;
|
||||
LastHoverCounter = HoverCounter;
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -269,7 +270,7 @@ public sealed class PayloadHandler {
|
||||
|
||||
public unsafe void MoveTooltip(AddonEvent type, AddonArgs args)
|
||||
{
|
||||
if (!_handleTooltips)
|
||||
if (!HandleTooltips)
|
||||
return;
|
||||
|
||||
// Only move if user has "Next to Cursor" option selected
|
||||
@@ -311,7 +312,7 @@ public sealed class PayloadHandler {
|
||||
|
||||
private void HoverStatus(StatusPayload status)
|
||||
{
|
||||
if (LogWindow.Plugin.TextureCache.GetStatus(status.Status) is { } icon)
|
||||
if (Plugin.TextureProvider.GetFromGameIcon(status.Status.Icon).GetWrapOrDefault() is { } icon)
|
||||
InlineIcon(icon);
|
||||
|
||||
var name = ChunkUtil.ToChunks(status.Status.Name.ToDalamudString(), ChunkSource.None, null);
|
||||
@@ -333,7 +334,7 @@ public sealed class PayloadHandler {
|
||||
if (item.Item == null)
|
||||
return;
|
||||
|
||||
if (LogWindow.Plugin.TextureCache.GetItem(item.Item, item.IsHQ) is { } icon)
|
||||
if (Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(item.Item.Icon, item.IsHQ)).GetWrapOrDefault() is { } icon)
|
||||
InlineIcon(icon);
|
||||
|
||||
var name = ChunkUtil.ToChunks(item.Item.Name.ToDalamudString(), ChunkSource.None, null);
|
||||
@@ -350,7 +351,7 @@ public sealed class PayloadHandler {
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
if (LogWindow.Plugin.TextureCache.GetEventItem(item) is { } icon)
|
||||
if (Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(item.Icon)).GetWrapOrDefault() is { } icon)
|
||||
InlineIcon(icon);
|
||||
|
||||
var name = ChunkUtil.ToChunks(item.Name.ToDalamudString(), ChunkSource.None, null);
|
||||
@@ -456,7 +457,7 @@ public sealed class PayloadHandler {
|
||||
return;
|
||||
|
||||
var hq = payload.Kind == ItemPayload.ItemKind.Hq;
|
||||
if (LogWindow.Plugin.TextureCache.GetItem(item, hq) is { } icon)
|
||||
if (Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(item.Icon, hq)).GetWrapOrDefault() is { } icon)
|
||||
InlineIcon(icon);
|
||||
|
||||
var name = item.Name.ToDalamudString();
|
||||
@@ -502,7 +503,7 @@ public sealed class PayloadHandler {
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
if (LogWindow.Plugin.TextureCache.GetEventItem(item) is { } icon)
|
||||
if (Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(item.Icon)).GetWrapOrDefault() is { } icon)
|
||||
InlineIcon(icon);
|
||||
|
||||
var name = item.Name.ToDalamudString();
|
||||
|
||||
@@ -53,7 +53,6 @@ public sealed class Plugin : IDalamudPlugin
|
||||
|
||||
internal Commands Commands { get; }
|
||||
internal ChatCommon Common { get; }
|
||||
internal TextureCache TextureCache { get; }
|
||||
internal GameFunctions.GameFunctions Functions { get; }
|
||||
internal MessageManager MessageManager { get; }
|
||||
internal IpcManager Ipc { get; }
|
||||
@@ -80,7 +79,6 @@ public sealed class Plugin : IDalamudPlugin
|
||||
|
||||
Commands = new Commands(this);
|
||||
Common = new ChatCommon();
|
||||
TextureCache = new TextureCache();
|
||||
Functions = new GameFunctions.GameFunctions(this);
|
||||
Ipc = new IpcManager();
|
||||
ExtraChat = new ExtraChat(this);
|
||||
@@ -158,7 +156,6 @@ public sealed class Plugin : IDalamudPlugin
|
||||
Ipc?.Dispose();
|
||||
MessageManager?.DisposeAsync().AsTask().Wait();
|
||||
Functions?.Dispose();
|
||||
TextureCache?.Dispose();
|
||||
Commands?.Dispose();
|
||||
|
||||
EmoteCache.Dispose();
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
using Dalamud.Interface.Textures;
|
||||
using Dalamud.Interface.Textures.TextureWraps;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
|
||||
namespace ChatTwo;
|
||||
|
||||
internal class TextureCache : IDisposable
|
||||
{
|
||||
private readonly Dictionary<(uint, bool), IDalamudTextureWrap> _itemIcons = new();
|
||||
private readonly Dictionary<(uint, bool), IDalamudTextureWrap> _statusIcons = new();
|
||||
private readonly Dictionary<(uint, bool), IDalamudTextureWrap> _eventItemIcons = new();
|
||||
|
||||
private IReadOnlyDictionary<(uint, bool), IDalamudTextureWrap> ItemIcons => _itemIcons;
|
||||
private IReadOnlyDictionary<(uint, bool), IDalamudTextureWrap> StatusIcons => _statusIcons;
|
||||
private IReadOnlyDictionary<(uint, bool), IDalamudTextureWrap> EventItemIcons => _eventItemIcons;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var tex in ItemIcons.Values.Concat(StatusIcons.Values))
|
||||
tex.Dispose();
|
||||
}
|
||||
|
||||
private void AddIcon(IDictionary<(uint, bool), IDalamudTextureWrap> dict, uint icon, bool hq = false) {
|
||||
if (dict.ContainsKey((icon, hq)))
|
||||
return;
|
||||
|
||||
var tex = Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(icon, hq)).RentAsync().Result;
|
||||
if (tex != null)
|
||||
dict[(icon, hq)] = tex;
|
||||
}
|
||||
|
||||
private void AddItem(Item item, bool hq)
|
||||
{
|
||||
AddIcon(_itemIcons, item.Icon, hq);
|
||||
}
|
||||
|
||||
private void AddStatus(Status status)
|
||||
{
|
||||
AddIcon(_statusIcons, status.Icon);
|
||||
}
|
||||
|
||||
private void AddEventItem(EventItem item)
|
||||
{
|
||||
AddIcon(_eventItemIcons, item.Icon);
|
||||
}
|
||||
|
||||
internal IDalamudTextureWrap? GetItem(Item item, bool hq = false)
|
||||
{
|
||||
AddItem(item, hq);
|
||||
ItemIcons.TryGetValue((item.Icon, hq), out var icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
internal IDalamudTextureWrap? GetStatus(Status status)
|
||||
{
|
||||
AddStatus(status);
|
||||
StatusIcons.TryGetValue((status.Icon, false), out var icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
internal IDalamudTextureWrap? GetEventItem(EventItem item)
|
||||
{
|
||||
AddEventItem(item);
|
||||
EventItemIcons.TryGetValue((item.Icon, false), out var icon);
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,9 @@ public class DebuggerWindow : Window
|
||||
if (ImGui.Selectable($"Agent Address: {agent:X}"))
|
||||
ImGui.SetClipboardText(agent.ToString("X"));
|
||||
|
||||
ImGui.TextUnformatted($"Handle Tooltips: {ChatLogWindow.PayloadHandler._handleTooltips}");
|
||||
ImGui.TextUnformatted($"Hovered Item: {ChatLogWindow.PayloadHandler._hoveredItem}");
|
||||
ImGui.TextUnformatted($"Hover Counter: {ChatLogWindow.PayloadHandler._hoverCounter}");
|
||||
ImGui.TextUnformatted($"Last Hover Counter: {ChatLogWindow.PayloadHandler._lastHoverCounter}");
|
||||
ImGui.TextUnformatted($"Handle Tooltips: {ChatLogWindow.PayloadHandler.HandleTooltips}");
|
||||
ImGui.TextUnformatted($"Hovered Item: {ChatLogWindow.PayloadHandler.HoveredItem}");
|
||||
ImGui.TextUnformatted($"Hover Counter: {ChatLogWindow.PayloadHandler.HoverCounter}");
|
||||
ImGui.TextUnformatted($"Last Hover Counter: {ChatLogWindow.PayloadHandler.LastHoverCounter}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user