diff utils.lua @ 107:d64a19e5a47d

Bypass the filtering. Not fully tested, but mostly works.
author contrebasse
date Thu, 02 Jun 2011 00:57:17 +0200
parents 8dd86b6b76d8
children 618163a6d970
line wrap: on
line diff
--- a/utils.lua	Tue May 31 00:57:27 2011 +0200
+++ b/utils.lua	Thu Jun 02 00:57:17 2011 +0200
@@ -73,9 +73,8 @@
 -- *** Scanning functions ***
 do
 	local selectedTradeSkillIndex
-	local subClasses, subClassID
-	local invSlots, invSlotID
-	local haveMats
+	local stateSaved
+	local filtersState = {}
 	local headersState = {}
 
 	local function GetSubClassID()
@@ -112,125 +111,87 @@
 		end
 	end
 
+	local function ApplyFilters()
+		TradeSkillOnlyShowSkillUps(TradeSkillFrame.filterTbl.hasSkillUp);
+		TradeSkillOnlyShowMakeable(TradeSkillFrame.filterTbl.hasMaterials);
+		SetTradeSkillSubClassFilter(TradeSkillFrame.filterTbl.subClassValue, 1, 1);
+		SetTradeSkillInvSlotFilter(TradeSkillFrame.filterTbl.slotValue, 1, 1);
+		TradeSkillUpdateFilterBar();
+		CloseDropDownMenus();
+	end
+
 	function A.SaveActiveFilters(headerName)
 		A.blockScan = true
 
-		--[[
-		print("save")
-		print(GetNumTradeSkills())
-		selectedTradeSkillIndex = GetTradeSkillSelectionIndex()
+		-- Save filters
+		filtersState.hasMaterials = TradeSkillFrame.filterTbl.hasMaterials
+		filtersState.hasSkillUp = TradeSkillFrame.filterTbl.hasSkillUp
+		filtersState.subClassValue = TradeSkillFrame.filterTbl.subClassValue
+		filtersState.slotValue = TradeSkillFrame.filterTbl.slotValue
 
-		subClasses = { GetTradeSkillSubClasses() }
-		invSlots = { GetTradeSkillInvSlots() }
-		subClassID = GetSubClassID()
-		invSlotID = GetInvSlotID()
-
-		-- Subclasses
-		SetTradeSkillSubClassFilter(0, 1, 1)	-- this checks "All subclasses"
-		if TradeSkillSubClassDropDown then
-			UIDropDownMenu_SetSelectedID(TradeSkillSubClassDropDown, 1)
-		end
-		print(GetNumTradeSkills())
-
-		-- Inventory slots
-		SetTradeSkillInvSlotFilter(0, 1, 1)		-- this checks "All slots"
-		if TradeSkillInvSlotDropDown then
-			UIDropDownMenu_SetSelectedID(TradeSkillInvSlotDropDown, 1)
-		end
-		print(GetNumTradeSkills())
-
-		-- Have Materials
-		if TradeSkillFrameAvailableFilterCheckButton then
-			haveMats = TradeSkillFrameAvailableFilterCheckButton:GetChecked()	-- nil or true
-			TradeSkillFrameAvailableFilterCheckButton:SetChecked(false)
-		end
-		TradeSkillOnlyShowMakeable(false)
-		print(GetNumTradeSkills())
-		--]]
+		-- Remove all filters
+		TradeSkillFrame.filterTbl.hasMaterials = false
+		TradeSkillFrame.filterTbl.hasSkillUp = false
+		TradeSkillFrame.filterTbl.subClassValue = -1
+		TradeSkillFrame.filterTbl.slotValue = -1
+		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") then
-				--headerCount = headerCount + 1
-				if not isExpanded and skillName==headerName then
-					ExpandTradeSkillSubClass(i)
-					--print(GetNumTradeSkills())
-					--headersState[headerCount] = true
+				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
 		end
 
-		--print("saved")
+		--@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
 
-		print("restore")
-		-- Subclasses
-		SetTradeSkillSubClassFilter(subClassID-1, 1, 1)	-- this checks the previously checked value
-
-		local frame = TradeSkillSubClassDropDown
-		if frame then	-- other addons might nil this frame (delayed load, etc..), so secure DDM calls
-			local text = (subClassID == 1) and ALL_SUBCLASSES or subClasses[subClassID-1]
-			UIDropDownMenu_SetSelectedID(frame, subClassID)
-			UIDropDownMenu_SetText(frame, text);
-		end
-
-		subClassID = nil
-		wipe(subClasses)
-		subClasses = nil
-
-		-- Inventory slots
-		invSlotID = invSlotID or 1
-		SetTradeSkillInvSlotFilter(invSlotID-1, 1, 1)	-- this checks the previously checked value
-
-		frame = TradeSkillInvSlotDropDown
-		if frame then
-			local text = (invSlotID == 1) and ALL_INVENTORY_SLOTS or invSlots[invSlotID-1]
-			UIDropDownMenu_SetSelectedID(frame, invSlotID)
-			UIDropDownMenu_SetText(frame, text);
-		end
-
-		invSlotID = nil
-		wipe(invSlots)
-		invSlots = nil
-
-		-- Have Materials
-		if TradeSkillFrameAvailableFilterCheckButton then
-			TradeSkillFrameAvailableFilterCheckButton:SetChecked(haveMats or false)
-		end
-		TradeSkillOnlyShowMakeable(haveMats or false)
-		haveMats = nil
-
-		SelectTradeSkill(selectedTradeSkillIndex)
-		selectedTradeSkillIndex = nil
-
-		-- Headers
-		local headerCount = 0
+		-- restore headers
 		for i = GetNumTradeSkills(), 1, -1 do
-			local _, skillType  = GetTradeSkillInfo(i)
-			if (skillType == "header") then
-				headerCount = headerCount + 1
-				if headersState[headerCount] then
+			local skillName, skillType  = GetTradeSkillInfo(i)
+			if (skillType == "header") and skillName==headersState.headerName and table.remove(headersState,1) then
 					CollapseTradeSkillSubClass(i)
-				end
 			end
 		end
 		wipe(headersState)
+
+		-- restore filters
+		TradeSkillFrame.filterTbl.hasMaterials = filtersState.hasMaterials
+		TradeSkillFrame.filterTbl.hasSkillUp = filtersState.hasSkillUp
+		TradeSkillFrame.filterTbl.subClassValue = filtersState.subClassValue
+		TradeSkillFrame.filterTbl.slotValue = filtersState.slotValue
+		ApplyFilters()
+
+
+		--print("restored")
+
+		stateSaved = nil
+
+		A.blockScan = nil
 	end
-	print("restored")
-	
-	A.blockScan = nil
 end
 
 function A.isRecipeUnique(itemData)
 	local unique = true
-	
+
 	-- Check if the item is made by only one recipe. If not, return
 	if #itemData>1 then
 		local spellLink
@@ -245,14 +206,14 @@
 			end
 		end
 	end
-	
+
 	return unique
 end
 
 --[[
 function A.isTradeskillUnique(itemData)
 	local spellName = itemData[1].spellName
-	
+
 	-- Check if the item is made by only one recipe. If not, return
 	if #itemData>1 then
 		for _,v in ipairs(itemData) do
@@ -265,4 +226,4 @@
 
 	return spellName
 end
---]]
\ No newline at end of file
+--]]