Quantcast

Added bank count in the queue display.

pschifferer [02-01-09 - 15:51]
Added bank count in the queue display.
Made the reagent information collector smarter: first try the tradeskill context, and cache the information,
on-demand, then try PeriodicTable if that is not available.
Filename
Cauldron.toc
CauldronMain.lua
CauldronMainUI.lua
CauldronTradeskill.lua
CauldronUtil.lua
Locale/Cauldron-enUS.lua
diff --git a/Cauldron.toc b/Cauldron.toc
index e48f370..f0c5fd0 100755
--- a/Cauldron.toc
+++ b/Cauldron.toc
@@ -1,6 +1,6 @@
 ## Interface: 30000
 ## Title: Cauldron |cff7fff7f -Ace3-|r
-## Version: 0.9.8.$Revision$
+## Version: 0.9.9.$Revision$
 ## Author: Caendra of Silver Hand
 ## Notes: An improved interface for your trade skills
 ## RequiredDeps:
diff --git a/CauldronMain.lua b/CauldronMain.lua
index f438bc7..fb9ab45 100644
--- a/CauldronMain.lua
+++ b/CauldronMain.lua
@@ -4,7 +4,7 @@
 Cauldron = LibStub("AceAddon-3.0"):NewAddon("Cauldron", "AceEvent-3.0", "AceTimer-3.0", "AceConsole-3.0", "AceHook-3.0", "LibLogger-1.0");
 local L = LibStub("AceLocale-3.0"):GetLocale("Cauldron");

-Cauldron.version = "0.9.8." .. string.sub("$Revision$", 12, -3);
+Cauldron.version = "0.9.9." .. string.sub("$Revision$", 12, -3);
 Cauldron.date = string.sub("$Date$", 8, 17);

 -- key binding names
diff --git a/CauldronMainUI.lua b/CauldronMainUI.lua
index 5969975..97b6742 100644
--- a/CauldronMainUI.lua
+++ b/CauldronMainUI.lua
@@ -682,6 +682,9 @@ function Cauldron:UpdateQueue()
 			frame = _G["CauldronQueueIntItem"..i.."Info"];
 			local countInfo = Cauldron:ReagentCount(queueInfo.name);
 			local infoText = string.format(queueInfo.tradeskill.."; "..L["Have %d"], countInfo.has);
+			if countInfo.bank > 0 then
+				infoText = infoText..string.format(L[" (%d in bank)"], countInfo.bank);
+			end
 			local need = math.max(0, queueInfo.amount - countInfo.has);
 			if need > 0 then
 				infoText = infoText..string.format(L[", need %d"], need);
@@ -800,6 +803,9 @@ function Cauldron:UpdateQueue()
 		frame = _G["CauldronQueueReagentItem"..i.."Info"];
 		local countInfo = Cauldron:ReagentCount(queueInfo.name);
 		local qtyText = string.format(L["Have %d"], countInfo.has);
+		if countInfo.bank > 0 then
+			qtyText = qtyText..string.format(L[" (%d in bank)"], countInfo.bank);
+		end
 		if need > 0 then
 			qtyText = qtyText..string.format(L[", need %d"], need);
 		end
diff --git a/CauldronTradeskill.lua b/CauldronTradeskill.lua
index b8404e8..f1acc2d 100644
--- a/CauldronTradeskill.lua
+++ b/CauldronTradeskill.lua
@@ -460,42 +460,78 @@ function Cauldron:GetReagentsForSkill(skillInfo)
 	local reagents = {};

 	local itemId = self:GetIdFromLink(skillInfo.itemLink);
-
-	-- check the standard skill
-	local reagentStr = self.libs.PT:ItemInSet(itemId, "TradeskillResultMats.Forward."..skillInfo.tradeskill);
-	if not reagentStr then
-		-- lookup the mapped skill
-		local skillMap = {
-			['Mining'] = 'Smelting',
---			['Inscription'] = 'Milling',
---			['Jewelcrafting'] = 'Prospecting',
-		};
-		if skillMap[skillInfo.tradeskill] then
-			reagentStr = self.libs.PT:ItemInSet(itemId, "TradeskillResultMats.Forward."..skillMap[skillInfo.tradeskill]);
-		end
+
+	local skillName = CURRENT_TRADESKILL;
+	local baseSkillName = CURRENT_TRADESKILL;
+	if IsTradeSkillLinked() then
+		skillName = "Linked-"..skillName;
 	end
-	if not reagentStr then
-		self:error("No reagents found for skill: "..skillInfo.name);
-		return {};
+
+	-- check if the reagents are already populated
+	if #skillInfo.reagents then
+		return skillInfo.reagents;
 	end
+
+	-- check for the proper trade skill context
+	if baseSkillName == skillInfo.tradeskill then

-	-- split the reagent info
-	for _, reagent in ipairs(split(";", reagentStr)) do
-		local id, numRequired = strsplit("x", reagent);
+		for i=1,GetTradeSkillNumReagents(skillInfo.index) do
+			local name, icon, count, _ = GetTradeSkillReagentInfo(skillInfo.index, i);
+			local link = GetTradeSkillReagentItemLink(skillInfo.index, i);

-		-- get item details for the reagent
-		local name, link, _, _, _, _, _, _, _, icon = GetItemInfo(id);
-
-		local r = {
-			["toonHas"] = GetItemCount(id),
-			["name"] = name,
-			["numRequired"] = tonumber(numRequired),
-			["skillIndex"] = skillInfo.index,
-			["icon"] = icon,
-			["link"] = link,
-		};
+			local r = {
+				["toonHas"] = GetItemCount(link),
+				["name"] = name,
+				["numRequired"] = count,
+				["skillIndex"] = skillInfo.index,
+				["icon"] = icon,
+				["link"] = link,
+			};
+
+			table.insert(reagents, r);
+		end
+
+		-- save the reagent list
+		skillInfo.reagents = reagents;
+	else
+		self:warn("No tradeskill context found; using PeriodicTable for reagent info!");
+
+		-- check the standard skill
+		local reagentStr = self.libs.PT:ItemInSet(itemId, "TradeskillResultMats.Forward."..skillInfo.tradeskill);
+		if not reagentStr then
+			-- lookup the mapped skill
+			local skillMap = {
+				['Mining'] = 'Smelting',
+	--			['Inscription'] = 'Milling',
+	--			['Jewelcrafting'] = 'Prospecting',
+			};
+			if skillMap[skillInfo.tradeskill] then
+				reagentStr = self.libs.PT:ItemInSet(itemId, "TradeskillResultMats.Forward."..skillMap[skillInfo.tradeskill]);
+			end
+		end
+		if not reagentStr then
+			self:error("No reagents found for skill: "..skillInfo.name);
+			return {};
+		end

-		table.insert(reagents, r);
+		-- split the reagent info
+		for _, reagent in ipairs(split(";", reagentStr)) do
+			local id, numRequired = strsplit("x", reagent);
+
+			-- get item details for the reagent
+			local name, link, _, _, _, _, _, _, _, icon = GetItemInfo(id);
+
+			local r = {
+				["toonHas"] = GetItemCount(id),
+				["name"] = name,
+				["numRequired"] = tonumber(numRequired),
+				["skillIndex"] = skillInfo.index,
+				["icon"] = icon,
+				["link"] = link,
+			};
+
+			table.insert(reagents, r);
+		end
 	end

 	return reagents;
diff --git a/CauldronUtil.lua b/CauldronUtil.lua
index ec8d5c9..259fe1c 100644
--- a/CauldronUtil.lua
+++ b/CauldronUtil.lua
@@ -38,8 +38,9 @@ function Cauldron:ReagentCount(reagent)
 	end

 	count.has = GetItemCount(reagent, false);
+	count.bank = GetItemCount(reagent, true) - count.has;

-
+--[[
 	-- TODO: find in banks, on alts, etc.
 	if BankItems_SelfCache then
 		-- TODO
@@ -50,7 +51,7 @@ function Cauldron:ReagentCount(reagent)
 	if BankItems_GuildCache then
 --		count.guildBank = BankItems_GuildCache[reagent].
 	end
-
+--]]

 	return count;
 end
diff --git a/Locale/Cauldron-enUS.lua b/Locale/Cauldron-enUS.lua
index e2b80df..816eb51 100644
--- a/Locale/Cauldron-enUS.lua
+++ b/Locale/Cauldron-enUS.lua
@@ -85,6 +85,7 @@ L["You first have to make:"] = true
 L["You will need:"] = true

 L["Have %d"] = true
+L[" (%d in bank)"] = true
 L[", need %d"] = true

 L["Crafting %1$d of %2$s..."] = true