changeset 108:618163a6d970 v1.0beta13

Always show counts and bypass all filtering and searches
author contrebasse
date Thu, 02 Jun 2011 14:12:06 +0200
parents d64a19e5a47d
children b5fd4a61ee64
files ReagentMaker.lua SecureMenu.lua data.lua utils.lua
diffstat 4 files changed, 80 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/ReagentMaker.lua	Thu Jun 02 00:57:17 2011 +0200
+++ b/ReagentMaker.lua	Thu Jun 02 14:12:06 2011 +0200
@@ -116,6 +116,10 @@
 
 -- Function run after selecting a item in the tradeskill window
 function A.ProcessReagent(btn, ...)
+	--SPELL_FAILED_REAGENTS = "Missing reagent: %s";
+	--ERR_SPELL_FAILED_REAGENTS_GENERIC = "Missing reagent";
+	--ERR_INTERNAL_BAG_ERROR = "Internal Bag Error";
+	--SPELL_FAILED_ERROR = "Internal error";
 
 	-- Do not manage guild tradeskill
 	if IsTradeSkillGuild() or IsTradeSkillLinked() then return end
@@ -141,16 +145,22 @@
 			return
 		end
 
-		local numMakable, reagentIndex = A.numMakable(reagentID)
+		local reagentIndex = A.findSkillIndex(reagentID) -- finds only the first recipe that creates the reagent, should check recipe name too
 
 		-- Try to show the recipe by removing filters once if it was not found
 		if not reagentIndex then
 			A.SaveActiveFilters(A.data[reagentID][1].header)
-			numMakable, reagentIndex = A.numMakable(reagentID)
+			reagentIndex = A.findSkillIndex(reagentID)
+		end
+		if not reagentIndex then
+			A.Error(A.L["The recipe to make the reagent seems to be hidden, it is not makable. Try to remove the filters on the recipes."])
+			A.RestoreActiveFilters()
+			return
 		end
 
+		local numMakable = A.numMakable(reagentID)
 		if not numMakable then
-			A.Error(A.L["The recipe to make the reagent seems to be hidden, it is not makable. Try to remove the filters on the recipes."])
+			A.Error(A.L["There was a problem while retrieving informations, please retry."])
 			A.RestoreActiveFilters()
 			return
 		end
@@ -291,7 +301,8 @@
 		else
 			-- Count and show
 			local numMakable = A.numMakable(reagentID)
-			if not numMakable or #(A.data[reagentID]) ~= 1 or A.data[reagentID][1].macro then
+			--if not numMakable or #(A.data[reagentID]) ~= 1 or A.data[reagentID][1].macro then
+			if not numMakable then
 				label:SetText("?")
 				label:SetTextColor(0, 0.5, 1, 1) -- blue
 			else
--- a/SecureMenu.lua	Thu Jun 02 00:57:17 2011 +0200
+++ b/SecureMenu.lua	Thu Jun 02 14:12:06 2011 +0200
@@ -230,7 +230,7 @@
 			btn:SetScript("PreClick",WarnNotMakable)
 			btn:SetAttribute("type", nil)
 			btn:SetAttribute("macrotext", nil)
-			
+
 			btn.countDetail:SetTextColor(1, 0.1, 0.1, 1)
 			btn.icon:SetVertexColor(0.5, 0.5, 0.5)
 			btn.itemName:SetTextColor(1,1,1,0.5)
@@ -325,7 +325,7 @@
 function A.externalCraftWindow(itemID,superItemID)
 	-- Do not open during combat
 	if InCombatLockdown() then
-		A.Error(SPELL_FAILED_AFFECTING_COMBAT)		
+		A.Error(SPELL_FAILED_AFFECTING_COMBAT)
 		return
 	end
 
--- a/data.lua	Thu Jun 02 00:57:17 2011 +0200
+++ b/data.lua	Thu Jun 02 14:12:06 2011 +0200
@@ -9,6 +9,7 @@
 	-- lua functions
 	local print = print
 	local ipairs = ipairs
+	local pairs = pairs
 	local tinsert = tinsert
 	local select = select
 
@@ -38,8 +39,8 @@
 		if NRecipes==0 or select(2,GetTradeSkillInfo(1))~="header" then
 			return
 		end
-		
-		tradeskillName = GetTradeSkillLine()
+
+		local tradeskillName = GetTradeSkillLine()
 
 		-- Check if the pseudo tradeskills have to be added
 		if tradeskillName == GetSpellInfo(25229) then -- Jewelcrafting
@@ -76,9 +77,16 @@
 					-- reagent ID
 					reagentID = A.link2ID(GetTradeSkillReagentItemLink(i, 1))
 
-
 					-- reagent number needed
 					reagentCount = select(3,GetTradeSkillReagentInfo(i, 1))
+				else
+					-- no reagentID
+
+					-- contains data for the whole reagents
+					reagentCount = {}
+					for j = 1,numReagents do
+						tinsert(reagentCount,{A.link2ID(GetTradeSkillReagentItemLink(i, j)), select(3,GetTradeSkillReagentInfo(i, j))})
+					end
 				end
 
 				-- number of reagent created by the recipe
@@ -109,7 +117,7 @@
 							end -- if
 						end -- for
 					end -- if
-				
+
 					-- Cache the data
 					if addSpell then
 						local spell = {reagentID,reagentCount,minMade,maxMade}
--- a/utils.lua	Thu Jun 02 00:57:17 2011 +0200
+++ b/utils.lua	Thu Jun 02 14:12:06 2011 +0200
@@ -43,6 +43,7 @@
 	local GetTradeSkillItemLink = GetTradeSkillItemLink
 
 	-- Gives the number of craftable objects
+	--[[
 	function A.numMakable(reagentID)
 		-- Look for the recipe to make the item
 		local reagentIndex = A.findSkillIndex(reagentID)
@@ -52,6 +53,36 @@
 		local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex)
 		return numReagentMakable, reagentIndex
 	end
+	--]]
+	function A.numMakable(reagentID)
+		-- No recipe
+		if not A.data[reagentID] then return 0 end
+
+		-- Many recipes
+		local n = 0
+		local itemCount
+		for _,recipe in pairs(A.data[reagentID]) do
+			if recipe[1] then -- only one reagent
+				itemCount = GetItemCount(recipe[1])
+				if not itemCount then return end
+				n = n + math.floor(itemCount/recipe[2])
+			else -- many reagents
+				local m
+				for _,reagent in pairs(recipe[2]) do
+					itemCount = GetItemCount(reagent[1])
+					if not itemCount then return end
+					if not m then
+						m = math.floor(itemCount/reagent[2])
+					else
+						m = math.min(m,math.floor(itemCount/reagent[2]))
+					end
+					if m==0 then break end
+				end
+				n = n + m
+			end -- if
+		end -- for
+		return n
+	end -- function
 
 	-- Find the first tradeskill index of the recipe to make an item
 	function A.findSkillIndex(itemID)
@@ -77,40 +108,6 @@
 	local filtersState = {}
 	local headersState = {}
 
-	local function GetSubClassID()
-		-- The purpose of this function is to get the subClassID in a UI independant way
-		-- ie: without relying on UIDropDownMenu_GetSelectedID(TradeSkillSubClassDropDown), which uses a hardcoded frame name.
-
-		if GetTradeSkillSubClassFilter(0) then		-- if "All Subclasses" is selected, GetTradeSkillSubClassFilter() will return 1 for all indexes, including 0
-			return 1				-- thus return 1 as selected id	(as would be returned by UIDropDownMenu_GetSelectedID(TradeSkillSubClassDropDown))
-		end
-
-		local filter
-		for i = 1, #subClasses do
-			filter = GetTradeSkillSubClassFilter(i)
-			if filter then
-				return i+1			-- ex: 3rd element of the subClasses array, but 4th in the dropdown due to "All Subclasses", so return i+1
-			end
-		end
-	end
-
-	local function GetInvSlotID()
-		-- The purpose of this function is to get the invSlotID in a UI independant way	(same as GetSubClassID)
-		-- ie: without relying on UIDropDownMenu_GetSelectedID(TradeSkillInvSlotDropDown), which uses a hardcoded frame name.
-
-		if GetTradeSkillInvSlotFilter(0) then		-- if "All Slots" is selected, GetTradeSkillInvSlotFilter() will return 1 for all indexes, including 0
-			return 1				-- thus return 1 as selected id	(as would be returned by  UIDropDownMenu_GetSelectedID(TradeSkillInvSlotDropDown))
-		end
-
-		local filter
-		for i = 1, #invSlots do
-			filter = GetTradeSkillInvSlotFilter(i)
-			if filter then
-				return i+1			-- ex: 3rd element of the invSlots array, but 4th in the dropdown due to "All Slots", so return i+1
-			end
-		end
-	end
-
 	local function ApplyFilters()
 		TradeSkillOnlyShowSkillUps(TradeSkillFrame.filterTbl.hasSkillUp);
 		TradeSkillOnlyShowMakeable(TradeSkillFrame.filterTbl.hasMaterials);
@@ -124,12 +121,16 @@
 		A.blockScan = true
 
 		-- Save filters
+		filtersState.text = GetTradeSkillItemNameFilter()
+		filtersState.minLevel, filtersState.maxLevel = GetTradeSkillItemLevelFilter()
 		filtersState.hasMaterials = TradeSkillFrame.filterTbl.hasMaterials
 		filtersState.hasSkillUp = TradeSkillFrame.filterTbl.hasSkillUp
 		filtersState.subClassValue = TradeSkillFrame.filterTbl.subClassValue
 		filtersState.slotValue = TradeSkillFrame.filterTbl.slotValue
 
 		-- Remove all filters
+		SetTradeSkillItemNameFilter(nil)
+		SetTradeSkillItemLevelFilter(0, 0)
 		TradeSkillFrame.filterTbl.hasMaterials = false
 		TradeSkillFrame.filterTbl.hasSkillUp = false
 		TradeSkillFrame.filterTbl.subClassValue = -1
@@ -137,31 +138,28 @@
 		ApplyFilters()
 
 		-- Headers
-		--local headerCount = 0		-- use a counter to avoid being bound to header names, which might not be unique.
 		headersState.headerName = headerName
 		for i = GetNumTradeSkills(), 1, -1 do		-- 1st pass, expand all categories
 			local skillName, skillType, _, isExpanded  = GetTradeSkillInfo(i)
-				if (skillType == "header") and skillName==headerName then
-					if not isExpanded then
-						ExpandTradeSkillSubClass(i)
-						table.insert(headersState,true)
-					else
-						table.insert(headersState,false)
-					end
+			if (skillType == "header") and skillName==headerName then
+				if not isExpanded then
+					ExpandTradeSkillSubClass(i)
+					table.insert(headersState,true)
+				else
+					table.insert(headersState,false)
 				end
+			end
 		end
 
+		stateSaved = true
+		A.blockScan = nil
+
 		--@todo Scroll down to the selected recipe
 		-- with TradeSkillSkillXX:Show() ?
-
-		stateSaved = true
-
-		A.blockScan = nil
 	end
 
 	function A.RestoreActiveFilters()
 		if not stateSaved then return end
-
 		A.blockScan = true
 
 		-- restore headers
@@ -174,18 +172,19 @@
 		wipe(headersState)
 
 		-- restore filters
+		SetTradeSkillItemNameFilter(filtersState.text)
+		SetTradeSkillItemLevelFilter(filtersState.minLevel, filtersState.maxLevel)
 		TradeSkillFrame.filterTbl.hasMaterials = filtersState.hasMaterials
 		TradeSkillFrame.filterTbl.hasSkillUp = filtersState.hasSkillUp
 		TradeSkillFrame.filterTbl.subClassValue = filtersState.subClassValue
 		TradeSkillFrame.filterTbl.slotValue = filtersState.slotValue
 		ApplyFilters()
 
+		stateSaved = nil
+		A.blockScan = nil
 
-		--print("restored")
-
-		stateSaved = nil
-
-		A.blockScan = nil
+		--@todo Scroll down to the selected recipe
+		-- with TradeSkillSkillXX:Show() ?
 	end
 end