comparison ui/ShoppingListTab.lua @ 0:ec731d2fe6ba

Version 1.2.12.0
author Adam tegen <adam.tegen@gmail.com>
date Tue, 20 May 2014 21:43:23 -0500
parents
children ece9167c0d1c
comparison
equal deleted inserted replaced
-1:000000000000 0:ec731d2fe6ba
1 local _, AskMrRobot = ...
2
3 -- initialize the ShoppingListTab class
4 AskMrRobot.ShoppingListTab = AskMrRobot.inheritsFrom(AskMrRobot.Frame)
5
6 StaticPopupDialogs["SHOPPING_TAB_PLEASE_OPEN"] = {
7 text = "You need to open the mail window for this to work",
8 button1 = "Ok",
9 timeout = 0,
10 whileDead = true,
11 hideOnEscape = true,
12 preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/
13 }
14
15 function AskMrRobot.ShoppingListTab:new(parent)
16
17 local tab = AskMrRobot.Frame:new(nil, parent)
18 setmetatable(tab, { __index = AskMrRobot.ShoppingListTab })
19 tab:SetPoint("TOPLEFT")
20 tab:SetPoint("BOTTOMRIGHT")
21 tab:Hide()
22 tab:RegisterEvent("AUCTION_HOUSE_CLOSED")
23 tab:RegisterEvent("AUCTION_HOUSE_SHOW")
24 tab:RegisterEvent("MAIL_SHOW")
25 tab:RegisterEvent("MAIL_CLOSED")
26
27 tab.isAuctionHouseVisible = false
28
29 tab:SetScript("OnEvent", function(...)
30 tab:OnEvent(...)
31 end)
32
33 tab.shoppingListHeader = AskMrRobot.FontString:new(tab, nil, "ARTWORK", "GameFontNormalLarge")
34 tab.shoppingListHeader:SetPoint("TOPLEFT", 0, -5)
35 tab.shoppingListHeader:SetText("Shopping List")
36
37 tab.shoppingPanel = AskMrRobot.Frame:new(nil, tab)
38 tab.shoppingPanel:SetPoint("TOPLEFT", tab.shoppingListHeader, "BOTTOMLEFT", 0, -10)
39 tab.shoppingPanel:SetPoint("BOTTOMRIGHT", tab, "BOTTOMRIGHT", -20, 17)
40
41
42 tab.sendButton = CreateFrame("Button", "AmrSendButton", tab.shoppingPanel, "UIPanelButtonTemplate")
43 tab.sendButton:SetText("send it!")
44 tab.sendButton:SetPoint("BOTTOMLEFT", 0, 0)
45 tab.sendButton:SetHeight(25)
46 tab.sendButton:SetNormalFontObject("GameFontNormalLarge")
47 tab.sendButton:SetHighlightFontObject("GameFontHighlightLarge")
48 tab.sendButton:SetWidth(150)
49 tab.sendButton:SetScript("OnClick", function()
50 tab:Send()
51 end)
52
53 tab.enchantMaterialsCheckbox = CreateFrame("CheckButton", "AmrEnchantMaterialsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate");
54 tab.enchantMaterialsCheckbox:SetChecked(AmrSendSettings.SendEnchantMaterials)
55 tab.enchantMaterialsCheckbox:SetScript("OnClick", function () AmrSendSettings.SendEnchantMaterials = tab.enchantMaterialsCheckbox:GetChecked() end)
56 tab.enchantMaterialsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 25)
57 local text3 = getglobal(tab.enchantMaterialsCheckbox:GetName() .. 'Text')
58 text3:SetFontObject("GameFontHighlightLarge")
59 text3:SetText("Enchant Materials")
60 text3:SetWidth(150)
61 text3:SetPoint("TOPLEFT", tab.enchantMaterialsCheckbox, "TOPRIGHT", 2, -4)
62
63
64 tab.enchantsCheckbox = CreateFrame("CheckButton", "AmrEnchantsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate");
65 tab.enchantsCheckbox:SetChecked(AmrSendSettings.SendEnchants)
66 tab.enchantsCheckbox:SetScript("OnClick", function () AmrSendSettings.SendEnchants = tab.enchantsCheckbox:GetChecked() end)
67 tab.enchantsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 50)
68 local text2 = getglobal(tab.enchantsCheckbox:GetName() .. 'Text')
69 text2:SetFontObject("GameFontHighlightLarge")
70 text2:SetText("Enchants")
71 text2:SetWidth(150)
72 text2:SetPoint("TOPLEFT", tab.enchantsCheckbox, "TOPRIGHT", 2, -4)
73
74
75
76 tab.gemsCheckbox = CreateFrame("CheckButton", "AmrGemsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate");
77 tab.gemsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 75)
78 tab.gemsCheckbox:SetChecked(AmrSendSettings.SendGems)
79 tab.gemsCheckbox:SetScript("OnClick", function () AmrSendSettings.SendGems = tab.gemsCheckbox:GetChecked() end)
80 local text = getglobal(tab.gemsCheckbox:GetName() .. 'Text')
81 text:SetFontObject("GameFontHighlightLarge")
82 text:SetText("Gems")
83 text:SetWidth(150)
84 text:SetPoint("TOPLEFT", tab.gemsCheckbox, "TOPRIGHT", 2, -4)
85
86
87 tab.sendMessage4 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontHighlightLarge")
88 tab.sendMessage4:SetText("Include:")
89 tab.sendMessage4:SetPoint("TOPLEFT", tab.gemsCheckbox, "TOPLEFT", 0, 20)
90
91
92 tab.sendMessage3 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontHighlightLarge")
93 tab.sendMessage3:SetText("Send list to")
94 tab.sendMessage3:SetPoint("TOPLEFT", tab.sendMessage4, "TOPLEFT", 0, 25)
95
96
97 tab.sendMessage2 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontNormal")
98 tab.sendMessage2:SetTextColor(.5,.5,.5)
99 tab.sendMessage2:SetText("Whisper to a friend or send to a channel, like /raid or /guild.")
100 tab.sendMessage2:SetPoint("TOPLEFT", tab.sendMessage3, "TOPLEFT", 0, 25)
101
102
103 tab.sendMessage1 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontNormalLarge")
104 tab.sendMessage1:SetTextColor(0,1,0)
105 tab.sendMessage1:SetText("Send to a Jewelcraft or Enchanter friend :)")
106 tab.sendMessage1:SetPoint("TOPLEFT", tab.sendMessage2, "TOPLEFT", 0, 25)
107
108
109 tab.scrollFrame = CreateFrame("ScrollFrame", "AmrScrollFrame", tab.shoppingPanel, "UIPanelScrollFrameTemplate")
110 tab.scrollFrame:SetPoint("TOPLEFT", 0, 0)
111 tab.scrollFrame:SetPoint("RIGHT", -20, 0)
112 tab.scrollFrame:SetPoint("BOTTOM", tab.sendMessage1, "TOP", 0, 10)
113
114 tab.scrollParent = AskMrRobot.Frame:new(nil, tab.shoppingPanel)
115 tab.scrollParent:SetPoint("TOPLEFT", 0, 0)
116 tab.scrollParent:SetWidth(tab:GetWidth() - 20)
117 tab.scrollParent:SetHeight(500)
118 tab.scrollFrame:SetScrollChild(tab.scrollParent)
119
120 -- magic to get the scrollbar to work with the scrollwheel...
121 tab.scrollFrame:SetScript("OnMouseWheel", function(arg1, arg2)
122 ScrollFrameTemplate_OnMouseWheel(arg1, arg2, arg1.ScrollBar)
123 end)
124
125 tab.gemsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
126 tab.gemsHeader:SetText("Gems")
127 tab.gemsHeader:SetPoint("TOPLEFT", tab.scrollParent, "TOPLEFT", 0, 0)
128
129 tab.gemsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
130 tab.gemsQuantityHeader:SetText("Total")
131 tab.gemsQuantityHeader:SetPoint("TOPLEFT", tab.scrollParent, "TOPLEFT", 370, 0)
132
133 tab.enchantsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
134 tab.enchantsHeader:SetText("Enchants")
135
136 tab.enchantsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
137 tab.enchantsQuantityHeader:SetText("Total")
138 tab.enchantsQuantityHeader:SetPoint("TOPLEFT", tab.enchantsHeader, "TOPLEFT", 370, 0)
139
140 tab.enchantMaterialsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
141 tab.enchantMaterialsHeader:SetText("Enchant Materials")
142
143 tab.enchantMaterialsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
144 tab.enchantMaterialsQuantityHeader:SetText("Total")
145 tab.enchantMaterialsQuantityHeader:SetPoint("TOPLEFT", tab.enchantMaterialsHeader, "TOPLEFT", 370, 0)
146
147 tab.stamp = AskMrRobot.RobotStamp:new(nil, tab)
148 tab.stamp:Hide()
149 tab.stamp.bigText:SetText("YOUR SHOPPING IS ALL DONE!")
150 tab.stamp.smallText:SetText("Unless you want to buy me a birthday present! I like titanium bolts and robot dogs... Or was it titanium dogs and robot bolts...")
151 tab.stamp:SetPoint("TOPLEFT", tab.shoppingListHeader, "BOTTOMLEFT", 2, -15)
152 tab.stamp:SetPoint("RIGHT", tab, "RIGHT", -30, 0)
153 tab.stamp:SetHeight(92)
154
155 tab.gemIcons = {}
156 tab.gemLinks = {}
157 tab.gemQuantity = {}
158 tab.enchantIcons = {}
159 tab.enchantLinks = {}
160 tab.enchantQuantity = {}
161 tab.enchantMaterialIcons = {}
162 tab.enchantMaterialLinks = {}
163 tab.enchantMaterialQuantity = {}
164
165 -- Create the dropdown, and configure its appearance
166 tab.dropDown = CreateFrame("FRAME", "AmrSendType", tab.shoppingPanel, "UIDropDownMenuTemplate")
167 tab.dropDown:SetPoint("TOPLEFT", tab.sendMessage3, "TOPRIGHT", 0, 5)
168 UIDropDownMenu_SetWidth(tab.dropDown, 140)
169 UIDropDownMenu_SetText(tab.dropDown, AmrSendSettings.SendToType)
170
171 local text = getglobal(tab.dropDown:GetName() .. 'Text')
172 text:SetFontObject("GameFontHighlightLarge")
173
174 local AddButton = function(list, optionText)
175 local info = UIDropDownMenu_CreateInfo()
176 info.justifyH = "RIGHT"
177 info.text = optionText
178 info.checked = AmrSendSettings.SendToType == optionText
179 info.arg1 = optionText
180 info.func = list.SetValue
181 info.owner = list
182 info.fontObject = "GameFontHighlightLarge"
183 info.minWidth = 140
184 return info
185 end
186
187 -- Create and bind the initialization function to the dropdown menu
188 UIDropDownMenu_Initialize(tab.dropDown, function(self, level, menuList)
189 UIDropDownMenu_AddButton(AddButton(self, "a friend"))
190 UIDropDownMenu_AddButton(AddButton(self, "party"))
191 UIDropDownMenu_AddButton(AddButton(self, "raid"))
192 UIDropDownMenu_AddButton(AddButton(self, "guild"))
193 UIDropDownMenu_AddButton(AddButton(self, "channel"))
194 UIDropDownMenu_AddButton(AddButton(self, "mail"))
195 end)
196
197 function tab.dropDown:SetValue(newValue)
198 AmrSendSettings.SendToType = newValue
199 -- Update the text; if we merely wanted it to display newValue, we would not need to do this
200 UIDropDownMenu_SetText(tab.dropDown, AmrSendSettings.SendToType)
201 -- Because this is called from a sub-menu, only that menu level is closed by default.
202 -- Close the entire menu with this next call
203 CloseDropDownMenus()
204 end
205
206 tab.sendTo = CreateFrame("EditBox", "AmrSendTo", tab.shoppingPanel, "InputBoxTemplate" )
207 tab.sendTo:SetPoint("TOPLEFT", tab.dropDown, "TOPRIGHT", 0, 0)
208 tab.sendTo:SetPoint("RIGHT", 0, 0)
209 tab.sendTo:SetHeight(30)
210 tab.sendTo:SetText(AmrSendSettings.SendTo or "")
211 tab.sendTo:SetFontObject("GameFontHighlightLarge")
212 tab.sendTo:SetAutoFocus(false)
213 tab.sendTo:SetScript("OnChar", function()
214 AmrSendSettings.SendTo = tab.sendTo:GetText()
215 end)
216
217 tab.messageQueue = {}
218 return tab
219 end
220
221 -- display a gem icon in a row
222 -- gemInfo is {id, enchantId, color, count }
223 function AskMrRobot.ShoppingListTab:SetGemIcon(row, gemInfo)
224 -- get gem icon for the row
225 local gemIcon = self.gemIcons[row]
226
227 -- if we don't have one
228 if gemIcon == nil then
229 -- make one
230 gemIcon = AskMrRobot.GemIcon:new(nil, self.scrollParent)
231 self.gemIcons[row] = gemIcon
232 gemIcon:SetScript("OnMouseDown", function()
233 self:SearchForGem(row)
234 end)
235
236 -- position it
237 local previous = self.gemsHeader
238 if row > 1 then
239 previous = self.gemIcons[row - 1]
240 end
241 gemIcon:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 0, -7)
242
243 -- size it
244 gemIcon:SetWidth(24)
245 gemIcon:SetHeight(24)
246
247 -- give it a nice border
248 gemIcon:SetRoundBorder()
249 end
250
251 gemIcon:Show()
252
253 -- make a link for the optimized gem
254 gemLink = select(2, GetItemInfo(gemInfo.id))
255
256 -- set the link (tooltip + icon)
257 gemIcon:SetItemLink(gemLink)
258 gemIcon:SetGemColor(gemInfo.color)
259
260 -- if we didn't get one, its because WoW is slow
261 if not gemLink and gemInfo.id then
262 -- when WoW finally returns the link, set the icon / tooltip
263 AskMrRobot.RegisterItemInfoCallback(gemInfo.id, function(name, link)
264 gemIcon:SetItemLink(link)
265 end)
266 end
267
268 end
269
270
271 -- display a gem icon in a row
272 -- gemInfo is {id, enchantId, color, count }
273 function AskMrRobot.ShoppingListTab:SetGemText(row, gemInfo)
274 -- get gem icon for the row
275 local gemText = self.gemLinks[row]
276
277 -- if we don't have one
278 if gemText == nil then
279 -- make one
280 gemText = AskMrRobot.ItemLinkText:new(nil, self.scrollParent)
281 self.gemLinks[row] = gemText
282 gemText:SetScript("OnMouseDown", function()
283 self:SearchForGem(row)
284 end)
285
286 -- position it
287 local previous = self.gemsHeader
288 if row > 1 then
289 previous = self.gemIcons[row - 1]
290 end
291 gemText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 30, -8)
292 gemText:SetPoint("RIGHT", self, "RIGHT", -70, 0)
293 gemText:SetHeight(18)
294 gemText:SetFontSize(15)
295 end
296
297 gemText:Show()
298
299 gemText:SetItemId(gemInfo.id)
300 end
301
302 -- display a gem icon in a row
303 -- gemInfo is {id, enchantId, color, count }
304 function AskMrRobot.ShoppingListTab:SetGemQuantity(row, qty, total)
305 if qty > total then qty = total end
306
307 -- get gem icon for the row
308 local gemText = self.gemQuantity[row]
309
310 -- if we don't have one
311 if gemText == nil then
312 -- make one
313 gemText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
314 self.gemQuantity[row] = gemText
315
316 -- position it
317 local previous = self.gemsHeader
318 if row > 1 then
319 previous = self.gemIcons[row - 1]
320 end
321 gemText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8)
322 gemText:SetHeight(18)
323 gemText:SetFontSize(15)
324 end
325
326 gemText:SetText('' .. qty .. '/' .. total)
327 if qty == total then
328 gemText:SetTextColor(0,1,0)
329 else
330 gemText:SetTextColor(1,0,0)
331 end
332 gemText:Show()
333 end
334
335
336 -- display an enchant icon in a row
337 function AskMrRobot.ShoppingListTab:SetEnchantIcon(row, enchantId)
338
339 -- get enchant icon for the row
340 local enchantIcon = self.enchantIcons[row]
341
342 -- if we don't have one
343 if enchantIcon == nil then
344 -- make one
345 enchantIcon = AskMrRobot.EnchantLinkIconAndText:new(nil, self.scrollParent)
346 self.enchantIcons[row] = enchantIcon
347 enchantIcon:SetScript("OnMouseDown", function()
348 self:SearchForEnchant(row)
349 end)
350
351 -- position it
352 if row == 1 then
353 enchantIcon:SetPoint("TOPLEFT", self.enchantsHeader, "BOTTOMLEFT", 0, -12)
354 enchantIcon:SetPoint("RIGHT", self.scrollParent, "RIGHT", -30, 0)
355 else
356 enchantIcon:SetPoint("TOPLEFT", self.enchantIcons[row - 1], "BOTTOMLEFT", 0, -7)
357 enchantIcon:SetPoint("RIGHT", self.scrollParent, "RIGHT", -30, 0)
358 end
359
360 -- size it
361 enchantIcon:SetWidth(24)
362 enchantIcon:SetHeight(24)
363 enchantIcon:SetFontSize(15)
364
365 -- give it a nice border
366 enchantIcon:SetRoundBorder()
367
368 enchantIcon:UseSpellName()
369 end
370
371 enchantIcon:SetEnchantId(enchantId)
372
373 enchantIcon:Show()
374 end
375
376 -- display a gem icon in a row
377 -- gemInfo is {id, enchantId, color, count }
378 function AskMrRobot.ShoppingListTab:SetEnchantQuantity(row, qty, total)
379 if qty > total then qty = total end
380
381 -- get gem icon for the row
382 local enchantText = self.enchantQuantity[row]
383
384 -- if we don't have one
385 if enchantText == nil then
386 -- make one
387 enchantText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
388 self.enchantQuantity[row] = enchantText
389
390 -- position it
391 local previous = self.enchantsHeader
392 if row > 1 then
393 previous = self.enchantIcons[row - 1]
394 end
395 enchantText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8)
396 enchantText:SetHeight(18)
397 enchantText:SetFontSize(15)
398 end
399
400 enchantText:SetText('' .. qty .. '/' .. total)
401 if qty == total then
402 enchantText:SetTextColor(0,1,0)
403 else
404 enchantText:SetTextColor(1,0,0)
405 end
406 enchantText:Show()
407 end
408
409 function AskMrRobot.ShoppingListTab:SearchForItem(itemName)
410 if self.isAuctionHouseVisible then
411 QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0, 0)
412 end
413 end
414
415 function AskMrRobot.ShoppingListTab:SearchForGem(row)
416 self:SearchForItem(self.gemLinks[row].itemName)
417 end
418
419 function AskMrRobot.ShoppingListTab:SearchForEnchant(row)
420 self:SearchForItem(self.enchantIcons[row].itemName)
421 end
422
423 function AskMrRobot.ShoppingListTab:SearchForEnchantMaterial(row)
424 self:SearchForItem(self.enchantMaterialLinks[row].itemName)
425 end
426
427
428 -- display an enchant material icon in a row
429 function AskMrRobot.ShoppingListTab:SetEnchantMaterialIcon(row, itemId)
430 -- get enchant material icon for the row
431 local materialIcon = self.enchantMaterialIcons[row]
432
433 -- if we don't have one
434 if materialIcon == nil then
435 -- make one
436 materialIcon = AskMrRobot.ItemIcon:new(nil, self.scrollParent)
437 self.enchantMaterialIcons[row] = materialIcon
438 materialIcon:SetScript("OnMouseDown", function()
439 self:SearchForEnchantMaterial(row)
440 end)
441
442 -- position it
443 local previous = self.enchantMaterialsHeader
444 if row > 1 then
445 previous = self.enchantMaterialIcons[row - 1]
446 end
447 materialIcon:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 0, -7)
448
449 -- size it
450 materialIcon:SetWidth(24)
451 materialIcon:SetHeight(24)
452
453 -- give it a nice border
454 materialIcon:SetRoundBorder()
455 end
456
457 materialIcon:Show()
458
459 -- make a link for the optimized gem
460 local itemLink = select(2, GetItemInfo(itemId))
461
462 materialIcon:SetItemLink(itemLink)
463
464 -- if we didn't get one, its because WoW is slow
465 if not itemLink and itemId then
466 -- when WoW finally returns the link, set the icon / tooltip
467 AskMrRobot.RegisterItemInfoCallback(itemId, function(name, link)
468 materialIcon:SetItemLink(link)
469 end)
470 end
471 end
472
473
474 -- display an enchant material link in a row
475 function AskMrRobot.ShoppingListTab:SetEnchantMaterialLink(row, itemId)
476 -- get gem icon for the row
477 local materialLink = self.enchantMaterialLinks[row]
478
479 -- if we don't have one
480 if materialLink == nil then
481 -- make one
482 materialLink = AskMrRobot.ItemLinkText:new(nil, self.scrollParent)
483 self.enchantMaterialLinks[row] = materialLink
484 materialLink:SetScript("OnMouseDown", function()
485 self:SearchForEnchantMaterial(row)
486 end)
487
488 -- position it
489 local previous = self.enchantMaterialsHeader
490 if row > 1 then
491 previous = self.enchantMaterialIcons[row - 1]
492 end
493 materialLink:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 30, -8)
494 materialLink:SetPoint("RIGHT", self, "RIGHT", -30, 0)
495 materialLink:SetHeight(18)
496 materialLink:SetFontSize(15)
497 end
498
499 materialLink:Show()
500
501 materialLink:SetItemId(itemId)
502 materialLink.itemId = itemId
503 end
504
505 -- display a gem icon in a row
506 -- gemInfo is {id, enchantId, color, count }
507 function AskMrRobot.ShoppingListTab:SetEnchantMaterialQuantity(row, qty, total)
508 if qty > total then qty = total end
509
510 -- get gem icon for the row
511 local enchantText = self.enchantMaterialQuantity[row]
512
513 -- if we don't have one
514 if enchantText == nil then
515 -- make one
516 enchantText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge")
517 self.enchantMaterialQuantity[row] = enchantText
518
519 -- position it
520 local previous = self.enchantMaterialsHeader
521 if row > 1 then
522 previous = self.enchantMaterialIcons[row - 1]
523 end
524 enchantText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8)
525 enchantText:SetHeight(18)
526 enchantText:SetFontSize(15)
527 end
528
529 enchantText:SetText('' .. qty .. '/' .. total)
530 if qty == total then
531 enchantText:SetTextColor(0,1,0)
532 else
533 enchantText:SetTextColor(1,0,0)
534 end
535 enchantText:Show()
536 end
537
538 function AskMrRobot.ShoppingListTab:HasStuffToBuy()
539
540 local gemList, enchantList, enchantMaterials = self:CalculateItems()
541
542 local count = 0
543 for gemId, gemInfo in AskMrRobot.spairs(gemList) do
544 count = count + gemInfo.total - gemInfo.count
545 end
546 for slot, enchant in AskMrRobot.spairs(enchantList) do
547 count = count + enchant.total - enchant.count
548 end
549
550 return count > 0
551 end
552
553 function AskMrRobot.ShoppingListTab:CalculateItems()
554 -- build a map of missing gem-ids -> {id, color, enchantid, count, total}
555 local gemList = {}
556 for slotNum, badGems in pairs(AskMrRobot.itemDiffs.gems) do
557 --badGems: {current: array of enchant ids, optimized: (array of {id, color, enchantId})
558 for i = 1, #badGems.optimized do
559 if badGems.badGems[i] then
560 local goodGem = badGems.optimized[i]
561 if goodGem.id ~= 0 then
562 local gem = gemList[goodGem.id]
563 if gem == nil then
564 gemList[goodGem.id] = {id = goodGem.id, enchantId = goodGem.enchantId, color = goodGem.color, count = 0, total = 1}
565 else
566 gem.total = gem.total + 1
567 end
568 end
569 end
570 end
571 end
572
573 local enchantList = {}
574 for slot, enchantData in AskMrRobot.sortSlots(AskMrRobot.itemDiffs.enchants) do
575 local id = AskMrRobot.getEnchantItemId(enchantData.optimized) or enchantData.optimized
576 local qty = enchantList[id]
577 if qty then
578 qty.total = qty.total + 1
579 else
580 qty = { count = 0, total = 1, optimized = enchantData.optimized }
581 enchantList[id] = qty
582 end
583 end
584
585 local enchantMaterials = {}
586 for slot, enchantData in pairs(AskMrRobot.itemDiffs.enchants) do
587 AskMrRobot.addEnchantMaterials(enchantMaterials, enchantData.optimized)
588 end
589
590 --substract any inventory we already have in the bank
591 for i = 1, #AmrBankItemsAndCounts do
592 local itemId = AskMrRobot.getItemIdFromLink(AmrBankItemsAndCounts[i].link)
593 if itemId then
594 local gem = gemList[itemId]
595 if gem then
596 gem.count = gem.count + AmrBankItemsAndCounts[i].count
597 else
598 local alternateGemId = AskMrRobot.gemDuplicates[itemId]
599 if alternateGemId then
600 gem = gemList[alternateGemId]
601 if gem then
602 gem.count = gem.count + AmrBankItemsAndCounts[i].count
603 end
604 end
605 end
606 local material = enchantMaterials[itemId]
607 if material then
608 material.count = material.count + AmrBankItemsAndCounts[i].count
609 end
610 local enchant = enchantList[itemId]
611 if enchant then
612 enchant.count = enchant.count + AmrBankItemsAndCounts[i].count
613 end
614 end
615 end
616
617 local _ , bagItemsWithCount = AskMrRobot.ScanBags()
618
619 --substract any inventory we already have in bags
620 for i = 1, #bagItemsWithCount do
621 local itemId = AskMrRobot.getItemIdFromLink(bagItemsWithCount[i].link)
622 if itemId then
623 local gem = gemList[itemId]
624 if gem then
625 gem.count = gem.count + bagItemsWithCount[i].count
626 else
627 local alternateGemId = AskMrRobot.gemDuplicates[itemId]
628 if alternateGemId then
629 gem = gemList[alternateGemId]
630 if gem then
631 gem.count = gem.count + bagItemsWithCount[i].count
632 end
633 end
634 end
635 local material = enchantMaterials[itemId]
636 if material then
637 material.count = material.count + bagItemsWithCount[i].count
638 end
639 local enchant = enchantList[itemId]
640 if enchant then
641 enchant.count = enchant.count + bagItemsWithCount[i].count
642 end
643 end
644 end
645
646 return gemList, enchantList, enchantMaterials
647 end
648
649 function AskMrRobot.ShoppingListTab:Update()
650
651 local gemList, enchantList, enchantMaterials = self:CalculateItems()
652
653 -- update the UI
654 local lastControl = nil
655 local row = 1
656 for gemId, gemInfo in AskMrRobot.spairs(gemList) do
657 self:SetGemIcon(row, gemInfo)
658 self:SetGemText(row, gemInfo)
659 self:SetGemQuantity(row, gemInfo.count, gemInfo.total)
660 lastControl = self.gemIcons[row]
661 row = row + 1
662 end
663
664 -- hide any extra gem icons
665 for i = row, #self.gemIcons do
666 self.gemIcons[i]:Hide()
667 self.gemLinks[i]:Hide()
668 self.gemQuantity[i]:Hide()
669 end
670
671 -- hide / show the gems header, and position the enchant headers
672 if row > 1 then
673 self.gemsHeader:Show()
674 self.gemsQuantityHeader:Show()
675 self.enchantsHeader:SetPoint("TOPLEFT", self.gemIcons[row - 1], "BOTTOMLEFT", 0, -15)
676 else
677 self.gemsHeader:Hide()
678 self.gemsQuantityHeader:Hide()
679 self.enchantsHeader:SetPoint("TOPLEFT", self.scrollParent, "TOPLEFT", 0, 0)
680 end
681
682 row = 1
683 for slot, enchant in AskMrRobot.spairs(enchantList) do
684 self:SetEnchantIcon(row, enchant.optimized)
685 self:SetEnchantQuantity(row, enchant.count, enchant.total)
686 lastControl = self.enchantIcons[row]
687 row = row + 1
688 end
689
690 -- hide any extra enchant icons
691 for i = row, #self.enchantIcons do
692 self.enchantIcons[i]:Hide()
693 self.enchantQuantity[i]:Hide()
694 end
695
696 -- hide / show the enchants header, and position the enchant materials headers
697 if row > 1 then
698 self.enchantsHeader:Show()
699 self.enchantsQuantityHeader:Show()
700 self.enchantMaterialsHeader:SetPoint("TOPLEFT", self.enchantIcons[row - 1], "BOTTOMLEFT", 0, -15)
701 else
702 self.enchantsHeader:Hide()
703 self.enchantsQuantityHeader:Hide()
704 self.enchantMaterialsHeader:SetPoint("TOPLEFT", self.scrollParent, "TOPLEFT", 0, 0)
705 end
706
707 row = 1
708 for itemId, count in AskMrRobot.spairs(enchantMaterials) do
709 self:SetEnchantMaterialIcon(row, itemId)
710 self:SetEnchantMaterialLink(row, itemId)
711 self:SetEnchantMaterialQuantity(row, count.count, count.total)
712 lastControl = self.enchantMaterialIcons[row]
713 row = row + 1
714 end
715
716 for i = row, #self.enchantMaterialIcons do
717 self.enchantMaterialIcons[i]:Hide()
718 self.enchantMaterialLinks[i]:Hide()
719 self.enchantMaterialQuantity[i]:Hide()
720 end
721
722 if row == 1 then
723 self.enchantMaterialsHeader:Hide()
724 self.enchantMaterialsQuantityHeader:Hide()
725 else
726 self.enchantMaterialsHeader:Show()
727 self.enchantMaterialsQuantityHeader:Show()
728 end
729
730 -- fix up the scrollbar length
731 if lastControl then
732 local height = self.scrollParent:GetTop() - lastControl:GetBottom()
733 self.scrollParent:SetHeight(height)
734 if height < self.scrollFrame:GetHeight() then
735 self.scrollFrame.ScrollBar:Hide()
736 else
737 self.scrollFrame:Show()
738 self.scrollFrame.ScrollBar:Show()
739 end
740 self.stamp:Hide()
741 self.shoppingPanel:Show()
742 else
743 self.scrollFrame.ScrollBar:Hide()
744 self.shoppingPanel:Hide()
745 self.stamp:Show()
746 end
747 end
748
749
750 function AskMrRobot.ShoppingListTab:OnEvent(frame, event, ...)
751 local handler = self["On_" .. event]
752 if handler then
753 handler(self, ...)
754 end
755 end
756
757 function AskMrRobot.ShoppingListTab:On_MAIL_SHOW()
758 self.mailOpen = true
759 end
760
761 function AskMrRobot.ShoppingListTab:On_MAIL_CLOSED()
762 self.mailOpen = nil
763 end
764
765 function AskMrRobot.ShoppingListTab:On_AUCTION_HOUSE_SHOW()
766 self.isAuctionHouseVisible = true
767 end
768
769 function AskMrRobot.ShoppingListTab:On_AUCTION_HOUSE_CLOSED()
770 self.isAuctionHouseVisible = false
771 end
772
773 function AskMrRobot.ShoppingListTab:sendMail()
774
775 -- need mail window to be open for this to work
776 if not self.mailOpen then
777 StaticPopup_Show("SHOPPING_TAB_PLEASE_OPEN")
778 return
779 end
780
781 local message = "Mr. Robot says I need the following to optimize my gear:\n"
782
783 local gemList, enchantList, enchantMaterials = self:CalculateItems()
784
785 if AmrSendSettings.SendGems then
786 for k,v in pairs(gemList) do
787 --exclude jewelcrafter gems
788 if not AskMrRobot.JewelcrafterGems[k] then
789 local needed = v.total - v.count
790 if needed > 0 then
791 local itemName = GetItemInfo(k)
792 if itemName then
793 message = message .. "\n" .. needed .. "x " .. itemName
794 end
795 end
796 end
797 end
798 end
799
800 if AmrSendSettings.SendEnchants then
801 for k,v in pairs(enchantList) do
802 local needed = v.total - v.count
803 if needed > 0 then
804 local itemName = GetItemInfo(k)
805 if itemName then
806 message = message .. "\n" .. needed .. "x " .. itemName
807 end
808 end
809 end
810 end
811
812 if AmrSendSettings.SendEnchantMaterials then
813 for k,v in pairs(enchantMaterials) do
814 local needed = v.total - v.count
815 if needed > 0 then
816 local itemName = GetItemInfo(k)
817 if itemName then
818 message = message .. "\n" .. needed .. "x " .. itemName
819 end
820 end
821 end
822 end
823
824 MailFrameTab_OnClick(nil, 2)
825 if AmrSendSettings.SendGems then
826 if AmrSendSettings.SendEnchants then
827 SendMailSubjectEditBox:SetText('Request for gems and enchants')
828 else
829 SendMailSubjectEditBox:SetText('Request for gems')
830 end
831 else
832 SendMailSubjectEditBox:SetText('Request for enchants')
833 end
834 SendMailNameEditBox:SetText(AmrSendSettings.SendTo)
835 SendMailBodyEditBox:SetText(message)
836 end
837
838 function AskMrRobot.ShoppingListTab:Send()
839 local chatType = nil
840 if AmrSendSettings.SendToType == "party" then
841 chatType = "PARTY"
842 elseif AmrSendSettings.SendToType == "guild" then
843 chatType = "GUILD"
844 elseif AmrSendSettings.SendToType == "raid" then
845 chatType = "RAID"
846 elseif AmrSendSettings.SendToType == "channel" then
847 chatType = "CHANNEL"
848 elseif AmrSendSettings.SendToType == "mail" then
849 self:sendMail()
850 return
851 else
852 chatType = "WHISPER"
853 end
854
855 local message = "Mr. Robot says I need"
856 local count = 0
857
858
859 local gemList, enchantList, enchantMaterials = self:CalculateItems()
860
861 local items = {}
862 if AmrSendSettings.SendGems then
863 for k,v in pairs(gemList) do
864 if not AskMrRobot.JewelcrafterGems[k] then
865 local needed = v.total - v.count
866 if needed > 0 then
867 tinsert(items, {id = k, needed = needed})
868 end
869 end
870 end
871 end
872
873 if AmrSendSettings.SendEnchants then
874 for k,v in pairs(enchantList) do
875 local needed = v.total - v.count
876 if needed > 0 then
877 tinsert(items, {id = k, needed = needed})
878 end
879 end
880 end
881
882 if AmrSendSettings.SendEnchantMaterials then
883 for k,v in pairs(enchantMaterials) do
884 local needed = v.total - v.count
885 if needed > 0 then
886 tinsert(items, {id = k, needed = needed})
887 end
888 end
889 end
890
891 for i, entry in ipairs(items) do
892 local _, link = GetItemInfo(entry.id)
893 if link then
894 message = message .. " " .. entry.needed .. "x " .. link
895 count = count + 1
896 if count == 2 then
897 tinsert(self.messageQueue, {message = message, chatType = chatType, chatChannel = AmrSendSettings.SendTo})
898 count = 0
899 message = "Mr. Robot says I need"
900 end
901 end
902 end
903
904 if count > 0 then
905 tinsert(self.messageQueue, {message = message, chatType = chatType, chatChannel = AmrSendSettings.SendTo})
906 end
907
908 self:SendNextMessage()
909 end
910
911 function AskMrRobot.ShoppingListTab:SendNextMessage()
912 while #self.messageQueue > 0 do
913 local entry = self.messageQueue[1]
914 table.remove(self.messageQueue, 1)
915 SendChatMessage(entry.message, entry.chatType, nil, entry.chatChannel)
916 end
917 end