Mercurial > wow > askmrrobot
comparison Shopping.lua @ 81:0515882856f1 v38
updated for 7.0
author | yellowfive |
---|---|
date | Tue, 19 Jul 2016 10:05:32 -0700 |
parents | cf2b6b9a8337 |
children | 6bbe64d587b4 |
comparison
equal
deleted
inserted
replaced
80:8f235b016212 | 81:0515882856f1 |
---|---|
4 | 4 |
5 local _frameShop | 5 local _frameShop |
6 local _panelContent | 6 local _panelContent |
7 local _cboPlayers | 7 local _cboPlayers |
8 local _selectedPlayer | 8 local _selectedPlayer |
9 | |
9 local _specs = { | 10 local _specs = { |
10 [1] = true, | 11 [1] = true, |
11 [2] = true | 12 [2] = true, |
13 [3] = true, | |
14 [4] = true, | |
12 } | 15 } |
16 | |
13 local _chk1 | 17 local _chk1 |
14 local _chk2 | 18 local _chk2 |
19 local _chk3 | |
20 local _chk4 | |
15 local _isAhOpen = false | 21 local _isAhOpen = false |
16 | 22 |
17 local function onShopFrameClose(widget) | 23 local function onShopFrameClose(widget) |
18 AceGUI:Release(widget) | 24 AceGUI:Release(widget) |
19 _frameShop = nil | 25 _frameShop = nil |
20 _cboPlayers = nil | 26 _cboPlayers = nil |
21 _chk1 = nil | 27 _chk1 = nil |
22 _chk2 = nil | 28 _chk2 = nil |
29 _chk3 = nil | |
30 _chk4 = nil | |
23 _panelContent = nil | 31 _panelContent = nil |
24 end | 32 end |
25 | 33 |
26 function Amr:HideShopWindow() | 34 function Amr:HideShopWindow() |
27 if not _frameShop then return end | 35 if not _frameShop then return end |
92 _chk2:SetPoint("LEFT", _chk1.frame, "RIGHT", 30, 0) | 100 _chk2:SetPoint("LEFT", _chk1.frame, "RIGHT", 30, 0) |
93 _chk2:SetUserData("spec", 2) | 101 _chk2:SetUserData("spec", 2) |
94 _chk2:SetCallback("OnClick", onSpecClick) | 102 _chk2:SetCallback("OnClick", onSpecClick) |
95 _frameShop:AddChild(_chk2) | 103 _frameShop:AddChild(_chk2) |
96 | 104 |
105 _chk3 = AceGUI:Create("AmrUiCheckBox") | |
106 _chk3:SetPoint("LEFT", _chk2.frame, "RIGHT", 30, 0) | |
107 _chk3:SetUserData("spec", 3) | |
108 _chk3:SetCallback("OnClick", onSpecClick) | |
109 _frameShop:AddChild(_chk3) | |
110 | |
111 _chk4 = AceGUI:Create("AmrUiCheckBox") | |
112 _chk4:SetPoint("LEFT", _chk3.frame, "RIGHT", 30, 0) | |
113 _chk4:SetUserData("spec", 4) | |
114 _chk4:SetCallback("OnClick", onSpecClick) | |
115 _frameShop:AddChild(_chk4) | |
116 | |
97 _panelContent = AceGUI:Create("AmrUiPanel") | 117 _panelContent = AceGUI:Create("AmrUiPanel") |
98 _panelContent:SetLayout("None") | 118 _panelContent:SetLayout("None") |
99 _panelContent:SetTransparent() | 119 _panelContent:SetTransparent() |
100 _panelContent:SetPoint("TOPLEFT", _chk1.frame, "BOTTOMLEFT", 0, -10) | 120 _panelContent:SetPoint("TOPLEFT", _chk1.frame, "BOTTOMLEFT", 0, -10) |
101 _panelContent:SetPoint("BOTTOMRIGHT", _frameShop.content, "BOTTOMRIGHT") | 121 _panelContent:SetPoint("BOTTOMRIGHT", _frameShop.content, "BOTTOMRIGHT") |
197 | 217 |
198 function Amr:RefreshShoppingUi() | 218 function Amr:RefreshShoppingUi() |
199 | 219 |
200 _chk1:SetVisible(false) | 220 _chk1:SetVisible(false) |
201 _chk2:SetVisible(false) | 221 _chk2:SetVisible(false) |
222 _chk3:SetVisible(false) | |
223 _chk4:SetVisible(false) | |
202 | 224 |
203 _chk1:SetChecked(false) | 225 _chk1:SetChecked(false) |
204 _chk2:SetChecked(false) | 226 _chk2:SetChecked(false) |
227 _chk3:SetChecked(false) | |
228 _chk4:SetChecked(false) | |
205 | 229 |
206 -- clear out any previous data | 230 -- clear out any previous data |
207 _panelContent:ReleaseChildren() | 231 _panelContent:ReleaseChildren() |
208 | 232 |
209 -- render required gems for the selected player | |
210 local data = Amr.db.global.Shopping[_selectedPlayer] | 233 local data = Amr.db.global.Shopping[_selectedPlayer] |
211 if not data then | 234 if not data then |
212 _panelContent:SetLayout("None") | 235 _panelContent:SetLayout("None") |
213 | 236 |
214 local lbl = AceGUI:Create("AmrUiLabel") | 237 local lbl = AceGUI:Create("AmrUiLabel") |
218 lbl:SetPoint("TOP", _panelContent.content, "TOP", 0, -30) | 241 lbl:SetPoint("TOP", _panelContent.content, "TOP", 0, -30) |
219 _panelContent:AddChild(lbl) | 242 _panelContent:AddChild(lbl) |
220 else | 243 else |
221 -- set labels on checkboxes | 244 -- set labels on checkboxes |
222 if data.specs[1] and data.specs[1] ~= 0 then | 245 if data.specs[1] and data.specs[1] ~= 0 then |
223 local id, name = GetSpecializationInfoByID(Amr.GetGameSpecId(data.specs[1])) | 246 _chk1:SetText(L.SpecsShort[data.specs[1]]) |
224 _chk1:SetText(name .. " " .. L.ShopSpecLabel) | |
225 _chk1:SetVisible(true) | 247 _chk1:SetVisible(true) |
226 _chk1:SetChecked(_specs[1]) | 248 _chk1:SetChecked(_specs[1]) |
227 end | 249 end |
228 | 250 |
229 if data.specs[2] and data.specs[2] ~= 0 then | 251 if data.specs[2] and data.specs[2] ~= 0 then |
230 local id, name = GetSpecializationInfoByID(Amr.GetGameSpecId(data.specs[2])) | 252 _chk2:SetText(L.SpecsShort[data.specs[2]]) |
231 _chk2:SetText(name .. " " .. L.ShopSpecLabel) | |
232 _chk2:SetVisible(true) | 253 _chk2:SetVisible(true) |
233 _chk2:SetChecked(_specs[2]) | 254 _chk2:SetChecked(_specs[2]) |
234 end | 255 end |
235 | 256 |
257 if data.specs[3] and data.specs[3] ~= 0 then | |
258 _chk3:SetText(L.SpecsShort[data.specs[3]]) | |
259 _chk3:SetVisible(true) | |
260 _chk3:SetChecked(_specs[3]) | |
261 end | |
262 | |
263 if data.specs[4] and data.spes[4] ~= 0 then | |
264 _chk4:SetText(L.SpecsShort[data.specs[4]]) | |
265 _chk4:SetVisible(true) | |
266 _chk4:SetChecked(_specs[4]) | |
267 end | |
268 | |
236 local spec = 0 | 269 local spec = 0 |
237 if not _specs[1] and not _specs[2] then | 270 if not _specs[1] and not _specs[2] and not _specs[3] and not _specs[4] then |
238 -- both unchecked, show nothing | 271 -- all unchecked, show nothing |
239 else | 272 else |
240 -- both is 0, otherwise the one that is selected | 273 -- both is 0, otherwise the one that is selected |
241 if not _specs[1] or not _specs[2] then | 274 if not _specs[1] or not _specs[2] then |
242 spec = _specs[1] and 1 or 2 | 275 spec = _specs[1] and 1 or 2 |
243 end | 276 end |
318 end | 351 end |
319 | 352 |
320 -- look at both gear sets and find stuff that a player needs to acquire to gem/enchant their gear | 353 -- look at both gear sets and find stuff that a player needs to acquire to gem/enchant their gear |
321 function Amr:UpdateShoppingData(player) | 354 function Amr:UpdateShoppingData(player) |
322 | 355 |
323 -- 0 is combination of both specs, 1 is primary, 2 is secondary | 356 -- TODO: re-enable shopping list when Legion comes out |
357 do return end | |
358 | |
359 -- 0 is combination of all specs | |
324 local required = { | 360 local required = { |
325 gems = { | 361 gems = { |
326 [0] = {}, | 362 [0] = {}, |
327 [1] = {}, | 363 [1] = {}, |
328 [2] = {} | 364 [2] = {}, |
365 [3] = {}, | |
366 [4] = {} | |
329 }, | 367 }, |
330 enchants = { | 368 enchants = { |
331 [0] = {}, | 369 [0] = {}, |
332 [1] = {}, | 370 [1] = {}, |
333 [2] = {} | 371 [2] = {}, |
372 [3] = {}, | |
373 [4] = {} | |
334 }, | 374 }, |
335 materials = { | 375 materials = { |
336 [0] = {}, | 376 [0] = {}, |
337 [1] = {}, | 377 [1] = {}, |
338 [2] = {} | 378 [2] = {}, |
379 [3] = {}, | |
380 [4] = {} | |
339 }, | 381 }, |
340 specs = player.Specs | 382 specs = player.Specs |
341 } | 383 } |
342 | 384 |
343 local enchantItemIdToId = {} | 385 local enchantItemIdToId = {} |
367 end | 409 end |
368 end | 410 end |
369 end | 411 end |
370 | 412 |
371 -- now subtract stuff the player already has, and generate a list of materials as well | 413 -- now subtract stuff the player already has, and generate a list of materials as well |
372 for spec = 0, 2 do | 414 for spec = 0, 4 do |
373 -- now check if the player has any of the gems or enchants in their inventory, and subtract those | 415 local specId = spec == 0 and 1 or GetSpecializationInfo(spec) |
374 for itemId, count in pairs(required.gems[spec]) do | 416 if specId then |
375 required.gems[spec][itemId] = math.max(count - getOwnedCount(itemId), 0) | 417 -- now check if the player has any of the gems or enchants in their inventory, and subtract those |
376 | 418 for itemId, count in pairs(required.gems[spec]) do |
377 if required.gems[spec][itemId] == 0 then | 419 required.gems[spec][itemId] = math.max(count - getOwnedCount(itemId), 0) |
378 required.gems[spec][itemId] = nil | 420 |
379 end | 421 if required.gems[spec][itemId] == 0 then |
380 end | 422 required.gems[spec][itemId] = nil |
381 | |
382 for itemId, count in pairs(required.enchants[spec]) do | |
383 -- look in both spec extra info cache | |
384 local e = enchantItemIdToId[itemId] | |
385 local enchInfo = nil | |
386 if Amr.db.char.ExtraEnchantData[1] then | |
387 enchInfo = Amr.db.char.ExtraEnchantData[1][e] | |
388 end | |
389 if not enchInfo then | |
390 if Amr.db.char.ExtraEnchantData[2] then | |
391 enchInfo = Amr.db.char.ExtraEnchantData[2][e] | |
392 end | 423 end |
393 end | 424 end |
394 | 425 |
395 if enchInfo then | 426 for itemId, count in pairs(required.enchants[spec]) do |
396 required.enchants[spec][itemId] = math.max(count - getOwnedCount(itemId), 0) | 427 -- look in both spec extra info cache |
397 | 428 local e = enchantItemIdToId[itemId] |
398 if required.enchants[spec][itemId] == 0 then | 429 local enchInfo = nil |
399 required.enchants[spec][itemId] = nil | 430 if Amr.db.char.ExtraEnchantData[1] then |
400 else | 431 enchInfo = Amr.db.char.ExtraEnchantData[1][e] |
401 -- count up required materials | 432 end |
402 if enchInfo.materials then | 433 if not enchInfo then |
403 local c = required.enchants[spec][itemId] | 434 if Amr.db.char.ExtraEnchantData[2] then |
404 for k, v in pairs(enchInfo.materials) do | 435 enchInfo = Amr.db.char.ExtraEnchantData[2][e] |
405 local prev = required.materials[spec][k] | 436 end |
406 required.materials[spec][k] = prev and prev + (v * c) or (v * c) | 437 end |
438 | |
439 if enchInfo then | |
440 required.enchants[spec][itemId] = math.max(count - getOwnedCount(itemId), 0) | |
441 | |
442 if required.enchants[spec][itemId] == 0 then | |
443 required.enchants[spec][itemId] = nil | |
444 else | |
445 -- count up required materials | |
446 if enchInfo.materials then | |
447 local c = required.enchants[spec][itemId] | |
448 for k, v in pairs(enchInfo.materials) do | |
449 local prev = required.materials[spec][k] | |
450 required.materials[spec][k] = prev and prev + (v * c) or (v * c) | |
451 end | |
407 end | 452 end |
408 end | 453 end |
409 end | 454 end |
410 end | 455 end |
411 end | 456 |
412 | 457 -- check if player has any of the materials already |
413 -- check if player has any of the materials already | 458 for itemId, count in pairs(required.materials[spec]) do |
414 for itemId, count in pairs(required.materials[spec]) do | 459 required.materials[spec][itemId] = math.max(count - getOwnedCount(itemId), 0) |
415 required.materials[spec][itemId] = math.max(count - getOwnedCount(itemId), 0) | 460 |
416 | 461 if required.materials[spec][itemId] == 0 then |
417 if required.materials[spec][itemId] == 0 then | 462 required.materials[spec][itemId] = nil |
418 required.materials[spec][itemId] = nil | 463 end |
419 end | 464 end |
420 end | 465 end |
421 end | 466 end |
422 | 467 |
423 Amr.db.global.Shopping[player.Name .. "-" .. player.Realm] = required | 468 Amr.db.global.Shopping[player.Name .. "-" .. player.Realm] = required |
424 end | 469 end |
425 | 470 |
471 -- TODO: re-enable shopping list with Legion | |
472 --[[ | |
426 Amr:AddEventHandler("AUCTION_HOUSE_SHOW", function() | 473 Amr:AddEventHandler("AUCTION_HOUSE_SHOW", function() |
427 _isAhOpen = true | 474 _isAhOpen = true |
428 if Amr.db.profile.options.shopAh then | 475 if Amr.db.profile.options.shopAh then |
429 Amr:ShowShopWindow() | 476 Amr:ShowShopWindow() |
430 end | 477 end |
434 _isAhOpen = false | 481 _isAhOpen = false |
435 if Amr.db.profile.options.shopAh then | 482 if Amr.db.profile.options.shopAh then |
436 Amr:HideShopWindow() | 483 Amr:HideShopWindow() |
437 end | 484 end |
438 end) | 485 end) |
486 ]] |