changeset 14:0fc8a54516d7

Altoholic is now marked as an optional dependency. Fixed the queue button so it doesn?t get recreated when a widget is re-used from the pool. Queue all button and queue single group buttons are now working. Items within a group being queued that couldn?t be found in the current profession will be announced. The goal is to put these into a new window from which you can queue these.
author Zerotorescue
date Mon, 18 Oct 2010 19:31:52 +0200
parents 5006cb0e97c6
children b11b3c0b5287
files Inventorium.toc Queue.lua Summary.lua
diffstat 3 files changed, 72 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Inventorium.toc	Mon Oct 18 15:26:42 2010 +0200
+++ b/Inventorium.toc	Mon Oct 18 19:31:52 2010 +0200
@@ -4,8 +4,7 @@
 ## Author: Zerotorescue
 ## Version: @project-version@
 ## SavedVariables: InventoriumDB
-## Dependencies: Altoholic
-## OptionalDeps: Auc-Advanced, Auc-ScanData, AdvancedTradeSkillWindow, Skillet, GnomeWorks, Auctionator
+## OptionalDeps: Altoholic, ItemCount, Auc-Advanced, Auc-ScanData, AdvancedTradeSkillWindow, Skillet, GnomeWorks, Auctionator
 
 embeds.xml
 
--- a/Queue.lua	Mon Oct 18 15:26:42 2010 +0200
+++ b/Queue.lua	Mon Oct 18 19:31:52 2010 +0200
@@ -266,30 +266,55 @@
 	addon:RegisterSlash(function()
 		self:QueueAll();
 	end, "q", "que", "queue");
+	
+	self:RegisterMessage("IM_QUEUE_ALL");
+	self:RegisterMessage("IM_QUEUE_GROUP");
+end
+
+function mod:IM_QUEUE_ALL()
+	self:QueueAll();
+end
+
+function mod:IM_QUEUE_GROUP(event, groupName)
+	self:QueueGroup(groupName);
 end
 
 function mod:QueueAll()
-	-- Go through all trade skills for the profession
-	for i = 1, GetNumTradeSkills() do
-		-- Go through all groups
-		for groupName, _ in pairs(addon.db.global.groups) do
-			-- Process every single tradeskill
-			self:ProcessTradeSkill(i, groupName);
+	local playerName = UnitName("player");
+	
+	-- Go through all groups
+	for groupName, values in pairs(addon.db.global.groups) do
+		local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
+		
+		if trackAt[playerName] then
+			self:QueueGroup(groupName);
 		end
 	end
 end
 
 function mod:QueueGroup(groupName)
-	if not addon.db.global.groups[groupName] then return false; end
+	if not addon.db.global.groups[groupName] then
+		print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName));
+		return;
+	end
+	
+	local temp = {};
 	
 	-- Go through all trade skills for the profession
 	for i = 1, GetNumTradeSkills() do
 		-- Process every single tradeskill
-		self:ProcessTradeSkill(i, groupName);
+		self:ProcessTradeSkill(i, groupName, temp);
+	end
+		
+	for itemId, _ in pairs(addon.db.global.groups[groupName].items) do
+		if not temp[itemId] then
+			local itemLink = select(2, GetItemInfo(itemId));
+			print("Couldn't queue " .. itemLink);
+		end
 	end
 end
 
-function mod:ProcessTradeSkill(i, groupName)
+function mod:ProcessTradeSkill(i, groupName, temp)
 	-- Try to retrieve the itemlink, this will be nil if current item is a group instead
 	local itemLink = GetTradeSkillItemLink(i);
 	
@@ -305,12 +330,23 @@
 		if addon.db.global.groups[groupName].items[itemId] then
 			-- This item is in this group, queue it!
 			
-			local amount = ( addon:GetOptionByKey(groupName, "restockTarget") - addon:GetItemCount(itemId) );
+			if temp then
+				-- Remember which items have been processed
+				temp[itemId] = true;
+			end
 			
-			if amount > 0 then
-				self:Queue(i, amount);
+			local currentStock = addon:GetItemCount(itemId);
+			if currentStock >= 0 then
+				-- Current stock will be -1 when no itemcount addon was found
+				local amount = ( addon:GetOptionByKey(groupName, "restockTarget") - currentStock );
 				
-				print("Queued " .. amount .. " of " .. itemLink);
+				if amount > 0 then
+					self:Queue(i, amount);
+					
+					print("Queued " .. amount .. " of " .. itemLink);
+				end
+			else
+				print("No usable itemcount addon found.");
 			end
 		end
 	end
--- a/Summary.lua	Mon Oct 18 15:26:42 2010 +0200
+++ b/Summary.lua	Mon Oct 18 19:31:52 2010 +0200
@@ -46,20 +46,27 @@
 	    
 	    widget.MakeButton = function(self, buttonSettings)
 			if type(buttonSettings) == "table" then
-				local button = CreateFrame("Button", nil, self.frame, "UIPanelButtonTemplate");
-				button:SetText(buttonSettings.name);
-				button:SetHeight(22);
-				button:SetWidth(120);
-				button:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5);
-				button:SetScript("OnClick", buttonSettings.exec);
-				button.tooltipTitle = buttonSettings.name;
-				button.tooltip = buttonSettings.desc or "";
-				button:SetScript("OnEnter", ShowTooltip);
-				button:SetScript("OnLeave", HideTooltip);
+				if not self.btnQueue then
+					-- Because widgets are re-used, we don't want to recreate this button
+					self.btnQueue = CreateFrame("Button", nil, self.frame, "UIPanelButtonTemplate");
+					self.btnQueue:SetHeight(22);
+					self.btnQueue:SetWidth(120);
+				end
+				self.btnQueue:SetText(buttonSettings.name);
+				self.btnQueue:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5);
+				
+				-- Triggers
+				self.btnQueue:SetScript("OnClick", buttonSettings.exec);
+				
+				-- Tooltip
+				self.btnQueue.tooltipTitle = buttonSettings.name;
+				self.btnQueue.tooltip = buttonSettings.desc or "";
+				self.btnQueue:SetScript("OnEnter", ShowTooltip);
+				self.btnQueue:SetScript("OnLeave", HideTooltip);
 			else
 				error("settings must be a table - usage: MakeButton(table);");
 			end
-	    end
+	    end;
 		
 	    return widget;
 	end
@@ -183,7 +190,7 @@
 	-- Speed slider
 	local sdrSpeed = AceGUI:Create("Slider");
 	sdrSpeed:SetLabel("Processing speed");
-	sdrSpeed:SetSliderValues(0.01, 5, 0.01);
+	sdrSpeed:SetSliderValues(0.01, 5, 0.05);
 	sdrSpeed:SetIsPercent(true);
 	sdrSpeed:SetRelativeWidth(.3);
 	sdrSpeed:SetCallback("OnMouseUp", function(self, event, value)
@@ -229,7 +236,7 @@
 	btnQueueAll:SetText("Queue All");
 	btnQueueAll:SetRelativeWidth(.2);
 	btnQueueAll:SetCallback("OnClick", function()
-		
+		self:SendMessage("IM_QUEUE_ALL");
 	end);
 	btnQueueAll:SetCallback("OnEnter", ShowTooltip);
 	btnQueueAll:SetCallback("OnLeave", HideTooltip);
@@ -270,7 +277,8 @@
 				name = "Queue",
 				desc = "Queue all items in this group.",
 				exec = function()
-					print(groupName);
+					print("Queueing all items within " .. groupName .. " craftable by the currently open profession.");
+					self:SendMessage("IM_QUEUE_GROUP", groupName);
 				end,
 			});