Commit 1ba5325c authored by Robin Schoonover's avatar Robin Schoonover

Refactor some code into common module and add IDs to pet card.

parent 8377dddf
local addon_name, addon = ...
local tmp = {}
function addon:AddIDLine(tip, ...) -- idname, id
if tip._alltheid then
return
end
wipe(tmp)
for i = 1,select("#", ...),2 do
local name, id = select(i, ...)
if id then
tinsert(tmp, format("|cff33cc44%s ID:|r %s", name, id))
end
end
if #tmp > 0 then
tip:AddLine(table.concat(tmp, " / "))
if tip:IsShown() then
-- force redraw
tip:Show()
end
tip._alltheid = true
end
end
function addon:HookTipScript(...)
GameTooltip:HookScript(...)
ItemRefTooltip:HookScript(...)
end
function addon:HookTip(method, hookfunc)
hooksecurefunc(GameTooltip, method, function(self, ...) hookfunc(GameTooltip, ...) end)
hooksecurefunc(ItemRefTooltip, method, function(self, ...) hookfunc(ItemRefTooltip, ...) end)
end
addon:HookTipScript("OnTooltipCleared", function(self)
self._alltheid = nil
end)
## Interface: 50100
## Title: AllTheIDs
AllTheIDs.lua
GameTooltip.lua
PetJournal.lua
local function AddIDLine(tip, name, id)
if id and not tip._alltheid then
tip._alltheid = name
tip:AddLine(format("|cff33cc44%s ID:|r %s", name, id))
if tip:IsShown() then
-- force redraw
tip:Show()
end
end
end
local function HookTipScript(...)
GameTooltip:HookScript(...)
ItemRefTooltip:HookScript(...)
end
local function HookTip(method, hookfunc)
hooksecurefunc(GameTooltip, method, function(self, ...) hookfunc(GameTooltip, ...) end)
hooksecurefunc(ItemRefTooltip, method, function(self, ...) hookfunc(ItemRefTooltip, ...) end)
end
--
--
--
HookTipScript("OnTooltipCleared", function(self)
self._alltheid = nil
end)
local addon_name, addon = ...
HookTipScript("OnTooltipSetItem", function(self)
addon:HookTipScript("OnTooltipSetItem", function(self)
local name, link = self:GetItem()
if link then
local _,_,id = strfind(link, "|Hitem:(%d+):")
AddIDLine(self, "Item", id)
addon:AddIDLine(self, "Item", id)
end
end)
HookTipScript("OnTooltipSetSpell", function(self)
addon:HookTipScript("OnTooltipSetSpell", function(self)
local name, rank, spellID = self:GetSpell()
AddIDLine(self, "Spell", spellID)
addon:AddIDLine(self, "Spell", spellID)
end)
HookTipScript("OnTooltipSetUnit", function(self)
addon:HookTipScript("OnTooltipSetUnit", function(self)
local name, unit = self:GetUnit()
if not unit then
return
......@@ -52,10 +24,10 @@ HookTipScript("OnTooltipSetUnit", function(self)
local utype = strsub(guid, 5, 5)
if utype == "1" then
-- world object
AddIDLine(self, "Object", tonumber(strsub(guid, 6, 12), 16))
addon:AddIDLine(self, "Object", tonumber(strsub(guid, 6, 12), 16))
elseif utype == "3" or utype == "5" then
-- npc/pet/vehicle
AddIDLine(self, "NPC", tonumber(strsub(guid, 6, 10), 16))
addon:AddIDLine(self, "NPC", tonumber(strsub(guid, 6, 10), 16))
end
end)
......@@ -63,69 +35,69 @@ end)
--
--
HookTip("SetAchievementByID", function(self, id)
AddIDLine(self, "Achievement", id)
addon:HookTip("SetAchievementByID", function(self, id)
addon:AddIDLine(self, "Achievement", id)
end)
HookTip("SetCurrencyByID", function(self, id)
AddIDLine(self, "Currency", id)
addon:HookTip("SetCurrencyByID", function(self, id)
addon:AddIDLine(self, "Currency", id)
end)
HookTip("SetCurrencyToken", function(self, idx)
addon:HookTip("SetCurrencyToken", function(self, idx)
-- TODO There doesn't seem to be a reasonable way to get this
end)
HookTip("SetGlyph", function(self, socket, talent)
addon:HookTip("SetGlyph", function(self, socket, talent)
local link = GetGlyphLink(socket, talent)
local _,_, id = strfind(link, "|Hglyph:(%d+)|")
AddIDLine(self, "Glyph", id)
addon:AddIDLine(self, "Glyph", id)
end)
HookTip("SetGlyphByID", function(self, id)
AddIDLine(self, "Glyph", id)
addon:HookTip("SetGlyphByID", function(self, id)
addon:AddIDLine(self, "Glyph", id)
end)
HookTip("SetHyperlink", function(self, link)
addon:HookTip("SetHyperlink", function(self, link)
local _, _, name, id = strfind(link, "(%w+):(%d+)")
AddIDLine(self, name:gsub("^%l", string.upper), id)
addon:AddIDLine(self, name:gsub("^%l", string.upper), id)
end)
HookTip("SetLFGCompletionReward", function(self)
addon:HookTip("SetLFGCompletionReward", function(self)
-- TODO item is handled, currency is not
end)
HookTip("SetLFGDungeonReward", function(self)
addon:HookTip("SetLFGDungeonReward", function(self)
-- TODO item is handled, currency is not
end)
HookTip("SetLootCurrency", function(self, slot)
addon:HookTip("SetLootCurrency", function(self, slot)
-- TODO don't know how to get currency info
end)
HookTip("SetMerchantCostItem", function(self, idx, currency)
addon:HookTip("SetMerchantCostItem", function(self, idx, currency)
local currencyID = select(currency, GetMerchantCurrencies())
AddIDLine(self, "Currency", currencyID)
addon:AddIDLine(self, "Currency", currencyID)
end)
HookTip("SetQuestCurrency", function(self, type, idx)
addon:HookTip("SetQuestCurrency", function(self, type, idx)
-- TODO GetQuestCurrencyInfo(type, idx) => name, texture, count
end)
HookTip("SetQuestLogCurrency", function(self, type, idx)
addon:HookTip("SetQuestLogCurrency", function(self, type, idx)
-- TODO GetQuestCurrencyInfo(type, idx) => name, texture, count
end)
HookTip("SetUnitAura", function(self, unit, index, filter)
addon:HookTip("SetUnitAura", function(self, unit, index, filter)
local _,_,_,_,_,_,_,_,_,_, spellID = UnitAura(unit, index, filter)
AddIDLine(self, "Spell", spellID)
addon:AddIDLine(self, "Spell", spellID)
end)
HookTip("SetUnitBuff", function(self, unit, index, filter)
addon:HookTip("SetUnitBuff", function(self, unit, index, filter)
local _,_,_,_,_,_,_,_,_,_, spellID = UnitBuff(unit, index, filter)
AddIDLine(self, "Spell", spellID)
addon:AddIDLine(self, "Spell", spellID)
end)
HookTip("SetUnitDebuff", function(self, unit, index, filter)
addon:HookTip("SetUnitDebuff", function(self, unit, index, filter)
local _,_,_,_,_,_,_,_,_,_, spellID = UnitDebuff(unit, index, filter)
AddIDLine(self, "Spell", spellID)
addon:AddIDLine(self, "Spell", spellID)
end)
local addon_name, addon = ...
local function HookPetCard()
PetJournalPetCardPetInfo:HookScript("OnEnter", function(self)
if GameTooltip:GetOwner() == self then
local speciesID = PetJournalPetCard.speciesID
local _, _, _, creatureID = C_PetJournal.GetPetInfoBySpeciesID(speciesID)
addon:AddIDLine(GameTooltip, "Species", speciesID, "NPC", creatureID)
end
end)
end
--
-- hook on addon load
--
if IsAddOnLoaded("Blizzard_PetJournal") then
HookPetCard()
else
local frame = CreateFrame("FRAME")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, addon_name)
if addon_name == "Blizzard_PetJournal" then
HookPetCard()
self:UnregisterEvent("ADDON_LOADED")
end
end)
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment