tooltip code refactor, added skill requirement if its craftable item
This commit is contained in:
Spit
2025-04-27 16:57:53 +03:00
parent 1ef67e9d77
commit 9b628213f6
3 changed files with 296 additions and 222 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
## Notes: Shows possible loot from dungeon bosses and other sources.
## Author: Shagu (pfUI update code), Lexie (Turtle WoW fixes/updates), Otari (overhaul/revamp, menu changes, bugfixes/updates)
## LegacyAuthor: Daviesh, Pompa (Turtle WoW World Bosses), Xerron (Turtle WoW World Bosses), Gurky (Turtle WoW 1.16/1.16.1 Dungeons)
## Version: 3.1.3
## Version: 3.1.4
## SavedVariablesPerCharacter: AtlasLootCharDB
## OptionalDeps: Alphamap, AtlasLoader, LootLink, ItemSync, HewdropLib, Ace2, EquipCompare, EQCompare
+292 -218
View File
@@ -1,170 +1,86 @@
-- extra info on GameTooltip and ItemRefTooltip
local AL = AceLibrary("AceLocale-2.2"):new("AtlasLoot")
local AtlasLootTip = CreateFrame("Frame", "AtlasLootTip", GameTooltip)
local strfind = string.find
local GetItemInfo = GetItemInfo
local GREY = "|cff999999"
local lastSearchName
local lastSearchID
local WrappingLines = {
["Set: %s"] = gsub("^"..ITEM_SET_BONUS, " %%s", ""),
["(%d) Set: %s"] = gsub(gsub(ITEM_SET_BONUS_GRAY, "%(%%d%)", "^%%(%%d%%)"), " %%s", ""),
["Effect: %s"] = gsub("^"..ITEM_SPELL_EFFECT, " %%s", ""),
["Equip:"] = "^"..ITEM_SPELL_TRIGGER_ONEQUIP,
["Chance on hit:"] = "^"..ITEM_SPELL_TRIGGER_ONPROC,
["Use:"] = "^"..ITEM_SPELL_TRIGGER_ONUSE,
}
local function GetItemIDByName(name)
if not name then return nil end
if name ~= lastSearchName then
for itemID = 1, 99999 do
local itemName = GetItemInfo(itemID)
if (itemName and itemName == name) then
lastSearchID = itemID
break
end
end
lastSearchName = name
end
return lastSearchID
local lines = {}
for i = 1, 30 do
lines[i] = {}
end
local function HookTooltip(tooltip)
local original_SetLootRollItem = tooltip.SetLootRollItem
local original_SetLootItem = tooltip.SetLootItem
local original_SetMerchantItem = tooltip.SetMerchantItem
local original_SetQuestLogItem = tooltip.SetQuestLogItem
local original_SetQuestItem = tooltip.SetQuestItem
local original_SetHyperlink = tooltip.SetHyperlink
local original_SetBagItem = tooltip.SetBagItem
local original_SetInboxItem = tooltip.SetInboxItem
local original_SetInventoryItem = tooltip.SetInventoryItem
local original_SetCraftItem = tooltip.SetCraftItem
local original_SetCraftSpell = tooltip.SetCraftSpell
local original_SetTradeSkillItem = tooltip.SetTradeSkillItem
local original_SetAuctionItem = tooltip.SetAuctionItem
local original_SetAuctionSellItem = tooltip.SetAuctionSellItem
local original_SetTradePlayerItem = tooltip.SetTradePlayerItem
local original_SetTradeTargetItem = tooltip.SetTradeTargetItem
local function AddSourceLine(tooltip, sourceStr)
local name = tooltip:GetName()
local numLines = tooltip:NumLines()
local left, right
local leftText, rightText
local rL, gL, bL
local rR, gR, bR
local wrap
local original_OnHide = tooltip:GetScript("OnHide")
tooltip:SetScript("OnHide", function()
if original_OnHide then original_OnHide() end
this.itemID = nil
end)
function tooltip.SetLootRollItem(self, rollID)
original_SetLootRollItem(self, rollID)
local _, _, id = strfind(GetLootRollItemLink(rollID) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetLootItem(self, slot)
original_SetLootItem(self, slot)
local _, _, id = strfind(GetLootSlotLink(slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetMerchantItem(self, merchantIndex)
original_SetMerchantItem(self, merchantIndex)
local _, _, id = strfind(GetMerchantItemLink(merchantIndex) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetQuestLogItem(self, itemType, index)
original_SetQuestLogItem(self, itemType, index)
local _, _, id = strfind(GetQuestLogItemLink(itemType, index) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetQuestItem(self, itemType, index)
original_SetQuestItem(self, itemType, index)
local _, _, id = strfind(GetQuestItemLink(itemType, index) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetHyperlink(self, arg1)
original_SetHyperlink(self, arg1)
local _, _, id = strfind(arg1 or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetBagItem(self, container, slot)
local hasCooldown, repairCost = original_SetBagItem(self, container, slot)
local _, _, id = strfind(GetContainerItemLink(container, slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
return hasCooldown, repairCost
end
function tooltip.SetInboxItem(self, mailID, attachmentIndex)
original_SetInboxItem(self, mailID, attachmentIndex)
local itemName = GetInboxItem(mailID)
self.itemID = GetItemIDByName(itemName)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetInventoryItem(self, unit, slot)
local hasItem, hasCooldown, repairCost = original_SetInventoryItem(self, unit, slot)
local _, _, id = strfind(GetInventoryItemLink(unit, slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
return hasItem, hasCooldown, repairCost
end
function tooltip.SetCraftItem(self, skill, slot)
original_SetCraftItem(self, skill, slot)
local _, _, id = strfind(GetCraftReagentItemLink(skill, slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetCraftSpell(self, slot)
original_SetCraftSpell(self, slot)
local _, _, id = strfind(GetCraftItemLink(slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetTradeSkillItem(self, skillIndex, reagentIndex)
original_SetTradeSkillItem(self, skillIndex, reagentIndex)
if reagentIndex then
local _, _, id = strfind(GetTradeSkillReagentItemLink(skillIndex, reagentIndex) or "", "item:(%d+)")
self.itemID = tonumber(id)
else
local _, _, id = strfind(GetTradeSkillItemLink(skillIndex) or "", "item:(%d+)")
self.itemID = tonumber(id)
for i in pairs(lines) do
for j in pairs(lines[i]) do
lines[i][j] = nil
end
AtlasLootTip.extendTooltip(self)
end
function tooltip.SetAuctionItem(self, atype, index)
original_SetAuctionItem(self, atype, index)
local itemName = GetAuctionItemInfo(atype, index)
self.itemID = GetItemIDByName(itemName)
AtlasLootTip.extendTooltip(self)
for i = 1, numLines do
left = getglobal(name .. "TextLeft" .. i)
right = getglobal(name .. "TextRight" .. i)
leftText = left:GetText()
rightText = right:IsShown() and right:GetText()
rL, gL, bL = left:GetTextColor()
rR, gR, bR = right:GetTextColor()
lines[i][1] = leftText
lines[i][2] = rightText
lines[i][3] = rL
lines[i][4] = gL
lines[i][5] = bL
lines[i][6] = rR
lines[i][7] = gR
lines[i][8] = bR
end
function tooltip.SetAuctionSellItem(self)
original_SetAuctionSellItem(self)
local itemName = GetAuctionSellItemInfo()
self.itemID = GetItemIDByName(itemName)
AtlasLootTip.extendTooltip(self)
if not lines[1][1] then return end
tooltip:SetText(lines[1][1], lines[1][3], lines[1][4], lines[1][5], 1, false)
if numLines < 28 then
tooltip:AddLine(sourceStr)
elseif lines[2][1] then
lines[2][1] = sourceStr.."\n"..lines[2][1]
end
function tooltip.SetTradePlayerItem(self, index)
original_SetTradePlayerItem(self, index)
local _, _, id = strfind(GetTradePlayerItemLink(index) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
for i = 2, getn(lines) do
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])
else
wrap = false
if strsub(lines[i][1] or "", 1, 1) == "\"" then
wrap = true
else
for _, pattern in pairs(WrappingLines) do
if strfind(lines[i][1] or "", pattern) then
wrap = true
break
end
end
end
tooltip:AddLine(lines[i][1], lines[i][3], lines[i][4], lines[i][5], wrap)
end
end
function tooltip.SetTradeTargetItem(self, index)
original_SetTradeTargetItem(self, index)
local _, _, id = strfind(GetTradeTargetItemLink(index) or "", "item:(%d+)")
self.itemID = tonumber(id)
AtlasLootTip.extendTooltip(self)
end
tooltip:Show()
end
local sets = {
@@ -181,6 +97,40 @@ local sets = {
["Tabards"] = true,
}
local professions = {
["Apprentice"] = true,
["Journeyman"] = true,
["Expert"] = true,
["Artisan"] = true,
["Goblin"] = true,
["Gnomish"] = true,
["Survival"] = true,
["Herbalism"] = true,
["FirstAid"] = true,
["Poisons"] = true,
["Mining"] = true,
["Smelting"] = true,
["Elemental"] = true,
["Tribal"] = true,
["Dragonscale"] = true,
["Weaponsmith"] = true,
["Axesmith"] = true,
["Hammersmith"] = true,
["Swordsmith"] = true,
["Armorsmith"] = true,
["Gemology"] = true,
["Goldsmithing"] = true,
}
local function SetPartialMatch(set, str)
if type(set) ~= "table" then return end
for k in pairs(set) do
if strfind(str, k, 1, true) then
return k
end
end
end
local function SetContains(set, key)
if not set or not key then
return false
@@ -189,17 +139,16 @@ local function SetContains(set, key)
end
local lastItemID, lastSourceStr, lastDropRate
function AtlasLootTip.extendTooltip(tooltip)
local function ExtendTooltip(tooltip)
if not AtlasLootCharDB.ShowSource then
return
end
local tooltipName = tooltip:GetName()
local itemName = getglobal(tooltipName .. "TextLeft1"):GetText()
local line2 = getglobal(tooltipName .. "TextLeft2")
local craftSpell, source, sourceStr, dropRate
local isCraft, isWBLoot, isPvP, isRepReward, isSetPiece, isWorldEvent = false, false, false, false, false, false
local itemID = tonumber(tooltip.itemID)
if itemName and itemID and itemID ~= 51217 then -- 51217 Fashion Coin
if itemID and itemID ~= 51217 then -- 51217 Fashion Coin
if itemID ~= lastItemID then
for row = 1, tooltip:NumLines() do
local rowtext = getglobal(tooltipName.."TextLeft"..row):GetText()
@@ -226,47 +175,20 @@ function AtlasLootTip.extendTooltip(tooltip)
break
end
for k2, v2 in pairs(AtlasLoot_Data["AtlasLootCrafting"][k1]) do
if v2[1] ~= 0 and v2[1] ~= "" --[[and string.sub(v2[1], 1, 1) ~= "e"]] then
if (v2[1] == craftSpell or v2[1] == itemID) and
(strfind(k1, "Apprentice", 1, true) or
strfind(k1, "Journeyman", 1, true) or
strfind(k1, "Expert", 1, true) or
strfind(k1, "Artisan", 1, true) or
strfind(k1, "Goblin", 1, true) or
strfind(k1, "Gnomish", 1, true) or
strfind(k1, "Survival", 1, true) or
strfind(k1, "Herbalism", 1, true) or
strfind(k1, "FirstAid", 1, true) or
strfind(k1, "Poisons", 1, true) or
strfind(k1, "Mining", 1, true) or
strfind(k1, "Smelting", 1, true) or
strfind(k1, "Elemental", 1, true) or
strfind(k1, "Tribal", 1, true) or
strfind(k1, "Dragonscale", 1, true) or
strfind(k1, "Weaponsmith", 1, true) or
strfind(k1, "Axesmith", 1, true) or
strfind(k1, "Hammersmith", 1, true) or
strfind(k1, "Swordsmith", 1, true) or
strfind(k1, "Armorsmith", 1, true) or
strfind(k1, "Gemology", 1, true) or
strfind(k1, "Goldsmithing", 1, true))
then
if v2[1] ~= 0 and v2[1] ~= "" then
if (v2[1] == craftSpell or v2[1] == itemID) and SetPartialMatch(professions, k1) then
source = k1
isCraft = true
lastDropRate = nil
-- if strfind(k1, "Apprentice", 1, true) then
-- dropRate = "1-75"
-- lastDropRate = dropRate
-- elseif strfind(k1, "Journeyman", 1, true) then
-- dropRate = "75-150"
-- lastDropRate = dropRate
-- elseif strfind(k1, "Expert", 1, true) then
-- dropRate = "150-225"
-- lastDropRate = dropRate
-- elseif strfind(k1, "Artisan", 1, true) then
-- dropRate = "225-300"
-- lastDropRate = dropRate
-- end
dropRate = AtlasLoot_FixText(v2[4] or "") or ""
dropRate = gsub(dropRate or "", "\124cff%x%x%x%x%x%x", "")
local skill = ""
_, _, dropRate, skill = strfind(dropRate or "", "("..AL["Skill:"]..") (%d+)")
if dropRate and skill then
dropRate = skill ~= "300" and dropRate.." "..skill.."+" or dropRate.." "..skill
lastDropRate = dropRate
else
lastDropRate = nil
end
break
end
end
@@ -454,38 +376,190 @@ function AtlasLootTip.extendTooltip(tooltip)
return
end
if line2 and line2:GetText() then
-- if line2:GetText() then
local str
if dropRate then
line2:SetText(GREY..sourceStr.." ("..dropRate..")|r\n"..line2:GetText())
str = GREY..sourceStr.." ("..dropRate..")|r"
else
line2:SetText(GREY..sourceStr.."|r\n"..line2:GetText())
str = GREY..sourceStr.."|r"
end
else
if dropRate then
tooltip:AddLine(GREY..sourceStr.." ("..dropRate..")|r")
else
tooltip:AddLine(GREY..sourceStr.."|r")
end
end
elseif itemID == lastItemID then
if lastSourceStr then
if line2:GetText() then
if lastDropRate then
line2:SetText(GREY..lastSourceStr.." ("..lastDropRate..")|r\n"..line2:GetText())
else
line2:SetText(GREY..lastSourceStr.."|r\n"..line2:GetText())
end
else
if lastDropRate then
tooltip:AddLine(GREY..lastSourceStr.." ("..lastDropRate..")|r")
else
tooltip:AddLine(GREY..lastSourceStr.."|r")
end
end
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
AddSourceLine(tooltip, str)
-- end
end
end
tooltip:Show()
end
local lastSearchName
local lastSearchID
local function GetItemIDByName(name)
if not name then return nil end
if name ~= lastSearchName then
for itemID = 1, 99999 do
local itemName = GetItemInfo(itemID)
if (itemName and itemName == name) then
lastSearchID = itemID
break
end
end
lastSearchName = name
end
return lastSearchID
end
local function HookTooltip(tooltip)
local original_SetLootRollItem = tooltip.SetLootRollItem
local original_SetLootItem = tooltip.SetLootItem
local original_SetMerchantItem = tooltip.SetMerchantItem
local original_SetQuestLogItem = tooltip.SetQuestLogItem
local original_SetQuestItem = tooltip.SetQuestItem
local original_SetHyperlink = tooltip.SetHyperlink
local original_SetBagItem = tooltip.SetBagItem
local original_SetInboxItem = tooltip.SetInboxItem
local original_SetInventoryItem = tooltip.SetInventoryItem
local original_SetCraftItem = tooltip.SetCraftItem
local original_SetCraftSpell = tooltip.SetCraftSpell
local original_SetTradeSkillItem = tooltip.SetTradeSkillItem
local original_SetAuctionItem = tooltip.SetAuctionItem
local original_SetAuctionSellItem = tooltip.SetAuctionSellItem
local original_SetTradePlayerItem = tooltip.SetTradePlayerItem
local original_SetTradeTargetItem = tooltip.SetTradeTargetItem
local original_OnHide = tooltip:GetScript("OnHide")
tooltip:SetScript("OnHide", function()
if original_OnHide then original_OnHide() end
this.itemID = nil
end)
function tooltip.SetLootRollItem(self, rollID)
original_SetLootRollItem(self, rollID)
local _, _, id = strfind(GetLootRollItemLink(rollID) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetLootItem(self, slot)
original_SetLootItem(self, slot)
local _, _, id = strfind(GetLootSlotLink(slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetMerchantItem(self, merchantIndex)
original_SetMerchantItem(self, merchantIndex)
local _, _, id = strfind(GetMerchantItemLink(merchantIndex) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetQuestLogItem(self, itemType, index)
original_SetQuestLogItem(self, itemType, index)
local _, _, id = strfind(GetQuestLogItemLink(itemType, index) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetQuestItem(self, itemType, index)
original_SetQuestItem(self, itemType, index)
local _, _, id = strfind(GetQuestItemLink(itemType, index) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetHyperlink(self, arg1)
original_SetHyperlink(self, arg1)
local _, _, id = strfind(arg1 or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetBagItem(self, container, slot)
local hasCooldown, repairCost = original_SetBagItem(self, container, slot)
local _, _, id = strfind(GetContainerItemLink(container, slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
return hasCooldown, repairCost
end
function tooltip.SetInboxItem(self, mailID, attachmentIndex)
original_SetInboxItem(self, mailID, attachmentIndex)
local itemName = GetInboxItem(mailID)
self.itemID = GetItemIDByName(itemName)
ExtendTooltip(self)
end
function tooltip.SetInventoryItem(self, unit, slot)
local hasItem, hasCooldown, repairCost = original_SetInventoryItem(self, unit, slot)
local _, _, id = strfind(GetInventoryItemLink(unit, slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
return hasItem, hasCooldown, repairCost
end
function tooltip.SetCraftItem(self, skill, slot)
original_SetCraftItem(self, skill, slot)
local _, _, id = strfind(GetCraftReagentItemLink(skill, slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetCraftSpell(self, slot)
original_SetCraftSpell(self, slot)
local _, _, id = strfind(GetCraftItemLink(slot) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetTradeSkillItem(self, skillIndex, reagentIndex)
original_SetTradeSkillItem(self, skillIndex, reagentIndex)
if reagentIndex then
local _, _, id = strfind(GetTradeSkillReagentItemLink(skillIndex, reagentIndex) or "", "item:(%d+)")
self.itemID = tonumber(id)
else
local _, _, id = strfind(GetTradeSkillItemLink(skillIndex) or "", "item:(%d+)")
self.itemID = tonumber(id)
end
ExtendTooltip(self)
end
function tooltip.SetAuctionItem(self, atype, index)
original_SetAuctionItem(self, atype, index)
local itemName = GetAuctionItemInfo(atype, index)
self.itemID = GetItemIDByName(itemName)
ExtendTooltip(self)
end
function tooltip.SetAuctionSellItem(self)
original_SetAuctionSellItem(self)
local itemName = GetAuctionSellItemInfo()
self.itemID = GetItemIDByName(itemName)
ExtendTooltip(self)
end
function tooltip.SetTradePlayerItem(self, index)
original_SetTradePlayerItem(self, index)
local _, _, id = strfind(GetTradePlayerItemLink(index) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
function tooltip.SetTradeTargetItem(self, index)
original_SetTradeTargetItem(self, index)
local _, _, id = strfind(GetTradeTargetItemLink(index) or "", "item:(%d+)")
self.itemID = tonumber(id)
ExtendTooltip(self)
end
end
HookTooltip(GameTooltip)
@@ -500,7 +574,7 @@ AtlasLootTip:SetScript("OnShow", function()
end
end
end
AtlasLootTip.extendTooltip(GameTooltip)
ExtendTooltip(GameTooltip)
end
end)
+1 -1
View File
@@ -3603,9 +3603,9 @@ AtlasLoot_Data["AtlasLootCrafting"] = {
{ "s41065", "INV_Stone_08", "=q1=Coarse Gemstone Cluster", "=ds=#sr# =so1=125 =so2=140 =so3=142 =so4=145" },
{ "s41057", "INV_Crown_01", "=q2=Agatestone Crown", "=ds=#sr# =so1=125 =so2=145 =so3=155 =so4=165" },
{ "s41061", "INV_Belt_31", "=q2=Binding Signet", "=ds=#sr# =so1=125 =so2=145 =so3=155 =so4=165" },
{ "s41063", "INV_Bracer_14", "=q2=Enchanted Bracelets", "=ds=#sr# =so1=125 =so2=145 =so3=155 =so4=165" },
};
JewelcraftingJourneyman2 = {
{ "s41063", "INV_Bracer_14", "=q2=Enchanted Bracelets", "=ds=#sr# =so1=125 =so2=145 =so3=155 =so4=165" },
{ "s41776", "INV_Jewelry_Ring_24", "=q2=Ring of Midnight", "=ds=#sr# =so1=125 =so2=145 =so3=155 =so4=165" },
{ "s41059", "INV_Staff_15", "=q2=Moonlight Staff", "=ds=#sr# =so1=125 =so2=150 =so3=160 =so4=170" },
{ "s41568", "INV_Jewelry_Ring_10", "=q2=Dazzling Moonstone Band", "=ds=#sr# =so1=130 =so2=150 =so3=160 =so4=170" },