Mercurial > wow > inventory
comparison Modules/Queue.lua @ 144:12a8ea5af671
Added a ?remove? button to the crafting queue.
When removing an item from the queue or when it is finished casting (when using the Inventorium queue processer), items are moved to the ?unqueuables? window.
Fixed auction price checking.
Now resetting filters before scanning the tradeskill recipes.
author | Zerotorescue |
---|---|
date | Wed, 19 Jan 2011 23:21:16 +0100 |
parents | 8eb0f5b5a885 |
children | 6a52272a0e5a |
comparison
equal
deleted
inserted
replaced
143:8eb0f5b5a885 | 144:12a8ea5af671 |
---|---|
1 local addon = select(2, ...); | 1 local addon = select(2, ...); |
2 local mod = addon:NewModule("Queue", "AceEvent-3.0", "AceTimer-3.0"); | 2 local mod = addon:NewModule("Queue", "AceEvent-3.0", "AceTimer-3.0"); |
3 | 3 |
4 local _G = _G; | 4 local _G = _G; |
5 local tonumber, pairs, sformat, smatch, slower, floor, ceil, tinsert, twipe = _G.tonumber, _G.pairs, _G.string.format, _G.string.match, _G.string.lower, _G.floor, _G.ceil, _G.table.insert, _G.table.wipe; | 5 local tonumber, tostring, pairs, sformat, smatch, slower, floor, ceil, tinsert, twipe = _G.tonumber, _G.tostring, _G.pairs, _G.string.format, _G.string.match, _G.string.lower, _G.floor, _G.ceil, _G.table.insert, _G.table.wipe; |
6 | 6 |
7 local queue, skipped = {}, {}; | 7 local queue, skipped = {}, {}; |
8 | 8 |
9 -- strings are passed by reference, so it takes no additional memory if one string was used in a thousand tables compared to any other reference type | 9 -- strings are passed by reference, so it takes no additional memory if one string was used in a thousand tables compared to any other reference type |
10 local skipReasons = { | 10 local skipReasons = { |
31 ["NO_ITEMCOUNT_ADDON"] = { | 31 ["NO_ITEMCOUNT_ADDON"] = { |
32 "|cffff0000No itemcount addon|r", -- red | 32 "|cffff0000No itemcount addon|r", -- red |
33 "No compatible item count could be found.", | 33 "No compatible item count could be found.", |
34 20, | 34 20, |
35 }, | 35 }, |
36 ["REMOVED"] = { -- because this is updated realtime, it is most useful around the top of the list | |
37 "|cffff0000Removed|r", -- red | |
38 "You manually removed this item from the queue.", | |
39 45, | |
40 }, | |
41 ["FINISHED"] = { -- because this is updated realtime, it is most useful on the top of the list | |
42 "|cff00ff00Just finished|r", -- green | |
43 "Just finished restocking this item.", | |
44 50, | |
45 }, | |
36 }; | 46 }; |
37 | |
38 local function OnQueueCancel() | |
39 twipe(queue); | |
40 twipe(skipped); | |
41 | |
42 if InventoriumQueuer then | |
43 InventoriumQueuer:Hide(); | |
44 end | |
45 end | |
46 | |
47 local function OnQueueAccept() | |
48 -- Prepare a table with all possible tradeskill craftables | |
49 local craftables = mod:GetTradeskillCraftables(); | |
50 | |
51 for _, q in pairs(queue) do | |
52 if craftables[q.itemId] then | |
53 if mod:QueueWithAddon(craftables[q.itemId].no, ceil(q.amount / craftables[q.itemId].quantity), q.groupName) == -1 then | |
54 addon:Print("Couldn't queue, no supported crafting addon found.", addon.Colors.Red); | |
55 | |
56 OnQueueCancel(); | |
57 return; | |
58 else | |
59 -- Update the crafted-item count | |
60 for groupName, values in pairs(addon.db.profile.groups) do | |
61 if values.items and values.items[q.itemId] then | |
62 values.items[q.itemId] = (tonumber(values.items[q.itemId]) or 0) + 1; | |
63 break; | |
64 end | |
65 end | |
66 end | |
67 else | |
68 addon:Debug("Lost %s", IdToItemLink(q.itemId)); | |
69 end | |
70 end | |
71 | |
72 twipe(queue); | |
73 twipe(skipped); | |
74 | |
75 if InventoriumQueuer then | |
76 InventoriumQueuer:Hide(); | |
77 end | |
78 end | |
79 | |
80 | |
81 --[[Allowing the queue window to actually initiate crafts is going to be a likely feature. | |
82 do | |
83 -- Start crafting the selected skill (or the first in line) | |
84 local function StartSelectedCraft() | |
85 local craftables = mod:GetTradeskillCraftables(); | |
86 | |
87 for _, q in pairs(queue) do | |
88 if craftables[q.itemId] then | |
89 DoTradeSkill(craftables[q.itemId].no, ceil(q.amount / craftables[q.itemId].quantity)); | |
90 return; | |
91 end | |
92 end | |
93 end | |
94 | |
95 -- Remove from queue and if it was selected, auto-select the next | |
96 local function CraftFinished() | |
97 | |
98 end | |
99 | |
100 -- Refresh the item count for this item | |
101 local function RefreshItem() | |
102 q.amount = mod:GetRestockAmount(q.itemId, q.groupName); | |
103 | |
104 if q.amount < 1 then | |
105 table.remove(crafts, i); | |
106 end | |
107 | |
108 DisplayQueue(); | |
109 end | |
110 | |
111 local function OnSpellFinished(event, unit, spellName, _, _, spellId) | |
112 if unit == "player" then | |
113 for i, q in pairs(queue) do | |
114 if q.craft.spellId == spellId then | |
115 -- We just finished this spell | |
116 | |
117 print("pass"); | |
118 | |
119 | |
120 return; | |
121 end | |
122 end | |
123 end | |
124 end | |
125 function Test() OnSpellFinished("SomeSpell", "player", "Delicate Inferno Ruby", nil, nil, 55400); end | |
126 | |
127 tinsert(queue, { | |
128 ["itemId"] = itemId, -- needed to display the queued item in the queue window | |
129 ["amount"] = amount, -- the amount missing | |
130 ["bonus"] = bonus, -- the amount queued by the bonus queue | |
131 ["craft"] = craft, -- (craftable) - needed to find the proper element of this parent array when crafting has finished (spellId), and to update the numCrafts (quantity) | |
132 ["groupName"] = groupName, -- related group, needed to find the selected crafting addon | |
133 }); | |
134 [1] = “player”; | |
135 [2] = “Delicate Inferno Ruby”; | |
136 [3] = “”; | |
137 [4] = 19; | |
138 [5] = 73336; | |
139 arg1 | |
140 Unit casting the spell - "player" | |
141 arg2 | |
142 Spell name - "“Delicate Inferno Ruby”" | |
143 arg3 | |
144 Spell rank (deprecated in 4.0) - "" | |
145 arg4 | |
146 Spell lineID counter - 19 | |
147 arg5 | |
148 Spell ID (added in 4.0) - 73336 | |
149 | |
150 end]] | |
151 | 47 |
152 local function MakeQueueWindow() | 48 local function MakeQueueWindow() |
153 if not InventoriumQueuer then | 49 if not InventoriumQueuer then |
154 addon:CreateQueueFrame(); | 50 addon:CreateQueueFrame(); |
155 | 51 |
158 -- Scrolling table with a list of items to be moved | 54 -- Scrolling table with a list of items to be moved |
159 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size | 55 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size |
160 local headers = { | 56 local headers = { |
161 { | 57 { |
162 ["name"] = "Item", | 58 ["name"] = "Item", |
163 ["width"] = (scrollTableWidth * .60), | 59 ["width"] = (scrollTableWidth * .65), |
164 ["defaultsort"] = "asc", | 60 ["defaultsort"] = "asc", |
165 ["comparesort"] = function(this, aRow, bRow, column) | 61 ["comparesort"] = function(this, aRow, bRow, column) |
166 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId); | 62 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId); |
167 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId); | 63 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId); |
168 local template = "%d%s"; | 64 local template = "%d%s"; |
174 else | 70 else |
175 return aName < bName; | 71 return aName < bName; |
176 end | 72 end |
177 end, | 73 end, |
178 ["sort"] = "asc", -- when the data is set, use this column so sort the default data | 74 ["sort"] = "asc", -- when the data is set, use this column so sort the default data |
179 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"), | 75 ["tooltipTitle"] = "Item", |
180 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."), | 76 ["tooltip"] = "Click to sort the list by item quality then item name.", |
181 }, | 77 }, |
182 { | 78 { |
183 ["name"] = "Amount", | 79 ["name"] = "Amount", |
184 ["width"] = (scrollTableWidth * .20), | 80 ["width"] = (scrollTableWidth * .15), |
185 ["align"] = "RIGHT", | 81 ["align"] = "RIGHT", |
186 ["defaultsort"] = "dsc", | 82 ["defaultsort"] = "dsc", |
187 ["comparesort"] = function(this, aRow, bRow, column) | 83 ["comparesort"] = function(this, aRow, bRow, column) |
188 if this.cols[column].sort == "dsc" then | 84 if this.cols[column].sort == "dsc" then |
189 return (this:GetRow(aRow).rowData.amount > this:GetRow(bRow).rowData.amount); | 85 return (this:GetRow(aRow).rowData.amount > this:GetRow(bRow).rowData.amount); |
190 else | 86 else |
191 return (this:GetRow(aRow).rowData.amount < this:GetRow(bRow).rowData.amount); | 87 return (this:GetRow(aRow).rowData.amount < this:GetRow(bRow).rowData.amount); |
192 end | 88 end |
193 end, | 89 end, |
194 ["sortnext"] = 1, | 90 ["sortnext"] = 1, |
195 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Amount needed"), | 91 ["tooltipTitle"] = "Amount needed", |
196 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of items needed to reach the restock target."), | 92 ["tooltip"] = "Click to sort the list by the amount of items needed to reach the restock target.", |
197 }, | 93 }, |
198 { | 94 { |
199 ["name"] = "Extra", | 95 ["name"] = "Extra", |
200 ["width"] = (scrollTableWidth * .20), | 96 ["width"] = (scrollTableWidth * .15), |
201 ["align"] = "RIGHT", | 97 ["align"] = "RIGHT", |
202 ["defaultsort"] = "dsc", | 98 ["defaultsort"] = "dsc", |
203 ["comparesort"] = function(this, aRow, bRow, column) | 99 ["comparesort"] = function(this, aRow, bRow, column) |
204 if this.cols[column].sort == "dsc" then | 100 if this.cols[column].sort == "dsc" then |
205 return (this:GetRow(aRow).rowData.bonus > this:GetRow(bRow).rowData.bonus); | 101 return (this:GetRow(aRow).rowData.bonus > this:GetRow(bRow).rowData.bonus); |
206 else | 102 else |
207 return (this:GetRow(aRow).rowData.bonus < this:GetRow(bRow).rowData.bonus); | 103 return (this:GetRow(aRow).rowData.bonus < this:GetRow(bRow).rowData.bonus); |
208 end | 104 end |
209 end, | 105 end, |
210 ["sortnext"] = 1, | 106 ["sortnext"] = 1, |
211 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Extra items"), | 107 ["tooltipTitle"] = "Extra items", |
212 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of bonus items."), | 108 ["tooltip"] = "Click to sort the list by the amount of bonus items.", |
109 }, | |
110 { | |
111 ["name"] = "X", | |
112 ["width"] = (scrollTableWidth * .05), | |
113 ["align"] = "CENTER", | |
114 ["sortnext"] = 1, | |
115 ["tooltipTitle"] = "Remove", | |
116 ["tooltip"] = "Click any of the fields in this column to remove this item from the queue.", | |
117 ["onClick"] = function(rowData) | |
118 -- Remove this element from the queue | |
119 for index, q in pairs(queue) do | |
120 if q == rowData then | |
121 table.remove(queue, index); | |
122 mod:Skip(q.itemId, skipReasons.REMOVED); | |
123 break; | |
124 end | |
125 end | |
126 | |
127 -- Rebuild our scrolltable (records were removed and added) | |
128 mod:BuildQueue(); | |
129 end, | |
130 ["color"] = { ["r"] = 1.0, ["g"] = 0.0, ["b"] = 0.0, ["a"] = 1, }, | |
213 }, | 131 }, |
214 }; | 132 }; |
215 | 133 |
216 local scrollTableWidth = ( InventoriumQueuerUnqueueables.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size | 134 local scrollTableWidth = ( InventoriumQueuerUnqueueables.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size |
217 local unqueueablesHeaders = { | 135 local unqueueablesHeaders = { |
230 return aName > bName; | 148 return aName > bName; |
231 else | 149 else |
232 return aName < bName; | 150 return aName < bName; |
233 end | 151 end |
234 end, | 152 end, |
235 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"), | 153 ["tooltipTitle"] = "Item", |
236 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."), | 154 ["tooltip"] = "Click to sort the list by item quality then item name.", |
237 }, | 155 }, |
238 { | 156 { |
239 ["name"] = "Reason", | 157 ["name"] = "Reason", |
240 ["width"] = (scrollTableWidth * .4), | 158 ["width"] = (scrollTableWidth * .4), |
241 ["defaultsort"] = "dsc", | 159 ["defaultsort"] = "dsc", |
242 ["comparesort"] = function(this, aRow, bRow, column) | 160 ["comparesort"] = function(this, aRow, bRow, column) |
243 local result = (this:GetRow(aRow).rowData.reason[3] > this:GetRow(bRow).rowData.reason[3]); | |
244 | |
245 if this.cols[column].sort == "dsc" then | 161 if this.cols[column].sort == "dsc" then |
246 return result; | 162 return this:GetRow(aRow).rowData.reason[3] > this:GetRow(bRow).rowData.reason[3]; |
247 else | 163 else |
248 return (not result); | 164 return this:GetRow(aRow).rowData.reason[3] < this:GetRow(bRow).rowData.reason[3]; |
249 end | 165 end |
250 end, | 166 end, |
251 ["sort"] = "dsc", -- when the data is set, use this column to sort the default data | 167 ["sort"] = "dsc", -- when the data is set, use this column to sort the default data |
252 ["sortnext"] = 1, | 168 ["sortnext"] = 1, |
253 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Reason"), | 169 ["tooltipTitle"] = "Reason", |
254 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the reason the items couldn't be queued."), | 170 ["tooltip"] = "Click to sort the list by the reason the items couldn't be queued.", |
255 }, | 171 }, |
256 }; | 172 }; |
257 | 173 |
258 local proceedButton = { | 174 local proceedButton = { |
259 text = "Queue", | 175 text = "Queue", |
260 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Queue"), | 176 tooltipTitle = "Queue", |
261 tooltip = (not addon.db.profile.defaults.hideHelp and "Add these items to the queue of your crafting addon."), | 177 tooltip = "Add these items to the queue of your crafting addon.", |
262 onClick = OnQueueAccept, | 178 onClick = function() mod:QueueProcess(); end, |
263 }; | 179 }; |
264 local cancelButton = { | 180 local cancelButton = { |
265 text = "Cancel", | 181 text = "Cancel", |
266 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Cancel"), | 182 tooltipTitle = "Cancel", |
267 tooltip = (not addon.db.profile.defaults.hideHelp and "Do not queue anything and close the window."), | 183 tooltip = "Do not queue anything and close the window.", |
268 onClick = OnQueueCancel, | 184 onClick = function() mod:QueueAbort(); end, |
269 }; | 185 }; |
270 | 186 |
271 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); | 187 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); |
272 end | 188 end |
273 end | 189 end |
274 | 190 |
275 local function DisplayQueue() | 191 function mod:BuildQueue() |
276 MakeQueueWindow(); | 192 MakeQueueWindow(); |
277 | 193 |
278 -- This table is never copied, just referenced. It is the same for every row. | 194 -- This table is never copied, just referenced. It is the same for every row. |
279 local queueablesColumns = { | 195 local queueablesColumns = { |
280 { | 196 { |
293 end, | 209 end, |
294 ["color"] = function(data, cols, realrow, column, table) | 210 ["color"] = function(data, cols, realrow, column, table) |
295 return ((data[realrow].rowData.bonus == 0) and { r = 1, g = 1, b = 1, a = 0.5 }) or { r = 0, g = 1, b = 0, a = 1 }; | 211 return ((data[realrow].rowData.bonus == 0) and { r = 1, g = 1, b = 1, a = 0.5 }) or { r = 0, g = 1, b = 0, a = 1 }; |
296 end, | 212 end, |
297 }, -- extra | 213 }, -- extra |
214 { | |
215 ["value"] = "X", | |
216 }, | |
298 }; | 217 }; |
299 | 218 |
300 -- Store the list with rows in this | 219 -- Store the list with rows in this |
301 local queueables = {}; | 220 local queueables = {}; |
302 | 221 |
332 end | 251 end |
333 | 252 |
334 addon:SetQueueFrameData(queueables, unqueueables); | 253 addon:SetQueueFrameData(queueables, unqueueables); |
335 end | 254 end |
336 | 255 |
337 function mod:OnEnable() | 256 local function RefreshQueue() |
338 -- Register our own slash commands | 257 InventoriumQueuer.scrollTable:Refresh(); |
339 -- /im queue | 258 end |
340 addon:RegisterSlash(function() | 259 |
341 mod:QueueAll(); | 260 do -- Crafting region |
342 end, { "q", "que", "queue" }, "|Hfunction:InventoriumCommandHandler:queue|h|cff00fff7/im queue|r|h (or /im q) - Queue all items found in the currently opened profession that are within the groups tracked at this current character."); | 261 -- We are keeping these events within the module object to allow for easier testing and overriding |
343 | 262 -- To test: LibStub("AceAddon-3.0"):GetAddon("Inventorium"):GetModule("Queue"):FUNCTION_NAME(param1, param2, ...); |
344 self:RegisterMessage("IM_QUEUE_ALL"); | 263 |
345 self:RegisterMessage("IM_QUEUE_GROUP"); | 264 -- Start crafting the selected skill (or the first in line) |
346 | 265 local currentQueueItem; |
347 self:RegisterEvent("TRADE_SKILL_CLOSE", OnQueueCancel); | 266 function mod:StartCrafting(test) |
348 | 267 local frame = InventoriumQueuer; -- both for speed as code-consistency |
349 --self:RegisterEvent("UNIT_SPELLCAST_STOP", OnSpellFinished); | 268 |
350 --self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP", OnSpellFinished); | 269 local selectedIndex = frame.scrollTable:GetSelection(); -- gets realrow index |
351 end | 270 |
352 | 271 addon:Debug("%d was selected.", tostring(selectedIndex)); |
353 function mod:IM_QUEUE_ALL() | 272 |
354 self:QueueAll(); | 273 if not selectedIndex then |
355 end | 274 -- Select the top most element (scrolltable with index of 1 will contain a index of the related realrow of the data table) |
356 | 275 selectedIndex = ((frame.scrollTable.sorttable and frame.scrollTable.sorttable[1]) or 1); |
357 function mod:IM_QUEUE_GROUP(event, groupName) | 276 |
358 self:QueueGroup(groupName); | 277 addon:Debug("%d should be the top record.", tostring(selectedIndex)); |
278 end | |
279 | |
280 local nextQueue = frame.scrollTable.data[selectedIndex] or frame.scrollTable.data[1]; -- if the selected index still fails, try to get the first record | |
281 | |
282 if nextQueue then | |
283 if not test then | |
284 -- Initiate spell (test will be used while debugging to fake crafts) | |
285 DoTradeSkill(nextQueue.craft.no, ceil(nextQueue.amount / nextQueue.craft.quantity)); | |
286 end | |
287 | |
288 -- Remember what we're crafting (saves many loops and/or table storing) | |
289 currentQueueItem = nextQueue; | |
290 | |
291 return; | |
292 else | |
293 addon:Print("Nothing is available in the craft queue.", addon.Colors.Red); | |
294 end | |
295 end | |
296 | |
297 function mod:SpellCastComplete(_, unit, _, _, _, spellId) | |
298 -- Sadly the item isn't put in our inventory yet so we don't know how many were made. | |
299 -- Because of that we assume the average amount was made, this isn't really the best solution, but it's pretty-est - for now. | |
300 | |
301 if unit == "player" and currentQueueItem and spellId == currentQueueItem.craft.spellId then | |
302 -- Make sure the old amount is accurate, this won't be updated by the spell we just finished, that item hasn't been received yet | |
303 currentQueueItem.amount = mod:GetRestockAmount(currentQueueItem.itemId, currentQueueItem.groupName); | |
304 | |
305 -- Decrease amount remaining by one quantity | |
306 currentQueueItem.amount = ( currentQueueItem.amount - currentQueueItem.craft.quantity ); | |
307 | |
308 if currentQueueItem.amount < 1 then | |
309 -- We finished crafting this item | |
310 | |
311 -- Remove this element from the queue | |
312 for index, q in pairs(queue) do | |
313 if q == currentQueueItem then | |
314 table.remove(queue, index); | |
315 break; | |
316 end | |
317 end | |
318 | |
319 -- Add this queue item to the "Unqueueables" frame - we finished it so it is no longer queueable and the user may become interested | |
320 self:Skip(currentQueueItem.itemId, skipReasons.FINISHED); | |
321 | |
322 -- We are no longer crafting anything | |
323 currentQueueItem = nil; | |
324 | |
325 -- Rebuild our scrolltable (records were removed and added) | |
326 mod:BuildQueue(); | |
327 else | |
328 -- Refresh the scrolltable (update item counts) | |
329 RefreshQueue(); | |
330 end | |
331 end | |
332 end | |
333 | |
334 function mod:SpellCastStart(_, unit, _, _, _, spellId) | |
335 if unit == "player" and currentQueueItem and spellId == currentQueueItem.craft.spellId then | |
336 self.isProcessing = true; | |
337 end | |
338 end | |
339 | |
340 function mod:SpellCastStop(_, unit, _, _, _, spellId) | |
341 if unit == "player" and currentQueueItem and spellId == currentQueueItem.craft.spellId then | |
342 self.isProcessing = nil; | |
343 end | |
344 end | |
345 | |
346 function mod:SpellCastFailed(_, unit, _, _, _, spellId) | |
347 if unit == "player" and currentQueueItem and spellId == currentQueueItem.craft.spellId then | |
348 currentQueueItem = nil; | |
349 self.isProcessing = nil; | |
350 end | |
351 end | |
352 | |
353 --@debug@ | |
354 function TestCraft() | |
355 mod:StartCrafting(true); | |
356 mod:SpellCastComplete("UNIT_SPELLCAST_SUCCEEDED", "player", "Relentless Earthsiege Diamond", nil, nil, 55400); | |
357 end | |
358 --@end-debug@ | |
359 end | |
360 | |
361 function mod:QueueProcess() | |
362 -- Prepare a table with all possible tradeskill craftables | |
363 local craftables = self:GetTradeskillCraftables(); | |
364 | |
365 for _, q in pairs(queue) do | |
366 if craftables[q.itemId] then | |
367 if self:QueueWithAddon(craftables[q.itemId].no, ceil(q.amount / craftables[q.itemId].quantity), q.groupName) == -1 then | |
368 addon:Print("Couldn't queue, no supported crafting addon found.", addon.Colors.Red); | |
369 | |
370 self:QueueAbort(); | |
371 return; | |
372 else | |
373 -- Update the crafted-item count | |
374 for groupName, values in pairs(addon.db.profile.groups) do | |
375 if values.items and values.items[q.itemId] then | |
376 values.items[q.itemId] = (tonumber(values.items[q.itemId]) or 0) + 1; | |
377 break; | |
378 end | |
379 end | |
380 end | |
381 else | |
382 addon:Debug("Lost %s", IdToItemLink(q.itemId)); | |
383 end | |
384 end | |
385 | |
386 self:QueueHide(); | |
387 end | |
388 | |
389 function mod:QueueAbort() | |
390 self:QueueHide(); | |
391 end | |
392 | |
393 function mod:QueueHide() | |
394 twipe(queue); | |
395 twipe(skipped); | |
396 | |
397 if InventoriumQueuer then | |
398 InventoriumQueuer:Hide(); | |
399 end | |
359 end | 400 end |
360 | 401 |
361 function mod:QueueAll() | 402 function mod:QueueAll() |
362 -- Prepare a table with all possible tradeskill craftables | 403 -- Prepare a table with all possible tradeskill craftables |
363 local craftables = self:GetTradeskillCraftables(); | 404 local craftables = self:GetTradeskillCraftables(); |
375 if trackAt[playerName] then | 416 if trackAt[playerName] then |
376 self:QueueGroup(groupName, craftables); | 417 self:QueueGroup(groupName, craftables); |
377 end | 418 end |
378 end | 419 end |
379 | 420 |
380 DisplayQueue(); | 421 mod:BuildQueue(); |
381 end | 422 end |
382 | 423 |
383 function mod:QueueGroup(groupName, craftables) | 424 function mod:QueueGroup(groupName, craftables) |
384 -- Prepare a table with all possible tradeskill craftables | 425 -- Prepare a table with all possible tradeskill craftables |
385 if not craftables then | 426 if not craftables then |
407 | 448 |
408 if amount and amount >= minCraftingQueue then | 449 if amount and amount >= minCraftingQueue then |
409 -- If we are queuing at least one AND more than the minimum amount, then proceed | 450 -- If we are queuing at least one AND more than the minimum amount, then proceed |
410 | 451 |
411 -- Auction value settings | 452 -- Auction value settings |
412 local value = (priceThreshold ~= 0 and addon:GetAuctionValue(itemLink, groupName)); | 453 local value = (priceThreshold ~= 0 and addon:GetAuctionValue(IdToItemLink(itemId), groupName)); |
413 | 454 |
414 if priceThreshold == 0 or value == -1 or value >= priceThreshold then | 455 if priceThreshold == 0 or value == -1 or value >= priceThreshold then |
415 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed | 456 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed |
416 | 457 |
417 self:Queue(itemId, amount, bonus, craftables[itemId], groupName); | 458 self:Queue(itemId, amount, bonus, craftables[itemId], groupName); |
418 else | 459 else |
419 self:Skip(itemId, skipReasons.LOW_VALUE); | 460 self:Skip(itemId, skipReasons.LOW_VALUE); |
461 --addon:Debug("%s is valued at %s while %s is needed", IdToItemLink(itemId), tostring(value), tostring(priceThreshold)); | |
420 end | 462 end |
421 else | 463 else |
422 if not amount then | 464 if not amount then |
423 -- nil = no item count addon | 465 -- nil = no item count addon |
424 self:Skip(itemId, skipReasons.NO_ITEMCOUNT_ADDON); | 466 self:Skip(itemId, skipReasons.NO_ITEMCOUNT_ADDON); |
505 end | 547 end |
506 | 548 |
507 return -1; | 549 return -1; |
508 end | 550 end |
509 | 551 |
510 -- Expand all categories | 552 function mod:OnEnable() |
511 local function ExpandSubClasses() | 553 -- Register our own slash commands |
512 for i = GetNumTradeSkills(), 1, -1 do | 554 -- /im queue |
513 local _, skillType, _, isExpanded = GetTradeSkillInfo(i); | 555 addon:RegisterSlash(function() |
514 | 556 mod:QueueAll(); |
515 if skillType == "header" and not isExpanded then | 557 end, { "q", "que", "queue" }, "|Hfunction:InventoriumCommandHandler:queue|h|cff00fff7/im queue|r|h (or /im q) - Queue all items found in the currently opened profession that are within the groups tracked at this current character."); |
516 ExpandTradeSkillSubClass(i); | 558 |
517 end | 559 self:RegisterMessage("IM_QUEUE_ALL"); |
518 end | 560 self:RegisterMessage("IM_QUEUE_GROUP"); |
519 end | 561 |
520 | 562 -- When closing the tradeskill window also hide the queue screen. |
521 function mod:GetTradeskillCraftables() | 563 -- We scan the recipes right before queueing not when the tradeskill is opened because we really don't need it at any other time. |
522 local craftables = {}; | 564 self:RegisterEvent("TRADE_SKILL_CLOSE", "QueueAbort"); |
523 | 565 |
524 if GetTradeSkillLine() ~= "UNKNOWN" then | 566 -- Crafting events |
525 ExpandSubClasses(); | 567 self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED", "SpellCastComplete"); |
526 | 568 |
527 -- Cache all craftable items | 569 -- Button en-/disabling |
528 for i = 1, GetNumTradeSkills() do | 570 self:RegisterEvent("UNIT_SPELLCAST_START", "SpellCastStart"); |
529 local itemLink = GetTradeSkillItemLink(i); | 571 self:RegisterEvent("UNIT_SPELLCAST_STOP", "SpellCastStop"); |
530 | 572 |
531 if itemLink then | 573 self:RegisterEvent("UNIT_SPELLCAST_FAILED", "SpellCastFailed"); |
532 local itemId = addon:GetItemId(itemLink); | 574 self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED", "SpellCastFailed"); |
533 if not itemId then | 575 end |
534 -- If this isn't an item, it can only be an enchant instead | 576 |
535 itemId = tonumber(smatch(itemLink, "|Henchant:([-0-9]+)|h")); | 577 do -- Addon messages (Ace3) region |
578 function mod:IM_QUEUE_ALL() | |
579 self:QueueAll(); | |
580 end | |
581 | |
582 function mod:IM_QUEUE_GROUP(event, groupName) | |
583 self:QueueGroup(groupName); | |
584 end | |
585 end | |
586 | |
587 do -- Trade skill recipes region | |
588 -- Expand all categories so no crafts are hidden | |
589 local function ExpandSubClasses() | |
590 for i = GetNumTradeSkills(), 1, -1 do | |
591 local _, skillType, _, isExpanded = GetTradeSkillInfo(i); | |
592 | |
593 if skillType == "header" and not isExpanded then | |
594 ExpandTradeSkillSubClass(i); | |
595 end | |
596 end | |
597 end | |
598 | |
599 -- Reset all filters so no crafts are hidden | |
600 local function ResetFilters() | |
601 SetTradeSkillSubClassFilter(0, 1, 1); | |
602 SetTradeSkillItemNameFilter(""); | |
603 SetTradeSkillItemLevelFilter(0, 0); | |
604 TradeSkillOnlyShowSkillUps(false); | |
605 TradeSkillOnlyShowMakeable(false); | |
606 end | |
607 | |
608 -- Get all craftable items into a table. Each record contains "no", "spellId" and "quantity". The last is the average amount made per craft. | |
609 function mod:GetTradeskillCraftables() | |
610 local craftables = {}; | |
611 | |
612 if GetTradeSkillLine() ~= "UNKNOWN" then | |
613 ExpandSubClasses(); | |
614 ResetFilters(); | |
615 | |
616 -- Cache all craftable items | |
617 for i = 1, GetNumTradeSkills() do | |
618 local itemLink = GetTradeSkillItemLink(i); | |
619 | |
620 if itemLink then | |
621 local itemId = addon:GetItemId(itemLink); | |
622 if not itemId then | |
623 -- If this isn't an item, it can only be an enchant instead | |
624 itemId = tonumber(smatch(itemLink, "|Henchant:([-0-9]+)|h")); | |
625 | |
626 if itemId and addon.scrollIds[itemId] then | |
627 -- Only if this scroll id actually exists | |
628 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds | |
629 end | |
630 end | |
536 | 631 |
537 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds | 632 -- Remember the average amount of items created per craft (doesn't need to be a round number, since we multiply this by the amount of items to be queued we're better off rounding at that time) |
633 local minMade, maxMade = GetTradeSkillNumMade(i); | |
634 local average = ((minMade == maxMade) and minMade) or ((minMade + maxMade) / 2); | |
635 | |
636 local recipeLink = GetTradeSkillRecipeLink(i); | |
637 local spellId = tonumber(smatch(recipeLink, "|Henchant:([-0-9]+)|h")); | |
638 | |
639 craftables[itemId] = { | |
640 ["no"] = i, -- needed to start crafting at the end of the entire cycle | |
641 ["spellId"] = spellId, -- needed to detect creation of this item was finished | |
642 ["quantity"] = average, -- needed to calculate the amount of crafts | |
643 }; | |
538 end | 644 end |
539 | |
540 -- Remember the average amount of items created per craft (doesn't need to be a round number, since we multiply this by the amount of items to be queued we're better off rounding at that time) | |
541 local minMade, maxMade = GetTradeSkillNumMade(i); | |
542 local average = ((minMade == maxMade) and minMade) or ((minMade + maxMade) / 2); | |
543 | |
544 local recipeLink = GetTradeSkillRecipeLink(i); | |
545 local spellId = tonumber(smatch(recipeLink, "|Henchant:([-0-9]+)|h")); | |
546 | |
547 craftables[itemId] = { | |
548 ["no"] = i, -- needed to start crafting at the end of the entire cycle | |
549 ["spellId"] = spellId, -- needed to detect creation of this item was finished | |
550 ["quantity"] = average, -- needed to calculate the amount of crafts | |
551 }; | |
552 end | 645 end |
553 end | 646 else |
554 else | 647 return; |
555 return; | 648 end |
556 end | 649 |
557 | 650 return craftables; |
558 return craftables; | 651 end |
559 end | 652 end |