refactor tooltip.lua
This commit is contained in:
+35
-62
@@ -121,22 +121,25 @@ local function ExtendTooltip(tooltip)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local lastSearchName
|
local IDCache = {}
|
||||||
local lastSearchID
|
|
||||||
|
|
||||||
local function GetItemIDByName(name)
|
local function GetItemIDByName(name)
|
||||||
if not name then return nil end
|
if not name then return nil end
|
||||||
if name ~= lastSearchName then
|
if IDCache[name] then return IDCache[name] ~= 0 and IDCache[name] or nil end
|
||||||
for itemID = 1, 99999 do
|
for itemID = 1, 99999 do
|
||||||
local itemName = GetItemInfo(itemID)
|
if GetItemInfo(itemID) == name then
|
||||||
if itemName and itemName == name then
|
IDCache[name] = itemID
|
||||||
lastSearchID = itemID
|
return itemID
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
lastSearchName = name
|
IDCache[name] = 0
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
return lastSearchID
|
|
||||||
|
local function IDFromLink(link)
|
||||||
|
if not link then return nil end
|
||||||
|
local _, _, id = strfind(link, "item:(%d+)")
|
||||||
|
return tonumber(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function HookTooltip(tooltip)
|
local function HookTooltip(tooltip)
|
||||||
@@ -169,8 +172,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetLootRollItem(self, rollID)
|
original_SetLootRollItem(self, rollID)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetLootRollItemLink(rollID) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetLootRollItemLink(rollID))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -178,8 +180,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetLootItem(self, slot)
|
original_SetLootItem(self, slot)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetLootSlotLink(slot) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetLootSlotLink(slot))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -187,8 +188,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetMerchantItem(self, merchantIndex)
|
original_SetMerchantItem(self, merchantIndex)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetMerchantItemLink(merchantIndex) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetMerchantItemLink(merchantIndex))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -196,8 +196,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetQuestLogItem(self, itemType, index)
|
original_SetQuestLogItem(self, itemType, index)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetQuestLogItemLink(itemType, index) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetQuestLogItemLink(itemType, index))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -205,8 +204,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetQuestItem(self, itemType, index)
|
original_SetQuestItem(self, itemType, index)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetQuestItemLink(itemType, index) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetQuestItemLink(itemType, index))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -214,8 +212,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetHyperlink(self, arg1)
|
original_SetHyperlink(self, arg1)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(arg1 or "", "item:(%d+)")
|
self.itemID = IDFromLink(arg1)
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -223,8 +220,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
local hasCooldown, repairCost = original_SetBagItem(self, container, slot)
|
local hasCooldown, repairCost = original_SetBagItem(self, container, slot)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetContainerItemLink(container, slot) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetContainerItemLink(container, slot))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
return hasCooldown, repairCost
|
return hasCooldown, repairCost
|
||||||
end
|
end
|
||||||
@@ -233,8 +229,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetInboxItem(self, mailID, attachmentIndex)
|
original_SetInboxItem(self, mailID, attachmentIndex)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local itemName = GetInboxItem(mailID)
|
self.itemID = GetItemIDByName(GetInboxItem(mailID))
|
||||||
self.itemID = GetItemIDByName(itemName)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -242,8 +237,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
local hasItem, hasCooldown, repairCost = original_SetInventoryItem(self, unit, slot)
|
local hasItem, hasCooldown, repairCost = original_SetInventoryItem(self, unit, slot)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetInventoryItemLink(unit, slot) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetInventoryItemLink(unit, slot))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
return hasItem, hasCooldown, repairCost
|
return hasItem, hasCooldown, repairCost
|
||||||
end
|
end
|
||||||
@@ -252,8 +246,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetCraftItem(self, skill, slot)
|
original_SetCraftItem(self, skill, slot)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetCraftReagentItemLink(skill, slot) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetCraftReagentItemLink(skill, slot))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -261,8 +254,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetCraftSpell(self, slot)
|
original_SetCraftSpell(self, slot)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetCraftItemLink(slot) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetCraftItemLink(slot))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -271,11 +263,9 @@ local function HookTooltip(tooltip)
|
|||||||
original_SetTradeSkillItem(self, skillIndex, reagentIndex)
|
original_SetTradeSkillItem(self, skillIndex, reagentIndex)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
if reagentIndex then
|
if reagentIndex then
|
||||||
local _, _, id = strfind(GetTradeSkillReagentItemLink(skillIndex, reagentIndex) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetTradeSkillReagentItemLink(skillIndex, reagentIndex))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
else
|
else
|
||||||
local _, _, id = strfind(GetTradeSkillItemLink(skillIndex) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetTradeSkillItemLink(skillIndex))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
end
|
end
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
@@ -284,8 +274,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetAuctionItem(self, atype, index)
|
original_SetAuctionItem(self, atype, index)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetAuctionItemLink(atype, index) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetAuctionItemLink(atype, index))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -301,8 +290,7 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetTradePlayerItem(self, index)
|
original_SetTradePlayerItem(self, index)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetTradePlayerItemLink(index) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetTradePlayerItemLink(index))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -310,35 +298,19 @@ local function HookTooltip(tooltip)
|
|||||||
insideHook = true
|
insideHook = true
|
||||||
original_SetTradeTargetItem(self, index)
|
original_SetTradeTargetItem(self, index)
|
||||||
insideHook = false
|
insideHook = false
|
||||||
local _, _, id = strfind(GetTradeTargetItemLink(index) or "", "item:(%d+)")
|
self.itemID = IDFromLink(GetTradeTargetItemLink(index))
|
||||||
self.itemID = tonumber(id)
|
|
||||||
ExtendTooltip(self)
|
ExtendTooltip(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local original_SetItemRef = SetItemRef
|
|
||||||
function SetItemRef(link, text, button)
|
|
||||||
local item, _, id = string.find(link, "item:(%d+)")
|
|
||||||
ItemRefTooltip.itemID = id
|
|
||||||
original_SetItemRef(link, text, button)
|
|
||||||
if not IsShiftKeyDown() and not IsControlKeyDown() and item then
|
|
||||||
ExtendTooltip(ItemRefTooltip)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local original_OnHide = ItemRefTooltip:GetScript("OnHide")
|
|
||||||
ItemRefTooltip:SetScript("OnHide", function()
|
|
||||||
original_OnHide()
|
|
||||||
ItemRefTooltip.itemID = nil
|
|
||||||
end)
|
|
||||||
|
|
||||||
AtlasLootTip:SetScript("OnShow", function()
|
AtlasLootTip:SetScript("OnShow", function()
|
||||||
if aux_frame and aux_frame:IsShown() then
|
if not (aux_frame and aux_frame:IsShown()) then return end
|
||||||
if GetMouseFocus() and GetMouseFocus():GetParent() and GetMouseFocus():GetParent().row and GetMouseFocus():GetParent().row.record then
|
local focus = GetMouseFocus()
|
||||||
GameTooltip.itemID = GetMouseFocus():GetParent().row.record.item_id
|
if not focus then return end
|
||||||
|
local parent = focus:GetParent()
|
||||||
|
if not (parent and parent.row and parent.row.record) then return end
|
||||||
|
GameTooltip.itemID = tonumber(parent.row.record.item_id)
|
||||||
ExtendTooltip(GameTooltip)
|
ExtendTooltip(GameTooltip)
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- adapted from http://shagu.org/ShaguTweaks/
|
-- adapted from http://shagu.org/ShaguTweaks/
|
||||||
@@ -361,3 +333,4 @@ AtlasLootTip.HookAddonOrVariable("Tmog", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
HookTooltip(GameTooltip)
|
HookTooltip(GameTooltip)
|
||||||
|
HookTooltip(ItemRefTooltip)
|
||||||
|
|||||||
Reference in New Issue
Block a user