tooltip cleanup

This commit is contained in:
Spit
2025-04-29 14:56:17 +03:00
parent 9b628213f6
commit 645433024f
+265 -268
View File
@@ -6,12 +6,12 @@ local GetItemInfo = GetItemInfo
local GREY = "|cff999999" local GREY = "|cff999999"
local WrappingLines = { local WrappingLines = {
["Set: %s"] = gsub("^"..ITEM_SET_BONUS, " %%s", ""), ["Set: %s"] = gsub("^" .. ITEM_SET_BONUS, " %%s", ""), -- "^Set:"
["(%d) Set: %s"] = gsub(gsub(ITEM_SET_BONUS_GRAY, "%(%%d%)", "^%%(%%d%%)"), " %%s", ""), ["(%d) Set: %s"] = gsub(gsub(ITEM_SET_BONUS_GRAY, "%(%%d%)", "^%%(%%d%%)"), " %%s", ""), -- "^%(%d%) Set:"
["Effect: %s"] = gsub("^"..ITEM_SPELL_EFFECT, " %%s", ""), ["Effect: %s"] = gsub("^" .. ITEM_SPELL_EFFECT, " %%s", ""), -- "^Effect:"
["Equip:"] = "^"..ITEM_SPELL_TRIGGER_ONEQUIP, ["Equip:"] = "^" .. ITEM_SPELL_TRIGGER_ONEQUIP, -- "^Equip:"
["Chance on hit:"] = "^"..ITEM_SPELL_TRIGGER_ONPROC, ["Chance on hit:"] = "^" .. ITEM_SPELL_TRIGGER_ONPROC, -- "^Chance on hit:"
["Use:"] = "^"..ITEM_SPELL_TRIGGER_ONUSE, ["Use:"] = "^" .. ITEM_SPELL_TRIGGER_ONUSE, -- "^Use:"
} }
local lines = {} local lines = {}
@@ -24,8 +24,8 @@ local function AddSourceLine(tooltip, sourceStr)
local numLines = tooltip:NumLines() local numLines = tooltip:NumLines()
local left, right local left, right
local leftText, rightText local leftText, rightText
local rL, gL, bL local leftR, leftG, leftB
local rR, gR, bR local rightR, rightG, rightB
local wrap local wrap
for i in pairs(lines) do for i in pairs(lines) do
@@ -39,26 +39,28 @@ local function AddSourceLine(tooltip, sourceStr)
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()
rL, gL, bL = left:GetTextColor() leftR, leftG, leftB = left:GetTextColor()
rR, gR, bR = 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] = rL lines[i][3] = leftR
lines[i][4] = gL lines[i][4] = leftG
lines[i][5] = bL lines[i][5] = leftB
lines[i][6] = rR lines[i][6] = rightR
lines[i][7] = gR lines[i][7] = rightG
lines[i][8] = bR lines[i][8] = rightB
end
if not lines[1][1] then
return
end end
if not lines[1][1] then return 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
@@ -83,7 +85,7 @@ local function AddSourceLine(tooltip, sourceStr)
tooltip:Show() tooltip:Show()
end end
local sets = { local Sets = {
["SpiritofEskhandar"] = true, ["SpiritofEskhandar"] = true,
["HakkariBlades"] = true, ["HakkariBlades"] = true,
["PrimalBlessing"] = true, ["PrimalBlessing"] = true,
@@ -97,7 +99,7 @@ local sets = {
["Tabards"] = true, ["Tabards"] = true,
} }
local professions = { local Professions = {
["Apprentice"] = true, ["Apprentice"] = true,
["Journeyman"] = true, ["Journeyman"] = true,
["Expert"] = true, ["Expert"] = true,
@@ -132,271 +134,266 @@ local function SetPartialMatch(set, str)
end end
local function SetContains(set, key) local function SetContains(set, key)
if not set or not key then if not set or not key then
return false return false
end end
return set[key] ~= nil return set[key] ~= nil
end end
local lastItemID, lastSourceStr, lastDropRate local lastItemID, lastSourceStr, lastDropRate
local function ExtendTooltip(tooltip) local function ExtendTooltip(tooltip)
if not AtlasLootCharDB.ShowSource then if not AtlasLootCharDB.ShowSource then
return return
end end
local tooltipName = tooltip:GetName() local tooltipName = tooltip:GetName()
local line2 = getglobal(tooltipName .. "TextLeft2") local craftSpell, source, sourceStr, dropRate
local craftSpell, source, sourceStr, dropRate local isCraft, isWBLoot, isPvP, isRepReward, isSetPiece, isWorldEvent = false, false, false, false, false, false
local isCraft, isWBLoot, isPvP, isRepReward, isSetPiece, isWorldEvent = false, false, false, false, false, false 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 for row = 1, tooltip:NumLines() do
for row = 1, tooltip:NumLines() do local rowtext = getglobal(tooltipName .. "TextLeft" .. row):GetText()
local rowtext = getglobal(tooltipName.."TextLeft"..row):GetText()
-- skip items that state which rep they require -- skip items that state which rep they require
if strfind(rowtext or "", "", 1, true) then if strfind(rowtext or "", "", 1, true) then
return return
end end
end end
-- first check if its craftable item -- first check if its craftable item
for k,v in pairs(GetSpellInfoAtlasLootDB["craftspells"]) do for k, v in pairs(GetSpellInfoAtlasLootDB["craftspells"]) do
if v["craftItem"] == itemID then if v["craftItem"] == itemID then
craftSpell = "s"..tostring(k) craftSpell = "s" .. tostring(k)
break break
end end
end end
for k, v in pairs(GetSpellInfoAtlasLootDB["enchants"]) do for k, v in pairs(GetSpellInfoAtlasLootDB["enchants"]) do
if v["item"] and v["item"] == itemID then if v["item"] and v["item"] == itemID then
craftSpell = "e"..tostring(k) craftSpell = "e" .. tostring(k)
break break
end end
end end
for k1, v1 in pairs(AtlasLoot_Data["AtlasLootCrafting"]) do for k1, v1 in pairs(AtlasLoot_Data["AtlasLootCrafting"]) do
if source then if source then
break break
end end
for k2, v2 in pairs(AtlasLoot_Data["AtlasLootCrafting"][k1]) do for k2, v2 in pairs(AtlasLoot_Data["AtlasLootCrafting"][k1]) do
if v2[1] ~= 0 and v2[1] ~= "" then if v2[1] ~= 0 and v2[1] ~= "" then
if (v2[1] == craftSpell or v2[1] == itemID) and SetPartialMatch(professions, k1) then if (v2[1] == craftSpell or v2[1] == itemID) and SetPartialMatch(Professions, k1) then
source = k1 source = k1
isCraft = true isCraft = true
dropRate = AtlasLoot_FixText(v2[4] or "") or "" dropRate = AtlasLoot_FixText(v2[4] or "") or ""
dropRate = gsub(dropRate or "", "\124cff%x%x%x%x%x%x", "") dropRate = gsub(dropRate or "", "\124c%x%x%x%x%x%x%x%x", "")
local skill = "" local skill = ""
_, _, dropRate, skill = strfind(dropRate or "", "("..AL["Skill:"]..") (%d+)") _, _, dropRate, skill = strfind(dropRate or "", "(" .. AL["Skill:"] .. ") (%d+)")
if dropRate and skill then if dropRate and skill then
dropRate = skill ~= "300" and dropRate.." "..skill.."+" or dropRate.." "..skill dropRate = skill ~= "300" and dropRate .. " " .. skill .. "+" or dropRate .. " " .. skill
lastDropRate = dropRate lastDropRate = dropRate
else else
lastDropRate = nil lastDropRate = nil
end end
break break
end end
end end
end end
end end
-- check if its world boss loot -- check if its world boss loot
if not isCraft then if not isCraft then
for k1,v1 in pairs(AtlasLoot_Data["AtlasLootWBItems"]) do for k1, v1 in pairs(AtlasLoot_Data["AtlasLootWBItems"]) do
if source then if source then
break break
end end
for k2,v2 in pairs(AtlasLoot_Data["AtlasLootWBItems"][k1]) do for k2, v2 in pairs(AtlasLoot_Data["AtlasLootWBItems"][k1]) do
if v2[1] == itemID then if v2[1] == itemID then
source = k1 source = k1
isWBLoot = true isWBLoot = true
if v2[5] and v2[5] ~= "" then if v2[5] and v2[5] ~= "" then
dropRate = v2[5] dropRate = v2[5]
lastDropRate = dropRate lastDropRate = dropRate
else else
lastDropRate = nil lastDropRate = nil
end end
break break
end end
end end
end end
end end
-- check if its a pvp reward -- check if its a pvp reward
if not isCraft and not isWBLoot then if not isCraft and not isWBLoot then
for k1,v1 in pairs(AtlasLoot_Data["AtlasLootGeneralPvPItems"]) do for k1, v1 in pairs(AtlasLoot_Data["AtlasLootGeneralPvPItems"]) do
if source then if source then
break break
end end
for k2,v2 in pairs(AtlasLoot_Data["AtlasLootGeneralPvPItems"][k1]) do for k2, v2 in pairs(AtlasLoot_Data["AtlasLootGeneralPvPItems"][k1]) do
if v2[1] == itemID then if v2[1] == itemID then
source = k1 source = k1
isPvP = true isPvP = true
lastDropRate = nil lastDropRate = nil
break break
end end
end end
end end
end end
-- check if its a rep reward -- check if its a rep reward
-- bgs -- bgs
if not isCraft and not isWBLoot and not isPvP then if not isCraft and not isWBLoot and not isPvP then
for k1,v1 in pairs(AtlasLoot_Data["AtlasLootBGItems"]) do for k1, v1 in pairs(AtlasLoot_Data["AtlasLootBGItems"]) do
if source then if source then
break break
end end
for k2,v2 in pairs(AtlasLoot_Data["AtlasLootBGItems"][k1]) do for k2, v2 in pairs(AtlasLoot_Data["AtlasLootBGItems"][k1]) do
if v2[1] == itemID then if v2[1] == itemID then
source = k1 source = k1
isRepReward = true isRepReward = true
if v2[5] and v2[5] ~= "" then if v2[5] and v2[5] ~= "" then
dropRate = v2[5] dropRate = v2[5]
lastDropRate = dropRate lastDropRate = dropRate
else else
lastDropRate = nil lastDropRate = nil
end end
break break
end end
end end
end end
-- factions -- factions
for k1,v1 in pairs(AtlasLoot_Data["AtlasLootRepItems"]) do for k1, v1 in pairs(AtlasLoot_Data["AtlasLootRepItems"]) do
if source then if source then
break break
end end
for k2,v2 in pairs(AtlasLoot_Data["AtlasLootRepItems"][k1]) do for k2, v2 in pairs(AtlasLoot_Data["AtlasLootRepItems"][k1]) do
if v2[1] == itemID then if v2[1] == itemID then
source = k1 source = k1
isRepReward = true isRepReward = true
if v2[5] and v2[5] ~= "" --[[and source ~= "Darkmoon" and not strfind(source, "Cenarion",1,true)]] then if v2[5] and v2[5] ~= "" then
dropRate = v2[5] dropRate = v2[5]
lastDropRate = dropRate lastDropRate = dropRate
else else
lastDropRate = nil lastDropRate = nil
end end
break break
end end
end end
end end
end end
-- check if its a set piece -- check if its a set piece
if not isCraft and not isWBLoot and not isPvP and not isRepReward then if not isCraft and not isWBLoot and not isPvP and not isRepReward then
for k1,v1 in pairs(AtlasLoot_Data["AtlasLootSetItems"]) do for k1, v1 in pairs(AtlasLoot_Data["AtlasLootSetItems"]) do
if source then if source then
break break
end end
for k2,v2 in pairs(AtlasLoot_Data["AtlasLootSetItems"][k1]) do for k2, v2 in pairs(AtlasLoot_Data["AtlasLootSetItems"][k1]) do
if v2[1] == itemID then if v2[1] == itemID then
source = k1 source = k1
isSetPiece = true isSetPiece = true
if (SetContains(sets, source) or strfind(source, "WorldEpics",1,true)) then if (SetContains(Sets, source) or strfind(source, "WorldEpics", 1, true)) then
source = nil source = nil
isSetPiece = false isSetPiece = false
end end
lastDropRate = nil lastDropRate = nil
break break
end end
end end
end
end
-- check world events
if not isCraft and not isWBLoot and not isPvP and not isRepReward and not isSetPiece then
for k1,v1 in pairs(AtlasLoot_Data["AtlasLootWorldEvents"]) do
if source then
break
end
for k2,v2 in pairs(AtlasLoot_Data["AtlasLootWorldEvents"][k1]) do
if v2[1] == itemID then
source = k1
isWorldEvent = true
if v2[5] and v2[5] ~= "" then
dropRate = v2[5]
lastDropRate = dropRate
else
lastDropRate = nil
end
break
end
end
end
end
-- check if its a dungeon/raid loot
if not isCraft and not isWBLoot and not isPvP and not isRepReward and not isWorldEvent and not isSetPiece then
for k1,v1 in pairs(AtlasLoot_Data["AtlasLootItems"]) do
if source then
break
end
for k2,v2 in pairs(AtlasLoot_Data["AtlasLootItems"][k1]) do
if v2[1] == itemID then
if k1 ~= "VanillaKeys" then
source = k1
end
if v2[5] and v2[5] ~= "" then
dropRate = v2[5]
lastDropRate = dropRate
else
lastDropRate = nil
end
break
end
end
end
-- check containers
for k1,v1 in pairs(AtlasLoot_Data["AtlasLootItems"]) do
if source then
break
end
for k2,v2 in pairs(AtlasLoot_Data["AtlasLootItems"][k1]) do
if source then
break
end
if v2[16] then
for i, n in pairs(v2[16]) do
if source then
break
end
for i2, n2 in pairs(v2[16][i]) do
if v2[16][i][i2][1] == itemID then
source = k1
break
end
end
end
end
end
end
end
lastItemID = itemID
if not source then
lastSourceStr = nil
return
end
for k,v in pairs(AtlasLoot_TableNames) do
if k == source then
sourceStr = AtlasLoot_TableNames[k][1]
lastSourceStr = sourceStr
break
end
end
if not sourceStr then
return
end
-- if line2:GetText() then
local str
if dropRate then
str = GREY..sourceStr.." ("..dropRate..")|r"
else
str = GREY..sourceStr.."|r"
end
AddSourceLine(tooltip, str)
-- end
elseif lastSourceStr then
-- if line2:GetText() then
local str
if lastDropRate then
str = GREY..lastSourceStr.." ("..lastDropRate..")|r"
else
str = GREY..lastSourceStr.."|r"
end end
AddSourceLine(tooltip, str) end
-- end -- check world events
end if not isCraft and not isWBLoot and not isPvP and not isRepReward and not isSetPiece then
end for k1, v1 in pairs(AtlasLoot_Data["AtlasLootWorldEvents"]) do
if source then
break
end
for k2, v2 in pairs(AtlasLoot_Data["AtlasLootWorldEvents"][k1]) do
if v2[1] == itemID then
source = k1
isWorldEvent = true
if v2[5] and v2[5] ~= "" then
dropRate = v2[5]
lastDropRate = dropRate
else
lastDropRate = nil
end
break
end
end
end
end
-- check if its a dungeon/raid loot
if not isCraft and not isWBLoot and not isPvP and not isRepReward and not isWorldEvent and not isSetPiece then
for k1, v1 in pairs(AtlasLoot_Data["AtlasLootItems"]) do
if source then
break
end
for k2, v2 in pairs(AtlasLoot_Data["AtlasLootItems"][k1]) do
if v2[1] == itemID then
if k1 ~= "VanillaKeys" then
source = k1
end
if v2[5] and v2[5] ~= "" then
dropRate = v2[5]
lastDropRate = dropRate
else
lastDropRate = nil
end
break
end
end
end
-- check containers
for k1, v1 in pairs(AtlasLoot_Data["AtlasLootItems"]) do
if source then
break
end
for k2, v2 in pairs(AtlasLoot_Data["AtlasLootItems"][k1]) do
if source then
break
end
if v2[16] then
for i, n in pairs(v2[16]) do
if source then
break
end
for i2, n2 in pairs(v2[16][i]) do
if v2[16][i][i2][1] == itemID then
source = k1
break
end
end
end
end
end
end
end
lastItemID = itemID
if not source then
lastSourceStr = nil
return
end
for k, v in pairs(AtlasLoot_TableNames) do
if k == source then
sourceStr = AtlasLoot_TableNames[k][1]
lastSourceStr = sourceStr
break
end
end
if not sourceStr then
return
end
local str
if dropRate then
str = GREY .. sourceStr .. " (" .. dropRate .. ")|r"
else
str = GREY .. sourceStr .. "|r"
end
AddSourceLine(tooltip, str)
elseif lastSourceStr then
local str
if lastDropRate then
str = GREY .. lastSourceStr .. " (" .. lastDropRate .. ")|r"
else
str = GREY .. lastSourceStr .. "|r"
end
AddSourceLine(tooltip, str)
end
end
end end
local lastSearchName local lastSearchName
@@ -407,7 +404,7 @@ local function GetItemIDByName(name)
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
@@ -435,7 +432,7 @@ local function HookTooltip(tooltip)
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
@@ -566,7 +563,7 @@ HookTooltip(GameTooltip)
HookTooltip(ItemRefTooltip) HookTooltip(ItemRefTooltip)
AtlasLootTip:SetScript("OnShow", function() AtlasLootTip:SetScript("OnShow", function()
if aux_frame and aux_frame:IsVisible() then if aux_frame and aux_frame:IsVisible() then
if GetMouseFocus():GetParent() then if GetMouseFocus():GetParent() then
if GetMouseFocus():GetParent().row then if GetMouseFocus():GetParent().row then
if GetMouseFocus():GetParent().row.record.item_id then if GetMouseFocus():GetParent().row.record.item_id then
@@ -585,11 +582,11 @@ AtlasLootTip.HookAddonOrVariable = function(addon, 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