Bring in tip scanner external

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ 2016-09-06 19:59:24 -06:00
parent c831f921ab
commit f39146ffb0
4 changed files with 93 additions and 19 deletions

View File

@ -11,7 +11,7 @@
## X-LoadOn-InterfaceOptions: GnomishVendorShrinker ## X-LoadOn-InterfaceOptions: GnomishVendorShrinker
externals\itemid.lua externals\itemid.lua
externals\ptr.lua externals\tooltip_scanner.lua
tekFunks\gsc.lua tekFunks\gsc.lua
tekKonfig\tekKonfig.xml tekKonfig\tekKonfig.xml

View File

@ -1,31 +1,28 @@
local myname, ns = ... local myname, ns = ...
local tip = CreateFrame("GameTooltip")
tip:SetOwner(WorldFrame, "ANCHOR_NONE")
local lcache = {} local function HasHeirloom(id)
for i=1,40 do return C_Heirloom.IsItemHeirloom(id) and C_Heirloom.PlayerHasHeirloom(id)
lcache[i] = tip:CreateFontString()
tip:AddFontStrings(lcache[i], tip:CreateFontString())
end end
ns.knowns = setmetatable({}, {__index = function(t, i)
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
ns.knowns = setmetatable({}, {
__index = function(t, i)
local id = ns.ids[i] local id = ns.ids[i]
if not id then return end if not id then return end
if C_Heirloom.IsItemHeirloom(id) and C_Heirloom.PlayerHasHeirloom(id) then if HasHeirloom(id) or IsKnown(i) then
t[i] = true
return true
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
t[i] = true t[i] = true
return true return true
end end
end end
end}) })

View File

@ -1 +1,2 @@
itemid.lua itemid.lua
tooltip_scanner.lua

76
externals/tooltip_scanner.lua vendored Normal file
View File

@ -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