diff Queue.lua @ 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 8f5c02113c5c
line wrap: on
line diff
--- 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