From 48ec9ddd7f28e951358b33ebb817ac9e92ca06f8 Mon Sep 17 00:00:00 2001 From: pschifferer Date: Sun, 1 Nov 2009 06:22:34 +0000 Subject: [PATCH] Added code to modify tooltip if a reagent that is moused-over that is needed in a skill marked as a favorite, or that can be used to level the tradeskill. (THIS CODE IS UNTESTED, and might be severely broken. Download and use at your own risk.) --- CauldronMain.lua | 185 ++++++++++++++++++++++++++++++++++++++++++++-- CauldronMain.xml | 7 +- CauldronTradeskill.lua | 61 ++++++++++++++- Locale/Cauldron-enUS.lua | 5 ++ 4 files changed, 246 insertions(+), 12 deletions(-) diff --git a/CauldronMain.lua b/CauldronMain.lua index 29d1ff1..8c7c24b 100644 --- a/CauldronMain.lua +++ b/CauldronMain.lua @@ -919,22 +919,141 @@ function Cauldron:HookTooltips() self:debug("HookTooltips enter"); --@end-alpha@ --- self:SecureHook(GameTooltip, "SetBagItem"); --- self:SecureHook(GameTooltip, "SetInventoryItem"); --- self:SecureHook(GameTooltip, "SetLootItem"); + self:SecureHook(GameTooltip, "SetBagItem"); + self:SecureHook(GameTooltip, "SetInventoryItem"); + self:SecureHook(GameTooltip, "SetLootItem"); self:SecureHook(GameTooltip, "SetHyperlink"); self:SecureHook(GameTooltip, "SetTradeSkillItem"); --- self:SecureHook(GameTooltip, "SetMerchantItem"); --- self:SecureHook(GameTooltip, "SetAuctionItem"); + self:SecureHook(GameTooltip, "SetMerchantItem"); + self:SecureHook(GameTooltip, "SetAuctionItem"); -- self:SecureHook(GameTooltip, "SetTrainerService"); --- self:SecureHook(GameTooltip, "SetGuildBankItem"); --- self:SecureHook("SetItemRef"); + self:SecureHook(GameTooltip, "SetGuildBankItem"); + self:SecureHook("SetItemRef"); --@alpha@ self:debug("HookTooltips exit"); --@end-alpha@ end +function Cauldron:AddToTooltip(tooltip, id) + if not id then + return; + end + + local skillList = Cauldron:GetSkillsForReagent(id); + + -- add favorite info + local favSkills = filterFavoriteSkills(skillList); + if favSkills and #favSkills > 0 then + local color = "|cffffffff"; + local favInfo = ""; + if #favSkills > 3 then + -- if the skill list has more than 3 items, summarize + favInfo = string.format(L["Needed for %1$d favorite skills"], #favSkills); + else + -- if the skill list is 3 or less, list all + favInfo = L["Needed for favorites: "]; + for i,skill in ipairs(favSkills) do + local skillName,skillLink = string.split(skill, ";", 2); + if i > 1 then + favInfo = favInfo.."|cffffffff, |r"; + end + local skillInfo = Cauldron:GetSkillForLink(skillLink); + local color = TradeSkillTypeColor[skillInfo.difficulty]; + local colorStr = "ffffff"; + if color then + string.format("%02x%02x%02x", color.r, color.g, color.b); + end + favInfo = favInfo.."|cff"..colorStr..skillInfo.name.."|r"; + end + end + tooltip:AddLine(color..favInfo.."|r"); + end + + -- add skill-up info + local skillups = filterSkillups(skillList); + if skillups and #skillups > 0 then + local color = "|cffffffff"; + local levelInfo = ""; + if #skillups > 3 then + -- if the skill list has more than 3 items, summarize + levelInfo = string.format(L["Needed for %1$d skills for leveling"], #skillups); + else + -- if the skill list is 3 or less, list all + levelInfo = L["Needed for leveling: "]; + for i,skill in ipairs(skillups) do + local skillName,skillLink = string.split(skill, ";", 2); + if i > 1 then + levelInfo = levelInfo.."|cffffffff, |r"; + end + local skillInfo = Cauldron:GetSkillForLink(skillLink); + local color = TradeSkillTypeColor[skillInfo.difficulty]; + local colorStr = "ffffff"; + if color then + string.format("%02x%02x%02x", color.r, color.g, color.b); + end + levelInfo = levelInfo.."|cff"..colorStr..skillInfo.name.."|r"; + end + end + tooltip:AddLine(color..levelInfo.."|r"); + end +end + +function filterFavoriteSkills(skillList) + + if not skillList then + return nil; + end + + local faves = {}; + + for i,skill in ipairs(skillList) do + local skillName, skillLink = string.split(skill, ";", 2); + local skillInfo = Cauldron:GetSkillForLink(skillLink); + + if skillInfo and skillName then + if Cauldron.db.realm.userdata[Cauldron.vars.playername].skills[skillName] then + if Cauldron.db.realm.userdata[Cauldron.vars.playername].skills[skillName].window.skills[skillInfo.name] then + if Cauldron.db.realm.userdata[Cauldron.vars.playername].skills[skillName].window.skills[skillInfo.name].favorite then + table.insert(faves, skill); + end + end + end + end + end + + return faves; +end + +function filterSkillups(skillList) + + if not skillList then + return nil; + end + + local skillups = {}; + + local difficulty = { + optimal = 4, + medium = 3, + easy = 2, + trivial = 1, + }; + + for i,skill in ipairs(skillList) do + local skillName, skillLink = string.split(skill, ";", 2); + local skillInfo = Cauldron:GetSkillForLink(skillLink); + + if skillInfo then + if difficulty[skillInfo.difficulty] > 1 then + table.insert(skillups, skill); + end + end + end + + return skillups; +end + function Cauldron:SetTradeSkillItem(tooltip, itemIndex, reagentIndex) local link; local name; @@ -943,6 +1062,9 @@ function Cauldron:SetTradeSkillItem(tooltip, itemIndex, reagentIndex) local reagentInfo = Cauldron:GetReagentInfoByIndex(itemIndex, reagentIndex); if reagentInfo then + local id = Cauldron:GetIdFromLink(reagentInfo.link); + self:AddToTooltip(tooltip, id); + -- let the user know if the reagent is a "non-key" reagent if not reagentInfo.key then tooltip:AddLine("|cff666666"..L["Available at vendor"].."|r"); @@ -960,6 +1082,55 @@ function Cauldron:SetHyperlink(tooltip, link) -- local name = Cauldron:GetNameFromLink(link); -- local skillInfo = Cauldron: + local id = Cauldron:GetIdFromLink(link); + +end + +function Cauldron:SetItemRef(link, text, button) +-- if IsControlKeyDown() or IsShiftKeyDown() then return end + if ( IsModifiedClick() ) then return end + local id = Cauldron:GetIdFromLink(link); + if id then +-- self:AddToTooltip(ItemRefTooltip,id); + end +end + +function Cauldron:SetBagItem(tooltip, bag, slot) + local link = GetContainerItemLink(bag, slot); + local id = Cauldron:GetIdFromLink(link); + self:AddToTooltip(tooltip, id); +end + +function Cauldron:SetGuildBankItem(tooltip, tab, slot) + local link = GetGuildBankItemLink(tab, slot); + local id = Cauldron:GetIdFromLink(link); + self:AddToTooltip(tooltip, id); +end + +function Cauldron:SetInventoryItem(tooltip, unit, slot, nameOnly) + if slot > 39 and slot < 68 then + local link = GetContainerItemLink(BANK_CONTAINER, slot-39) + local id = Cauldron:GetIdFromLink(link); + self:AddToTooltip(tooltip, id); + end +end + +function Cauldron:SetLootItem(tooltip, index) + local link = GetLootSlotLink(index); + local id = Cauldron:GetIdFromLink(link); + self:AddToTooltip(tooltip, id); +end + +function Cauldron:SetMerchantItem(tooltip, index) + local link = GetMerchantItemLink(index); + local id = Cauldron:GetIdFromLink(link); + self:AddToTooltip(tooltip, id); +end + +function Cauldron:SetAuctionItem(tooltip, type, index) + local link = GetAuctionItemLink(type, index); + local id = Cauldron:GetIdFromLink(link); + self:AddToTooltip(tooltip, id); end ---------------------------------------------------------------------- diff --git a/CauldronMain.xml b/CauldronMain.xml index e855c9e..5809d55 100644 --- a/CauldronMain.xml +++ b/CauldronMain.xml @@ -2,7 +2,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\..\FrameXML\UI.xsd"> - + + + +