From f39146ffb0fe094c86e0ae86a8e2a512e4bad0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tekkub=20=CA=95=20=C2=B4=E1=B4=A5=60=20=CA=94?= Date: Tue, 6 Sep 2016 19:59:24 -0600 Subject: [PATCH] Bring in tip scanner external --- GnomishVendorShrinker.toc | 2 +- KnownScanner.lua | 33 +++++++-------- externals.txt | 1 + externals/tooltip_scanner.lua | 76 +++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 externals/tooltip_scanner.lua diff --git a/GnomishVendorShrinker.toc b/GnomishVendorShrinker.toc index 93b1c57..9dd8720 100644 --- a/GnomishVendorShrinker.toc +++ b/GnomishVendorShrinker.toc @@ -11,7 +11,7 @@ ## X-LoadOn-InterfaceOptions: GnomishVendorShrinker externals\itemid.lua -externals\ptr.lua +externals\tooltip_scanner.lua tekFunks\gsc.lua tekKonfig\tekKonfig.xml diff --git a/KnownScanner.lua b/KnownScanner.lua index 40ea7e8..7d25df1 100644 --- a/KnownScanner.lua +++ b/KnownScanner.lua @@ -1,31 +1,28 @@ local myname, ns = ... -local tip = CreateFrame("GameTooltip") -tip:SetOwner(WorldFrame, "ANCHOR_NONE") -local lcache = {} -for i=1,40 do - lcache[i] = tip:CreateFontString() - tip:AddFontStrings(lcache[i], tip:CreateFontString()) +local function HasHeirloom(id) + return C_Heirloom.IsItemHeirloom(id) and C_Heirloom.PlayerHasHeirloom(id) end -ns.knowns = setmetatable({}, {__index = function(t, i) - local id = ns.ids[i] - if not id then return end - if C_Heirloom.IsItemHeirloom(id) and C_Heirloom.PlayerHasHeirloom(id) then - t[i] = true - return true +local function IsKnown(link) + ns.scantip:SetHyperlink(link) + for i=1,ns.scantip:NumLines() do + if ns.scantip.L[i] == ITEM_SPELL_KNOWN then return true end end +end - tip:ClearLines() - if not tip:IsOwned(WorldFrame) then tip:SetOwner(WorldFrame, "ANCHOR_NONE") end - tip:SetHyperlink(i) - for i=1,tip:NumLines() do - if lcache[i]:GetText() == ITEM_SPELL_KNOWN then + +ns.knowns = setmetatable({}, { + __index = function(t, i) + local id = ns.ids[i] + if not id then return end + + if HasHeirloom(id) or IsKnown(i) then t[i] = true return true end end -end}) +}) diff --git a/externals.txt b/externals.txt index ed20bac..99aa9e1 100644 --- a/externals.txt +++ b/externals.txt @@ -1 +1,2 @@ itemid.lua +tooltip_scanner.lua diff --git a/externals/tooltip_scanner.lua b/externals/tooltip_scanner.lua new file mode 100644 index 0000000..b0566f6 --- /dev/null +++ b/externals/tooltip_scanner.lua @@ -0,0 +1,76 @@ + +local myname, ns = ... + + +local tip = CreateFrame("GameTooltip") +tip:SetOwner(WorldFrame, "ANCHOR_NONE") + +ns.scantip = tip + + +local lcache, rcache = {}, {} +for i=1,30 do + lcache[i], rcache[i] = tip:CreateFontString(), tip:CreateFontString() + lcache[i]:SetFontObject(GameFontNormal) + rcache[i]:SetFontObject(GameFontNormal) + tip:AddFontStrings(lcache[i], rcache[i]) +end + + +-- GetText cache tables, provide fast access to the tooltip's text +tip.L = setmetatable({}, { + __index = function(t, key) + if tip:NumLines() >= key and lcache[key] then + local v = lcache[key]:GetText() + t[key] = v + return v + end + return nil + end, +}) + + +tip.R = setmetatable({}, { + __index = function(t, key) + if tip:NumLines() >= key and rcache[key] then + local v = rcache[key]:GetText() + t[key] = v + return v + end + return nil + end, +}) + + +-- Performes a "full" erase of the tooltip +tip.Erase = function(self) + self:ClearLines() -- Ensures tooltip's NumLines is reset + for i in pairs(self.L) do self.L[i] = nil end -- Flush the metatable cache + for i in pairs(self.R) do + self.rcache[i]:SetText() -- Clear text from right side (ClearLines only hides them) + self.R[i] = nil -- Flush the metatable cache + end + if not self:IsOwned(WorldFrame) then + self:SetOwner(WorldFrame, "ANCHOR_NONE") + end +end + + +-- Hooks the Set* methods to force a full erase beforehand +local methods = {"SetMerchantCostItem", "SetBagItem", "SetAction", + "SetAuctionItem", "SetAuctionSellItem", "SetBuybackItem", "SetCraftItem", + "SetCraftSpell", "SetHyperlink", "SetInboxItem", "SetInventoryItem", + "SetLootItem", "SetLootRollItem", "SetMerchantItem", "SetPetAction", + "SetPlayerBuff", "SetQuestItem", "SetQuestLogItem", "SetQuestRewardSpell", + "SetSendMailItem", "SetShapeshift", "SetSpell", "SetTalent", + "SetTrackingSpell", "SetTradePlayerItem", "SetTradeSkillItem", + "SetTradeTargetItem", "SetTrainerService", "SetUnit", "SetUnitBuff", + "SetUnitDebuff"} +for _,m in pairs(methods) do + local orig = tip[m] + tip[m] = function(self, ...) + self:Erase() + return orig(self, ...) + end +end +