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