diff Modules/Queue.lua @ 145:6a52272a0e5a

Added a craft button to the queue window. This is still very experimental.
author Zerotorescue
date Thu, 20 Jan 2011 00:07:47 +0100
parents 12a8ea5af671
children ebe6f90c4bb9
line wrap: on
line diff
--- a/Modules/Queue.lua	Wed Jan 19 23:21:16 2011 +0100
+++ b/Modules/Queue.lua	Thu Jan 20 00:07:47 2011 +0100
@@ -45,6 +45,30 @@
 	},
 };
 
+local function Compare(a, b, this, aRow, bRow, columnNo)
+	if a == b then
+		local column = this.cols[columnNo];
+		if column.sortnext then
+			local nextcol = this.cols[column.sortnext];
+			if not(nextcol.sort) then 
+				if nextcol.comparesort then 
+					return nextcol.comparesort(this, aRow, bRow, column.sortnext);
+				else
+					return this:CompareSort(this, bRow, column.sortnext);
+				end
+			else
+				return false;
+			end
+		else
+			return false; 
+		end 
+	elseif (this.cols[columnNo].sort or this.cols[columnNo].defaultsort or "asc") == "dsc" then
+		return a > b;
+	else
+		return a < b;
+	end
+end
+
 local function MakeQueueWindow()
 	if not InventoriumQueuer then
 		addon:CreateQueueFrame();
@@ -58,18 +82,13 @@
 				["name"] = "Item",
 				["width"] = (scrollTableWidth * .65),
 				["defaultsort"] = "asc",
-				["comparesort"] = function(this, aRow, bRow, column)
+				["comparesort"] = function(this, aRow, bRow, columnNo)
 					local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId);
 					local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId);
-					local template = "%d%s";
-					aName = sformat(template, (10 - (aRarity or 10)), slower(aName or ""));
-					bName = sformat(template, (10 - (bRarity or 10)), slower(bName or ""));
+					aName = sformat("%d%s", (10 - (aRarity or 10)), slower(aName or ""));
+					bName = sformat("%d%s", (10 - (bRarity or 10)), slower(bName or ""));
 					
-					if this.cols[column].sort == "dsc" then
-						return aName > bName;
-					else
-						return aName < bName;
-					end
+					return Compare(aName, bName, this, aRow, bRow, columnNo);
 				end,
 				["sort"] = "asc", -- when the data is set, use this column so sort the default data
 				["tooltipTitle"] = "Item",
@@ -80,12 +99,11 @@
 				["width"] = (scrollTableWidth * .15),
 				["align"] = "RIGHT",
 				["defaultsort"] = "dsc",
-				["comparesort"] = function(this, aRow, bRow, column)
-					if this.cols[column].sort == "dsc" then
-						return (this:GetRow(aRow).rowData.amount > this:GetRow(bRow).rowData.amount);
-					else
-						return (this:GetRow(aRow).rowData.amount < this:GetRow(bRow).rowData.amount);
-					end
+				["comparesort"] = function(this, aRow, bRow, columnNo)
+					local a = this:GetRow(aRow).rowData.amount;
+					local b = this:GetRow(bRow).rowData.amount;
+					
+					return Compare(a, b, this, aRow, bRow, columnNo);
 				end,
 				["sortnext"] = 1,
 				["tooltipTitle"] = "Amount needed",
@@ -96,12 +114,11 @@
 				["width"] = (scrollTableWidth * .15),
 				["align"] = "RIGHT",
 				["defaultsort"] = "dsc",
-				["comparesort"] = function(this, aRow, bRow, column)
-					if this.cols[column].sort == "dsc" then
-						return (this:GetRow(aRow).rowData.bonus > this:GetRow(bRow).rowData.bonus);
-					else
-						return (this:GetRow(aRow).rowData.bonus < this:GetRow(bRow).rowData.bonus);
-					end
+				["comparesort"] = function(this, aRow, bRow, columnNo)
+					local a = this:GetRow(aRow).rowData.bonus;
+					local b = this:GetRow(bRow).rowData.bonus;
+					
+					return Compare(a, b, this, aRow, bRow, columnNo);
 				end,
 				["sortnext"] = 1,
 				["tooltipTitle"] = "Extra items",
@@ -137,18 +154,13 @@
 				["name"] = "Item",
 				["width"] = (scrollTableWidth * .6),
 				["defaultsort"] = "asc",
-				["comparesort"] = function(this, aRow, bRow, column)
+				["comparesort"] = function(this, aRow, bRow, columnNo)
 					local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId);
 					local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId);
-					local template = "%d%s";
-					aName = sformat(template, (10 - (aRarity or 10)), slower(aName or ""));
-					bName = sformat(template, (10 - (bRarity or 10)), slower(bName or ""));
+					aName = sformat("%d%s", (10 - (aRarity or 10)), slower(aName or ""));
+					bName = sformat("%d%s", (10 - (bRarity or 10)), slower(bName or ""));
 					
-					if this.cols[column].sort == "dsc" then
-						return aName > bName;
-					else
-						return aName < bName;
-					end
+					return Compare(aName, bName, this, aRow, bRow, columnNo);
 				end,
 				["tooltipTitle"] = "Item",
 				["tooltip"] = "Click to sort the list by item quality then item name.",
@@ -157,12 +169,11 @@
 				["name"] = "Reason",
 				["width"] = (scrollTableWidth * .4),
 				["defaultsort"] = "dsc",
-				["comparesort"] = function(this, aRow, bRow, column)
-					if this.cols[column].sort == "dsc" then
-						return this:GetRow(aRow).rowData.reason[3] > this:GetRow(bRow).rowData.reason[3];
-					else
-						return this:GetRow(aRow).rowData.reason[3] < this:GetRow(bRow).rowData.reason[3];
-					end
+				["comparesort"] = function(this, aRow, bRow, columnNo)
+					local a = this:GetRow(aRow).rowData.reason[3];
+					local b = this:GetRow(bRow).rowData.reason[3];
+					
+					return Compare(a, b, this, aRow, bRow, columnNo);
 				end,
 				["sort"] = "dsc", -- when the data is set, use this column to sort the default data
 				["sortnext"] = 1,
@@ -183,8 +194,14 @@
 			tooltip = "Do not queue anything and close the window.",
 			onClick = function() mod:QueueAbort(); end,
 		};
+		local craftButton = {
+			text = "Craft",
+			tooltipTitle = "Craft",
+			tooltip = "Start crafting the first item.",
+			onClick = function() mod:StartCrafting(); end,
+		};
 		
-		addon:SetQueueFrameSettings("Inventorium Queue", "The following items can be added to the queue of your crafting addon. Do you wish to proceed?", proceedButton, cancelButton, headers, unqueueablesHeaders);
+		addon:SetQueueFrameSettings("Inventorium Queue", "The following items can be added to the queue of your crafting addon. Do you wish to proceed?", proceedButton, cancelButton, craftButton, headers, unqueueablesHeaders);
 	end
 end
 
@@ -268,19 +285,21 @@
 		
 		local selectedIndex = frame.scrollTable:GetSelection(); -- gets realrow index
 		
-		addon:Debug("%d was selected.", tostring(selectedIndex));
+		addon:Debug("%s was selected.", tostring(selectedIndex));
 		
 		if not selectedIndex then
 			-- Select the top most element (scrolltable with index of 1 will contain a index of the related realrow of the data table)
 			selectedIndex = ((frame.scrollTable.sorttable and frame.scrollTable.sorttable[1]) or 1);
 			
-			addon:Debug("%d should be the top record.", tostring(selectedIndex));
+			addon:Debug("%s should be the top record.", tostring(selectedIndex));
 		end
 		
-		local nextQueue = frame.scrollTable.data[selectedIndex] or frame.scrollTable.data[1]; -- if the selected index still fails, try to get the first record
+		local nextQueue = frame.scrollTable.data[selectedIndex].rowData or frame.scrollTable.data[1].rowData; -- if the selected index still fails, try to get the first record
 		
 		if nextQueue then
 			if not test then
+				self:ResetTradeSkillFilters();
+				
 				-- Initiate spell (test will be used while debugging to fake crafts)
 				DoTradeSkill(nextQueue.craft.no, ceil(nextQueue.amount / nextQueue.craft.quantity));
 			end
@@ -585,8 +604,15 @@
 end
 
 do -- Trade skill recipes region
-	-- Expand all categories so no crafts are hidden
-	local function ExpandSubClasses()
+	-- Reset all filters so no crafts are hidden
+	function mod:ResetTradeSkillFilters()
+		SetTradeSkillSubClassFilter(0, 1, 1);
+		SetTradeSkillItemNameFilter("");
+		SetTradeSkillItemLevelFilter(0, 0);
+		TradeSkillOnlyShowSkillUps(false);
+		TradeSkillOnlyShowMakeable(false);
+		
+		-- Expand all categories so no crafts are hidden
 		for i = GetNumTradeSkills(), 1, -1 do
 			local _, skillType, _, isExpanded = GetTradeSkillInfo(i);
 
@@ -596,22 +622,12 @@
 		end
 	end
 
-	-- Reset all filters so no crafts are hidden
-	local function ResetFilters()
-		SetTradeSkillSubClassFilter(0, 1, 1);
-		SetTradeSkillItemNameFilter("");
-		SetTradeSkillItemLevelFilter(0, 0);
-		TradeSkillOnlyShowSkillUps(false);
-		TradeSkillOnlyShowMakeable(false);
-	end
-
 	-- Get all craftable items into a table. Each record contains "no", "spellId" and "quantity". The last is the average amount made per craft.
 	function mod:GetTradeskillCraftables()
 		local craftables = {};
 		
 		if GetTradeSkillLine() ~= "UNKNOWN" then
-			ExpandSubClasses();
-			ResetFilters();
+			self:ResetTradeSkillFilters();
 			
 			-- Cache all craftable items
 			for i = 1, GetNumTradeSkills() do