comparison 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
comparison
equal deleted inserted replaced
13:5006cb0e97c6 14:0fc8a54516d7
264 function mod:OnEnable() 264 function mod:OnEnable()
265 -- Register our own slash commands 265 -- Register our own slash commands
266 addon:RegisterSlash(function() 266 addon:RegisterSlash(function()
267 self:QueueAll(); 267 self:QueueAll();
268 end, "q", "que", "queue"); 268 end, "q", "que", "queue");
269
270 self:RegisterMessage("IM_QUEUE_ALL");
271 self:RegisterMessage("IM_QUEUE_GROUP");
272 end
273
274 function mod:IM_QUEUE_ALL()
275 self:QueueAll();
276 end
277
278 function mod:IM_QUEUE_GROUP(event, groupName)
279 self:QueueGroup(groupName);
269 end 280 end
270 281
271 function mod:QueueAll() 282 function mod:QueueAll()
272 -- Go through all trade skills for the profession 283 local playerName = UnitName("player");
273 for i = 1, GetNumTradeSkills() do 284
274 -- Go through all groups 285 -- Go through all groups
275 for groupName, _ in pairs(addon.db.global.groups) do 286 for groupName, values in pairs(addon.db.global.groups) do
276 -- Process every single tradeskill 287 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
277 self:ProcessTradeSkill(i, groupName); 288
289 if trackAt[playerName] then
290 self:QueueGroup(groupName);
278 end 291 end
279 end 292 end
280 end 293 end
281 294
282 function mod:QueueGroup(groupName) 295 function mod:QueueGroup(groupName)
283 if not addon.db.global.groups[groupName] then return false; end 296 if not addon.db.global.groups[groupName] then
297 print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName));
298 return;
299 end
300
301 local temp = {};
284 302
285 -- Go through all trade skills for the profession 303 -- Go through all trade skills for the profession
286 for i = 1, GetNumTradeSkills() do 304 for i = 1, GetNumTradeSkills() do
287 -- Process every single tradeskill 305 -- Process every single tradeskill
288 self:ProcessTradeSkill(i, groupName); 306 self:ProcessTradeSkill(i, groupName, temp);
289 end 307 end
290 end 308
291 309 for itemId, _ in pairs(addon.db.global.groups[groupName].items) do
292 function mod:ProcessTradeSkill(i, groupName) 310 if not temp[itemId] then
311 local itemLink = select(2, GetItemInfo(itemId));
312 print("Couldn't queue " .. itemLink);
313 end
314 end
315 end
316
317 function mod:ProcessTradeSkill(i, groupName, temp)
293 -- Try to retrieve the itemlink, this will be nil if current item is a group instead 318 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
294 local itemLink = GetTradeSkillItemLink(i); 319 local itemLink = GetTradeSkillItemLink(i);
295 320
296 if itemLink then 321 if itemLink then
297 local itemId = addon:GetItemId(itemLink); 322 local itemId = addon:GetItemId(itemLink);
303 end 328 end
304 329
305 if addon.db.global.groups[groupName].items[itemId] then 330 if addon.db.global.groups[groupName].items[itemId] then
306 -- This item is in this group, queue it! 331 -- This item is in this group, queue it!
307 332
308 local amount = ( addon:GetOptionByKey(groupName, "restockTarget") - addon:GetItemCount(itemId) ); 333 if temp then
334 -- Remember which items have been processed
335 temp[itemId] = true;
336 end
309 337
310 if amount > 0 then 338 local currentStock = addon:GetItemCount(itemId);
311 self:Queue(i, amount); 339 if currentStock >= 0 then
340 -- Current stock will be -1 when no itemcount addon was found
341 local amount = ( addon:GetOptionByKey(groupName, "restockTarget") - currentStock );
312 342
313 print("Queued " .. amount .. " of " .. itemLink); 343 if amount > 0 then
344 self:Queue(i, amount);
345
346 print("Queued " .. amount .. " of " .. itemLink);
347 end
348 else
349 print("No usable itemcount addon found.");
314 end 350 end
315 end 351 end
316 end 352 end
317 end 353 end
318 354