From 601c8c4affc7db1fd789b3c176903a165d473de1 Mon Sep 17 00:00:00 2001 From: Robin Schoonover Date: Mon, 5 Oct 2015 15:38:07 -0600 Subject: [PATCH] In quest log, handle currency reward types. --- AllTheIDs.toc | 1 + CurrencyCache.lua | 35 +++++++++++++++++++++++++++++++++++ GameTooltip.lua | 18 ++++++++++++++---- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 CurrencyCache.lua diff --git a/AllTheIDs.toc b/AllTheIDs.toc index 0bc31eb..b7ea759 100644 --- a/AllTheIDs.toc +++ b/AllTheIDs.toc @@ -5,5 +5,6 @@ ## Author: End ## X-Email: end@cornhooves.org AllTheIDs.lua +CurrencyCache.lua GameTooltip.lua Other.lua diff --git a/CurrencyCache.lua b/CurrencyCache.lua new file mode 100644 index 0000000..af014c0 --- /dev/null +++ b/CurrencyCache.lua @@ -0,0 +1,35 @@ + +local addon_name, addon = ... + +local function defaulttable(callable) + callable = callable or function() return nil end + return setmetatable({}, { + __index = function(t, key) + local val = callable() + rawset(t, key, val) + return val + end + }) +end + +addon.currencyCache = defaulttable(defaulttable) + +local event_frame = CreateFrame("FRAME") +event_frame:SetScript("OnEvent", function(frame, event, ...) + local func = frame[event] + if func then + return func(frame, ...) + end +end) + +function event_frame:PLAYER_ENTERING_WORLD() + for idx = 1,GetCurrencyListSize() do + local link = GetCurrencyListLink(idx) + local name, _, _, _, _, _, icon = GetCurrencyListInfo(idx) + if name and icon then + addon.currencyCache[name][icon] = link + end + end +end +event_frame:RegisterEvent("PLAYER_ENTERING_WORLD") +event_frame:PLAYER_ENTERING_WORLD() diff --git a/GameTooltip.lua b/GameTooltip.lua index b037f2a..82b9a26 100644 --- a/GameTooltip.lua +++ b/GameTooltip.lua @@ -107,12 +107,22 @@ addon:HookTip("SetMerchantCostItem", function(self, idx, currency) addon:AddIDLine(self, "Currency", currencyID) end) -addon:HookTip("SetQuestCurrency", function(self, type, idx) - -- TODO GetQuestCurrencyInfo(type, idx) => name, texture, count +addon:HookTip("SetQuestCurrency", function(tip, type, idx) + local name, icon = GetQuestCurrencyInfo(type, idx) + local link = addon.currencyCache[name][icon] + if link then + local _, _, name, id = strfind(link, "|H(%w+):(%d+)") + addon:AddIDLine(tip, name:gsub("^%l", string.upper), id) + end end) -addon:HookTip("SetQuestLogCurrency", function(self, type, idx) - -- TODO GetQuestLogRewardCurrencyInfo(idx) => name, texture, count +addon:HookTip("SetQuestLogCurrency", function(tip, type, idx) + local name, icon = GetQuestLogRewardCurrencyInfo(idx) + local link = addon.currencyCache[name][icon] + if link then + local _, _, name, id = strfind(link, "|H(%w+):(%d+)") + addon:AddIDLine(tip, name:gsub("^%l", string.upper), id) + end end) addon:HookTip("SetQuestLogItem", function(self, ...) -- GitLab