fix error when using aux

This commit is contained in:
Spit
2025-09-02 10:27:26 +03:00
parent be2f6837c8
commit b2d6cf0aa7
+284 -288
View File
@@ -8,359 +8,355 @@ local insideHook = false
local tooltipMoney = 0 local tooltipMoney = 0
local original_SetTooltipMoney = SetTooltipMoney local original_SetTooltipMoney = SetTooltipMoney
function SetTooltipMoney(frame, money) function SetTooltipMoney(frame, money)
if insideHook then if insideHook then
tooltipMoney = money or 0 tooltipMoney = money or 0
else else
original_SetTooltipMoney(frame, money) original_SetTooltipMoney(frame, money)
end end
end end
local WrappingLines = { local WrappingLines = {
["^Set:"] = gsub("^"..ITEM_SET_BONUS, "%%s", ""), ["^Set:"] = gsub("^"..ITEM_SET_BONUS, "%%s", ""),
["^%(%d%) Set:"] = gsub(gsub(ITEM_SET_BONUS_GRAY, "%(%%d%)", "^%%(%%d%%)"), "%%s", ""), ["^%(%d%) Set:"] = gsub(gsub(ITEM_SET_BONUS_GRAY, "%(%%d%)", "^%%(%%d%%)"), "%%s", ""),
["^Effect:"] = gsub("^"..ITEM_SPELL_EFFECT, "%%s", ""), ["^Effect:"] = gsub("^"..ITEM_SPELL_EFFECT, "%%s", ""),
["^Equip:"] = "^"..ITEM_SPELL_TRIGGER_ONEQUIP, ["^Equip:"] = "^"..ITEM_SPELL_TRIGGER_ONEQUIP,
["^Chance on hit:"] = "^"..ITEM_SPELL_TRIGGER_ONPROC, ["^Chance on hit:"] = "^"..ITEM_SPELL_TRIGGER_ONPROC,
["^Use:"] = "^"..ITEM_SPELL_TRIGGER_ONUSE, ["^Use:"] = "^"..ITEM_SPELL_TRIGGER_ONUSE,
["^\nRequires"] = "^\n"..gsub(ITEM_REQ_SKILL, "%%s", "") ["^\nRequires"] = "^\n"..gsub(ITEM_REQ_SKILL, "%%s", "")
} }
local lines = {} local lines = {}
for i = 1, 30 do for i = 1, 30 do
lines[i] = {} lines[i] = {}
end end
local function AddSourceLine(tooltip, sourceStr) local function AddSourceLine(tooltip, sourceStr)
local name = tooltip:GetName() local name = tooltip:GetName()
local numLines = tooltip:NumLines() local numLines = tooltip:NumLines()
local left, right local left, right
local leftText, rightText local leftText, rightText
local leftR, leftG, leftB local leftR, leftG, leftB
local rightR, rightG, rightB local rightR, rightG, rightB
local wrap local wrap
for i in pairs(lines) do for i in pairs(lines) do
for j in pairs(lines[i]) do for j in pairs(lines[i]) do
lines[i][j] = nil lines[i][j] = nil
end end
end end
for i = 1, numLines do for i = 1, numLines do
left = getglobal(name .. "TextLeft" .. i) left = getglobal(name .. "TextLeft" .. i)
right = getglobal(name .. "TextRight" .. i) right = getglobal(name .. "TextRight" .. i)
leftText = left:GetText() leftText = left:GetText()
rightText = right:IsShown() and right:GetText() rightText = right:IsShown() and right:GetText()
leftR, leftG, leftB = left:GetTextColor() leftR, leftG, leftB = left:GetTextColor()
rightR, rightG, rightB = right:GetTextColor() rightR, rightG, rightB = right:GetTextColor()
lines[i][1] = leftText lines[i][1] = leftText
lines[i][2] = rightText lines[i][2] = rightText
lines[i][3] = leftR lines[i][3] = leftR
lines[i][4] = leftG lines[i][4] = leftG
lines[i][5] = leftB lines[i][5] = leftB
lines[i][6] = rightR lines[i][6] = rightR
lines[i][7] = rightG lines[i][7] = rightG
lines[i][8] = rightB lines[i][8] = rightB
end end
if not lines[1][1] then if not lines[1][1] then
return return
end end
tooltip:SetText(lines[1][1], lines[1][3], lines[1][4], lines[1][5], 1, false) tooltip:SetText(lines[1][1], lines[1][3], lines[1][4], lines[1][5], 1, false)
if numLines < 28 then if numLines < 28 then
tooltip:AddLine(sourceStr) tooltip:AddLine(sourceStr)
elseif lines[2][1] then elseif lines[2][1] then
lines[2][1] = sourceStr .. "\n" .. lines[2][1] lines[2][1] = sourceStr .. "\n" .. lines[2][1]
end end
for i = 2, getn(lines) do for i = 2, getn(lines) do
if lines[i][2] then if lines[i][2] then
tooltip:AddDoubleLine(lines[i][1], lines[i][2], lines[i][3], lines[i][4], lines[i][5], lines[i][6], lines[i][7], lines[i][8]) tooltip:AddDoubleLine(lines[i][1], lines[i][2], lines[i][3], lines[i][4], lines[i][5], lines[i][6], lines[i][7], lines[i][8])
else else
wrap = false wrap = false
if strsub(lines[i][1] or "", 1, 1) == "\"" then if strsub(lines[i][1] or "", 1, 1) == "\"" then
wrap = true wrap = true
else else
for _, pattern in pairs(WrappingLines) do for _, pattern in pairs(WrappingLines) do
if strfind(lines[i][1] or "", pattern) then if strfind(lines[i][1] or "", pattern) then
wrap = true wrap = true
break break
end end
end end
end end
tooltip:AddLine(lines[i][1], lines[i][3], lines[i][4], lines[i][5], wrap) tooltip:AddLine(lines[i][1], lines[i][3], lines[i][4], lines[i][5], wrap)
end end
end end
end end
local lastItemID, lastSourceStr local lastItemID, lastSourceStr
local function ExtendTooltip(tooltip) local function ExtendTooltip(tooltip)
if AtlasLootCharDB.ShowSource then if AtlasLootCharDB.ShowSource then
local itemID = tonumber(tooltip.itemID) local itemID = tonumber(tooltip.itemID)
if itemID and itemID ~= 51217 then -- 51217 Fashion Coin if itemID and itemID ~= 51217 then -- 51217 Fashion Coin
if itemID ~= lastItemID then if itemID ~= lastItemID then
lastItemID = itemID lastItemID = itemID
lastSourceStr = nil lastSourceStr = nil
local source = AtlasLoot_Data["AtlasLootSources"][itemID] local source = AtlasLoot_Data["AtlasLootSources"][itemID]
if source then if source then
local str = GREY .. source .. "|r" local str = GREY .. source .. "|r"
lastSourceStr = str lastSourceStr = str
end end
end end
if lastSourceStr then if lastSourceStr then
AddSourceLine(tooltip, lastSourceStr) AddSourceLine(tooltip, lastSourceStr)
tooltip:Show() tooltip:Show()
end end
end end
end end
if tooltipMoney > 0 then if tooltipMoney > 0 then
original_SetTooltipMoney(tooltip, tooltipMoney) original_SetTooltipMoney(tooltip, tooltipMoney)
tooltip:Show() tooltip:Show()
end end
end end
local lastSearchName local lastSearchName
local lastSearchID 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 name ~= lastSearchName then
for itemID = 1, 99999 do for itemID = 1, 99999 do
local itemName = GetItemInfo(itemID) local itemName = GetItemInfo(itemID)
if itemName and itemName == name then if itemName and itemName == name then
lastSearchID = itemID lastSearchID = itemID
break break
end end
end end
lastSearchName = name lastSearchName = name
end end
return lastSearchID return lastSearchID
end end
local function HookTooltip(tooltip) local function HookTooltip(tooltip)
local original_SetLootRollItem = tooltip.SetLootRollItem local original_SetLootRollItem = tooltip.SetLootRollItem
local original_SetLootItem = tooltip.SetLootItem local original_SetLootItem = tooltip.SetLootItem
local original_SetMerchantItem = tooltip.SetMerchantItem local original_SetMerchantItem = tooltip.SetMerchantItem
local original_SetQuestLogItem = tooltip.SetQuestLogItem local original_SetQuestLogItem = tooltip.SetQuestLogItem
local original_SetQuestItem = tooltip.SetQuestItem local original_SetQuestItem = tooltip.SetQuestItem
local original_SetHyperlink = tooltip.SetHyperlink local original_SetHyperlink = tooltip.SetHyperlink
local original_SetBagItem = tooltip.SetBagItem local original_SetBagItem = tooltip.SetBagItem
local original_SetInboxItem = tooltip.SetInboxItem local original_SetInboxItem = tooltip.SetInboxItem
local original_SetInventoryItem = tooltip.SetInventoryItem local original_SetInventoryItem = tooltip.SetInventoryItem
local original_SetCraftItem = tooltip.SetCraftItem local original_SetCraftItem = tooltip.SetCraftItem
local original_SetCraftSpell = tooltip.SetCraftSpell local original_SetCraftSpell = tooltip.SetCraftSpell
local original_SetTradeSkillItem = tooltip.SetTradeSkillItem local original_SetTradeSkillItem = tooltip.SetTradeSkillItem
local original_SetAuctionItem = tooltip.SetAuctionItem local original_SetAuctionItem = tooltip.SetAuctionItem
local original_SetAuctionSellItem = tooltip.SetAuctionSellItem local original_SetAuctionSellItem = tooltip.SetAuctionSellItem
local original_SetTradePlayerItem = tooltip.SetTradePlayerItem local original_SetTradePlayerItem = tooltip.SetTradePlayerItem
local original_SetTradeTargetItem = tooltip.SetTradeTargetItem local original_SetTradeTargetItem = tooltip.SetTradeTargetItem
local original_OnHide = tooltip:GetScript("OnHide") local original_OnHide = tooltip:GetScript("OnHide")
tooltip:SetScript("OnHide", function() tooltip:SetScript("OnHide", function()
if original_OnHide then original_OnHide() end if original_OnHide then original_OnHide() end
this.itemID = nil this.itemID = nil
tooltipMoney = 0 tooltipMoney = 0
end) end)
function tooltip.SetLootRollItem(self, rollID) function tooltip.SetLootRollItem(self, rollID)
insideHook = true insideHook = true
original_SetLootRollItem(self, rollID) original_SetLootRollItem(self, rollID)
insideHook = false insideHook = false
local _, _, id = strfind(GetLootRollItemLink(rollID) or "", "item:(%d+)") local _, _, id = strfind(GetLootRollItemLink(rollID) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetLootItem(self, slot) function tooltip.SetLootItem(self, slot)
insideHook = true insideHook = true
original_SetLootItem(self, slot) original_SetLootItem(self, slot)
insideHook = false insideHook = false
local _, _, id = strfind(GetLootSlotLink(slot) or "", "item:(%d+)") local _, _, id = strfind(GetLootSlotLink(slot) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetMerchantItem(self, merchantIndex) function tooltip.SetMerchantItem(self, merchantIndex)
insideHook = true insideHook = true
original_SetMerchantItem(self, merchantIndex) original_SetMerchantItem(self, merchantIndex)
insideHook = false insideHook = false
local _, _, id = strfind(GetMerchantItemLink(merchantIndex) or "", "item:(%d+)") local _, _, id = strfind(GetMerchantItemLink(merchantIndex) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetQuestLogItem(self, itemType, index) function tooltip.SetQuestLogItem(self, itemType, index)
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+)") local _, _, id = strfind(GetQuestLogItemLink(itemType, index) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetQuestItem(self, itemType, index) function tooltip.SetQuestItem(self, itemType, index)
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+)") local _, _, id = strfind(GetQuestItemLink(itemType, index) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetHyperlink(self, arg1) function tooltip.SetHyperlink(self, arg1)
insideHook = true insideHook = true
original_SetHyperlink(self, arg1) original_SetHyperlink(self, arg1)
insideHook = false insideHook = false
local _, _, id = strfind(arg1 or "", "item:(%d+)") local _, _, id = strfind(arg1 or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetBagItem(self, container, slot) function tooltip.SetBagItem(self, container, slot)
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+)") local _, _, id = strfind(GetContainerItemLink(container, slot) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
return hasCooldown, repairCost return hasCooldown, repairCost
end end
function tooltip.SetInboxItem(self, mailID, attachmentIndex) function tooltip.SetInboxItem(self, mailID, attachmentIndex)
insideHook = true insideHook = true
original_SetInboxItem(self, mailID, attachmentIndex) original_SetInboxItem(self, mailID, attachmentIndex)
insideHook = false insideHook = false
local itemName = GetInboxItem(mailID) local itemName = GetInboxItem(mailID)
self.itemID = GetItemIDByName(itemName) self.itemID = GetItemIDByName(itemName)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetInventoryItem(self, unit, slot) function tooltip.SetInventoryItem(self, unit, slot)
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+)") local _, _, id = strfind(GetInventoryItemLink(unit, slot) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
return hasItem, hasCooldown, repairCost return hasItem, hasCooldown, repairCost
end end
function tooltip.SetCraftItem(self, skill, slot) function tooltip.SetCraftItem(self, skill, slot)
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+)") local _, _, id = strfind(GetCraftReagentItemLink(skill, slot) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetCraftSpell(self, slot) function tooltip.SetCraftSpell(self, slot)
insideHook = true insideHook = true
original_SetCraftSpell(self, slot) original_SetCraftSpell(self, slot)
insideHook = false insideHook = false
local _, _, id = strfind(GetCraftItemLink(slot) or "", "item:(%d+)") local _, _, id = strfind(GetCraftItemLink(slot) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetTradeSkillItem(self, skillIndex, reagentIndex) function tooltip.SetTradeSkillItem(self, skillIndex, reagentIndex)
insideHook = true insideHook = true
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+)") local _, _, id = strfind(GetTradeSkillReagentItemLink(skillIndex, reagentIndex) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
else else
local _, _, id = strfind(GetTradeSkillItemLink(skillIndex) or "", "item:(%d+)") local _, _, id = strfind(GetTradeSkillItemLink(skillIndex) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
end end
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetAuctionItem(self, atype, index) function tooltip.SetAuctionItem(self, atype, index)
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+)") local _, _, id = strfind(GetAuctionItemLink(atype, index) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetAuctionSellItem(self) function tooltip.SetAuctionSellItem(self)
insideHook = true insideHook = true
original_SetAuctionSellItem(self) original_SetAuctionSellItem(self)
insideHook = false insideHook = false
self.itemID = tonumber(GetItemIDByName(GetAuctionSellItemInfo())) self.itemID = tonumber(GetItemIDByName(GetAuctionSellItemInfo()))
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetTradePlayerItem(self, index) function tooltip.SetTradePlayerItem(self, index)
insideHook = true insideHook = true
original_SetTradePlayerItem(self, index) original_SetTradePlayerItem(self, index)
insideHook = false insideHook = false
local _, _, id = strfind(GetTradePlayerItemLink(index) or "", "item:(%d+)") local _, _, id = strfind(GetTradePlayerItemLink(index) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
function tooltip.SetTradeTargetItem(self, index) function tooltip.SetTradeTargetItem(self, index)
insideHook = true insideHook = true
original_SetTradeTargetItem(self, index) original_SetTradeTargetItem(self, index)
insideHook = false insideHook = false
local _, _, id = strfind(GetTradeTargetItemLink(index) or "", "item:(%d+)") local _, _, id = strfind(GetTradeTargetItemLink(index) or "", "item:(%d+)")
self.itemID = tonumber(id) self.itemID = tonumber(id)
ExtendTooltip(self) ExtendTooltip(self)
end end
end end
local original_SetItemRef = SetItemRef local original_SetItemRef = SetItemRef
function SetItemRef(link, text, button) function SetItemRef(link, text, button)
local item, _, id = string.find(link, "item:(%d+)") local item, _, id = string.find(link, "item:(%d+)")
ItemRefTooltip.itemID = id ItemRefTooltip.itemID = id
original_SetItemRef(link, text, button) original_SetItemRef(link, text, button)
if not IsShiftKeyDown() and not IsControlKeyDown() and item then if not IsShiftKeyDown() and not IsControlKeyDown() and item then
ExtendTooltip(ItemRefTooltip) ExtendTooltip(ItemRefTooltip)
end end
end end
local original_OnHide = ItemRefTooltip:GetScript("OnHide") local original_OnHide = ItemRefTooltip:GetScript("OnHide")
ItemRefTooltip:SetScript("OnHide", function() ItemRefTooltip:SetScript("OnHide", function()
original_OnHide() original_OnHide()
ItemRefTooltip.itemID = nil ItemRefTooltip.itemID = nil
end) end)
AtlasLootTip:SetScript("OnShow", function() AtlasLootTip:SetScript("OnShow", function()
if aux_frame and aux_frame:IsVisible() then if aux_frame and aux_frame:IsShown() then
if GetMouseFocus():GetParent() then if GetMouseFocus() and GetMouseFocus():GetParent() and GetMouseFocus():GetParent().row and GetMouseFocus():GetParent().row.record then
if GetMouseFocus():GetParent().row then GameTooltip.itemID = GetMouseFocus():GetParent().row.record.item_id
if GetMouseFocus():GetParent().row.record.item_id then ExtendTooltip(GameTooltip)
GameTooltip.itemID = GetMouseFocus():GetParent().row.record.item_id end
ExtendTooltip(GameTooltip) end
end
end
end
end
end) end)
-- adapted from http://shagu.org/ShaguTweaks/ -- adapted from http://shagu.org/ShaguTweaks/
AtlasLootTip.HookAddonOrVariable = function(addon, func) AtlasLootTip.HookAddonOrVariable = function(addon, func)
local lurker = CreateFrame("Frame", nil) local lurker = CreateFrame("Frame", nil)
lurker.func = func lurker.func = func
lurker:RegisterEvent("ADDON_LOADED") lurker:RegisterEvent("ADDON_LOADED")
lurker:RegisterEvent("VARIABLES_LOADED") lurker:RegisterEvent("VARIABLES_LOADED")
lurker:RegisterEvent("PLAYER_ENTERING_WORLD") lurker:RegisterEvent("PLAYER_ENTERING_WORLD")
lurker:SetScript("OnEvent", function() lurker:SetScript("OnEvent", function()
if IsAddOnLoaded(addon) or getglobal(addon) then if IsAddOnLoaded(addon) or getglobal(addon) then
this:func() this:func()
this:UnregisterAllEvents() this:UnregisterAllEvents()
end end
end) end)
end end
AtlasLootTip.HookAddonOrVariable("Tmog", function() AtlasLootTip.HookAddonOrVariable("Tmog", function()
HookTooltip(TmogTooltip) HookTooltip(TmogTooltip)
end) end)
HookTooltip(GameTooltip) HookTooltip(GameTooltip)