Quantcast

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.

pschifferer [11-01-09 - 06:22]
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.)
Filename
CauldronMain.lua
CauldronMain.xml
CauldronTradeskill.lua
Locale/Cauldron-enUS.lua
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">

-    <!-- Templates -->
+    <!-- Template: Button -->
     <Button name="CauldronButtonTemplate" inherits="UIPanelButtonTemplate" virtual="true">
         <Size x="80" y="20" />
         <NormalText inherits="GameFontHighlightSmall" />
@@ -24,6 +24,7 @@
         </Scripts>
     </Button>

+    <!-- Template: Reagent detail -->
 	<Button name="CauldronReagentDetailTemplate" inherits="QuestItemTemplate" virtual="true">
 		<Scripts>
 			<OnEnter>
@@ -45,6 +46,7 @@
 		</Scripts>
 	</Button>

+    <!-- Template: Skill item frame -->
     <Button name="CauldronSkillItemFrameTemplate" virtual="true">
     	<Size x="300" y="50" />
     	<Layers>
@@ -115,7 +117,7 @@
 					<OnEnter>
 						GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
 						GameTooltip:SetTradeSkillItem(self.skillIndex);
-						Cauldron:AppendToTooltip(GameTooltip, self.skillIndex);
+						-- Cauldron:AppendToTooltip(GameTooltip, self.skillIndex);
 						CursorUpdate(self);
 					</OnEnter>
 					<OnLeave>
@@ -283,6 +285,7 @@
     	</Scripts>
     </Button>

+    <!-- Template: Queue item frame -->
     <Button name="CauldronQueueItemFrameTemplate" virtual="true" enableMouse="true">
     	<Size x="300" y="39" />
     	<Layers>
diff --git a/CauldronTradeskill.lua b/CauldronTradeskill.lua
index 83b5ff1..c782527 100644
--- a/CauldronTradeskill.lua
+++ b/CauldronTradeskill.lua
@@ -29,6 +29,11 @@ function Cauldron:UpdateSkills()
 		self.db.realm.userdata[self.vars.playername].skills[skillName] = {};
 	end

+	-- initialize the reagent map
+	if not self.db.realm.userdata[self.vars.playername].reagentMap then
+		self.db.realm.userdata[self.vars.playername].reagentMap = {};
+	end
+
 	-- save the skill entry in a local var
 	local skillDB = self.db.realm.userdata[self.vars.playername].skills[skillName];
 	if not skillDB.recipes then
@@ -63,8 +68,7 @@ function Cauldron:UpdateSkills()
 	-- make sure we're getting a full list
 	SetTradeSkillItemNameFilter(nil);
 	SetTradeSkillItemLevelFilter(0, 0);
-
-
+
 	local category = "";

 	for i=1,GetNumTradeSkills() do
@@ -180,6 +184,12 @@ function Cauldron:UpdateSkills()
 					};

 					table.insert(skillDB.recipes[name].reagents, r);
+
+					-- add the reagent to the reagent map
+					if not self.db.realm.userdata[self.vars.playername].reagentMap[rName] then
+						self.db.realm.userdata[self.vars.playername].reagentMap[rName] = {};
+					end
+					table.insert(self.db.realm.userdata[self.vars.playername].reagentMap[rName], skillName..";"..recipeLink);

 					if rName then
 --							Cauldron:info("adding to keywords: "..tostring(keywords));
@@ -512,6 +522,27 @@ function Cauldron:GetSkillInfoForItem(item)
 	return nil;
 end

+function Cauldron:GetSkillInfoForLink(recipeLink)
+
+	if not recipeLink then
+		Cauldron:error("GetSkillInfoForLink: recipeLink is nil!");
+		return nil;
+	end
+
+	for tradeskill, list in pairs(self.db.realm.userdata[self.vars.playername].skills) do
+		-- skip linked skills
+		if not (string.find(tradeskill, "Linked-")) then
+			for _, recipeInfo in pairs(list.recipes) do
+				if recipeLink == recipeInfo.recipeLink then
+					return recipeInfo;
+				end
+			end
+		end
+	end
+
+	return nil;
+end
+
 function Cauldron:GetSkillInfoByIndex(itemIndex)

 	if not itemIndex then
@@ -692,4 +723,28 @@ function Cauldron:GetReagentsForSkill(skillInfo)

 	return reagents;
 end
---]==]
\ No newline at end of file
+--]==]
+
+function Cauldron:GetSkillsForReagent(id)
+	if not id then
+		return {};
+	end
+
+	local itemName,itemInfo,_ = GetItemInfo(id);
+	local skillList = {};
+
+	if not Cauldron.db.realm.userdata[Cauldron.vars.playername].reagentMap then
+		return {};
+	end
+
+	-- find the reagent in the map
+	local reagentMap = Cauldron.db.realm.userdata[Cauldron.vars.playername].reagentMap[itemName];
+	if reagentMap then
+		for _,skill in ipairs(reagentMap) do
+			table.insert(skillList, skill);
+		end
+	end
+
+	return skillList;
+end
+
diff --git a/Locale/Cauldron-enUS.lua b/Locale/Cauldron-enUS.lua
index 2226bed..a8c6ab5 100644
--- a/Locale/Cauldron-enUS.lua
+++ b/Locale/Cauldron-enUS.lua
@@ -134,6 +134,11 @@ L["Purchasing %1$s from merchant %2$s..."] = true
 L["(%1$d stacks, %2$d total)"] = true
 L["(%1$d total)"] = true

+L["Needed for %1$d favorite skills"] = true
+L["Needed for favorites: "] = true
+L["Needed for %1$d skills for leveling"] = true
+L["Needed for leveling: "] = true
+
 -- error messages
 L["Crafting %1$s requires the %2$s skill."] = true