comparison Modules/Crafting.lua @ 99:e9b903cf9b33

Added a menu to allow the user to see what is to be crafted, only what you hae mats for, or view everything so you can see why something isn't to be crafted.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 19 Aug 2010 23:14:30 -0700
parents 63823b6b5e28
children 53147a647e28
comparison
equal deleted inserted replaced
98:b29441cd130d 99:e9b903cf9b33
112 ['DoCellUpdate'] = displayMoney, 112 ['DoCellUpdate'] = displayMoney,
113 }, 113 },
114 { name= "Est Sale Each", width = 100, align = "RIGHT", 114 { name= "Est Sale Each", width = 100, align = "RIGHT",
115 ['DoCellUpdate'] = displayMoney, 115 ['DoCellUpdate'] = displayMoney,
116 }, 116 },
117 { name= "Decided By", width = 100, align = "RIGHT", 117 { name= "Decided By", width = 125, align = "RIGHT",
118 118
119 }, 119 },
120 { name= "craft", width = 50, align = "RIGHT", 120 { name= "craft", width = 50, align = "RIGHT",
121
122 },
123 { name= "Have Mats", width = 60, align = "RIGHT",
121 124
122 }, 125 },
123 { name= "Total Profit", width = 100, align = "RIGHT", 126 { name= "Total Profit", width = 100, align = "RIGHT",
124 ['DoCellUpdate'] = displayMoney, 127 ['DoCellUpdate'] = displayMoney,
125 }, 128 },
158 161
159 end 162 end
160 end 163 end
161 164
162 -- ItemAuditor:GetModule('Crafting').filter_queued = false 165 -- ItemAuditor:GetModule('Crafting').filter_queued = false
163 Crafting.filter_queued = true 166 Crafting.filter_have_mats = false
167 Crafting.filter_show_all = false
164 local function tableFilter(self, row, ...) 168 local function tableFilter(self, row, ...)
169 if Crafting.filter_show_all then
170 return true
171 end
172
165 -- column 5 is how many should be crafted 173 -- column 5 is how many should be crafted
166 if Crafting.filter_queued and row[5] <= 0 then 174 if Crafting.filter_have_mats and row[6] == 'n' then
175 return false
176 end
177 if strfind(row[4], 'VETO: .*') or row[5] == 0 then
167 return false 178 return false
168 end 179 end
169 return true 180 return true
170 end 181 end
171 182
202 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) 213 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
203 GameTooltip:Hide() 214 GameTooltip:Hide()
204 end, 215 end,
205 }); 216 });
206 217
207 218 local craftingView = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate")
219 craftingView:SetText("View")
220 craftingView:SetSize(50, 25)
221 craftingView:SetPoint("BOTTOMLEFT", craftingContent, 0, 0)
222
223 local menu = {
224 { text = "View", isTitle = true},
225 { text = "To be crafted", func = function()
226 Crafting.filter_have_mats = false
227 Crafting.filter_show_all = false
228 ItemAuditor:RefreshCraftingTable()
229 end },
230 { text = "Have Mats", func = function()
231 Crafting.filter_have_mats = true
232 Crafting.filter_show_all = false
233 ItemAuditor:RefreshCraftingTable()
234 end },
235 { text = "All", func = function()
236 Crafting.filter_have_mats = false
237 Crafting.filter_show_all = true
238 ItemAuditor:RefreshCraftingTable()
239 end },
240 }
241 local menuFrame = CreateFrame("Frame", "ExampleMenuFrame", UIParent, "UIDropDownMenuTemplate")
242 craftingView:SetScript("OnClick", function (self, button, down)
243 EasyMenu(menu, menuFrame, "cursor", 0 , 0, "MENU");
244 end)
245
246
208 btnProcess = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate") 247 btnProcess = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate")
209 btnProcess:SetText("Process") 248 btnProcess:SetText("Process")
210 btnProcess:SetSize(100, 25) 249 btnProcess:SetSize(100, 25)
211 btnProcess:SetPoint("BOTTOMRIGHT", craftingContent, 0, 0) 250 btnProcess:SetPoint("BOTTOMRIGHT", craftingContent, 0, 0)
212 btnProcess:RegisterForClicks("LeftButtonUp"); 251 btnProcess:RegisterForClicks("LeftButtonUp");
235 btnProcess:SetScript("OnLeave", function() 274 btnProcess:SetScript("OnLeave", function()
236 GameTooltip:Hide() 275 GameTooltip:Hide()
237 end) 276 end)
238 277
239 btnSkillet = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate") 278 btnSkillet = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate")
240 279
241
242 btnSkillet:SetSize(125, 25) 280 btnSkillet:SetSize(125, 25)
243 btnSkillet:SetPoint("BOTTOMRIGHT", btnProcess, 'BOTTOMLEFT', 0, 0) 281 btnSkillet:SetPoint("BOTTOMRIGHT", btnProcess, 'BOTTOMLEFT', 0, 0)
244 btnSkillet:RegisterForClicks("LeftButtonUp"); 282 btnSkillet:RegisterForClicks("LeftButtonUp");
245 btnSkillet:SetScript("OnClick", function (self, button, down) 283 btnSkillet:SetScript("OnClick", function (self, button, down)
246 Crafting.Export() 284 Crafting.Export()
329 367
330 local function isProfitable(data) 368 local function isProfitable(data)
331 if data.profit > 0 and data.profit > ItemAuditor:GetCraftingThreshold() then 369 if data.profit > 0 and data.profit > ItemAuditor:GetCraftingThreshold() then
332 return 1 370 return 1
333 end 371 end
334 return -1 372 return -1, 'Not Profitable'
335 end 373 end
336 374
337 Crafting.RegisterCraftingDecider('Is Profitable', isProfitable) 375 Crafting.RegisterCraftingDecider('Is Profitable', isProfitable)
338 376
339 377
409 queue = 0, 447 queue = 0,
410 winner = "", 448 winner = "",
411 } 449 }
412 450
413 data.winner, data.queue = Decide(data) 451 data.winner, data.queue = Decide(data)
414 data.queue = data.queue - count 452 --[[
453 If it wasn't vetoed we need to reduce the number by how many are owned
454 but this should not go below 0
455 ]]
456 if data.queue > 0 then
457 data.queue = max(0, data.queue - count)
458 end
415 459
416 -- If a tradeskill makes 5 at a time and something asks for 9, we should only 460 -- If a tradeskill makes 5 at a time and something asks for 9, we should only
417 -- craft twice to get 10. 461 -- craft twice to get 10.
418 data.queue = ceil(data.queue / GetTradeSkillNumMade(i)) 462 data.queue = ceil(data.queue / GetTradeSkillNumMade(i))
419 463
420 realData[row] = data 464 realData[row] = data
421 row = row + 1 465 row = row + 1
422 end 466 end
423 end 467 end
424 end 468 end
425 table.sort(realData, function(a, b) return a.profit*a.queue > b.profit*b.queue end) 469 table.sort(realData, function(a, b) return a.profit*max(1, a.queue) > b.profit*max(1, b.queue) end)
426 470
427 local numOwned = {} 471 local numOwned = {}
428 for key, data in pairs(realData) do 472 for key, data in pairs(realData) do
429 data.haveMaterials = true 473 data.haveMaterials = true
430 for id, reagent in pairs(data.reagents) do 474 for id, reagent in pairs(data.reagents) do
445 self:RefreshCraftingTable() 489 self:RefreshCraftingTable()
446 end 490 end
447 end 491 end
448 492
449 function ItemAuditor:RefreshCraftingTable() 493 function ItemAuditor:RefreshCraftingTable()
494 local displayMaterials
450 for key, data in pairs(realData) do 495 for key, data in pairs(realData) do
496 displayMaterials = 'n'
497 if data.haveMaterials then
498 displayMaterials = 'y'
499 end
451 tableData[key] = { 500 tableData[key] = {
452 data.name, 501 data.name,
453 data.cost, 502 data.cost,
454 data.price, 503 data.price,
455 data.winner, 504 data.winner,
456 data.queue, 505 abs(data.queue),
457 data.profit*data.queue, 506 displayMaterials,
507 data.profit*abs(data.queue),
458 } 508 }
459 end 509 end
460 craftingTable:SetData(tableData, true) 510 craftingTable:SetData(tableData, true)
461 511
462 if self:GetCraftingRow(1) then 512 if self:GetCraftingRow(1) then