Mercurial > wow > buffalo2
comparison Modules/ArtifactPower.lua @ 101:f32b63c93275
- implement caching to reduce the number of tooltip queries made for each scan prompt
author | Nenue |
---|---|
date | Sat, 21 Jan 2017 20:12:17 -0500 |
parents | 74d6d97a2d24 |
children | 1e511e9aaca5 |
comparison
equal
deleted
inserted
replaced
100:6bf83e41b08c | 101:f32b63c93275 |
---|---|
6 | 6 |
7 local print = DEVIAN_WORKSPACE and function(...) print('VnAP', ...) end or nop | 7 local print = DEVIAN_WORKSPACE and function(...) print('VnAP', ...) end or nop |
8 VeneerArtifactPowerMixin = { | 8 VeneerArtifactPowerMixin = { |
9 numItems = 0, | 9 numItems = 0, |
10 Tokens = {}, | 10 Tokens = {}, |
11 cache = {}, | |
12 fishingCache = {}, | |
13 scanQueue = {}, | |
11 ItemButtons = {}, | 14 ItemButtons = {}, |
12 anchorPoint = 'TOP', | 15 anchorPoint = 'TOP', |
13 anchorFrom = 'TOP', | 16 anchorFrom = 'TOP', |
17 } | |
18 local defaultSettings = { | |
19 firstUse = true, | |
20 autoHide = true, | |
14 } | 21 } |
15 local ap = VeneerArtifactPowerMixin | 22 local ap = VeneerArtifactPowerMixin |
16 local BAGS_TO_SCAN = {BACKPACK_CONTAINER } | 23 local BAGS_TO_SCAN = {BACKPACK_CONTAINER } |
17 local TOOLTIP_NAME = 'VeneerAPScanner' | 24 local TOOLTIP_NAME = 'VeneerAPScanner' |
18 local POINT_COSTS = { | 25 local POINT_COSTS = { |
80 | 87 |
81 function ap:Setup() | 88 function ap:Setup() |
82 print(self:GetName()..':Setup()') | 89 print(self:GetName()..':Setup()') |
83 local guid = UnitGUID('player') | 90 local guid = UnitGUID('player') |
84 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings | 91 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings |
85 VeneerData.ArtifactPower[guid] = VeneerData.ArtifactPower[guid] or {} | 92 self.db = VeneerData.ArtifactPower |
86 self.profile = VeneerData.ArtifactPower[guid] | 93 self.db[guid] = self.db[guid] or {} |
94 self.db.cache = self.db.cache or {} | |
95 self.db.fishingCache = self.db.fishingCache or {} | |
96 | |
97 for i, data in pairs(self.cache) do | |
98 -- bring in anything found before player data is active | |
99 self.db.cache[i] = data | |
100 end | |
101 for i, data in pairs(self.fishingCache) do | |
102 self.db.fishingCache[i] = data | |
103 end | |
104 | |
105 | |
106 self.cache = self.db.cache | |
107 self.profile = self.db[guid] | |
87 self.profile.bagslots = self.profile.bagslots or {} | 108 self.profile.bagslots = self.profile.bagslots or {} |
88 self.profile.artifacts = self.profile.artifacts or {} | 109 self.profile.artifacts = self.profile.artifacts or {} |
89 self.updateSummary = true | 110 self.updateSummary = true |
111 | |
112 VeneerArtifactPowerTimer:SetScript('OnUpdate', function() | |
113 self:OnUpdate() | |
114 end) | |
90 | 115 |
91 local DoTryToShow = function() | 116 local DoTryToShow = function() |
92 self:TryToShow() | 117 self:TryToShow() |
93 end | 118 end |
94 hooksecurefunc("OpenBackpack", DoTryToShow) | 119 hooksecurefunc("OpenBackpack", DoTryToShow) |
120 hooksecurefunc(frame, name, DoTryToShow) | 145 hooksecurefunc(frame, name, DoTryToShow) |
121 end | 146 end |
122 end | 147 end |
123 end | 148 end |
124 end | 149 end |
150 | |
151 if self.db.firstUse then | |
152 self.db.firstUse = nil | |
153 | |
154 end | |
125 end | 155 end |
126 | 156 |
127 local UNDERLIGHT_ANGLER_ID = 133755 | 157 local UNDERLIGHT_ANGLER_ID = 133755 |
128 function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent) | 158 function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent) |
129 print('|cFF00FF00SetArtifact()|r') | 159 print('|cFF00FF00SetArtifact()|r') |
130 if not self.profile then | 160 if not self.profile then |
131 return | 161 return |
132 end | 162 end |
133 local artifacts = self.profile.artifacts | 163 local artifacts = self.profile.artifacts |
134 | 164 |
165 local multi = C_ArtifactUI.GetArtifactKnowledgeMultiplier() | |
166 self.profile.knowledgeMultiplier = multi or self.profile.knowledgeMultiplier | |
167 print('multiplier:', multi) | |
135 | 168 |
136 if itemID then | 169 if itemID then |
137 | 170 |
138 self.currentEquipped = itemID | 171 self.currentEquipped = itemID |
139 | 172 |
272 elseif event == 'PLAYER_REGEN_DISABLED' then | 305 elseif event == 'PLAYER_REGEN_DISABLED' then |
273 self:Hide() | 306 self:Hide() |
274 end | 307 end |
275 end | 308 end |
276 | 309 |
310 function ap:OnUpdate() | |
311 if #self.scanQueue >= 1 then | |
312 local scanInfo = tremove(self.scanQueue, 1) | |
313 | |
314 end | |
315 end | |
316 | |
277 function ap:OnMouseDown() | 317 function ap:OnMouseDown() |
278 self.enabled = nil | 318 self.enabled = nil |
279 self:Hide() | 319 self:Hide() |
280 end | 320 end |
281 | 321 |
285 return | 325 return |
286 end | 326 end |
287 print('|cFF00FFFFUpdate()|r') | 327 print('|cFF00FFFFUpdate()|r') |
288 | 328 |
289 local bankText, bagText | 329 local bankText, bagText |
290 if not (self.bankAP and self.bagAP) then | 330 if not self.profile.knowledgeMultiplier then |
331 bankText = '|cFF00FF00Shift-Right-Click an artifact weapon to start building data.' | |
332 elseif not (self.bankAP and self.bagAP) then | |
291 bankText = '|cFFFF0000Open bank frame to count all AP|r ' | 333 bankText = '|cFFFF0000Open bank frame to count all AP|r ' |
292 else | 334 else |
293 if (self.bagAP + self.bankAP) == 0 then | 335 if (self.bagAP + self.bankAP) == 0 then |
294 bankText = '|cFFFF4400No Artifact Power tokens on hand|r' | 336 bankText = '|cFFFF4400No Artifact Power tokens on hand|r' |
295 else | 337 else |
304 if self.fishingAP and self.fishingAP >= 1 then | 346 if self.fishingAP and self.fishingAP >= 1 then |
305 bankText = (bankText and (bankText .. ' ') or '') .. '|cFF0088FF' .. tostring(self.fishingAP) .. ' fishing AP|r' | 347 bankText = (bankText and (bankText .. ' ') or '') .. '|cFF0088FF' .. tostring(self.fishingAP) .. ' fishing AP|r' |
306 end | 348 end |
307 | 349 |
308 self.SummaryHeader:SetText(bankText) | 350 self.SummaryHeader:SetText(bankText) |
351 | |
352 local numButtons = 0 | |
353 local contentsHeight = 64 | |
354 if self.profile.knowledgeMultiplier then | |
355 numButtons = self:UpdateArtifactButtons() | |
356 contentsHeight = contentsHeight + self:UpdateItemButtons() | |
357 end | |
358 | |
359 | |
360 | |
361 self:SetWidth(64*numButtons + 4 * (numButtons+1)) | |
362 self:SetHeight(16 + self.SummaryHeader:GetHeight() + contentsHeight) | |
363 self:Reanchor() | |
364 end | |
365 | |
366 function ap:UpdateArtifactButtons() | |
309 | 367 |
310 -- Artifact icons, in no particular order | 368 -- Artifact icons, in no particular order |
311 self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo() | 369 self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo() |
312 local numButtons = 0 | 370 local numButtons = 0 |
313 local lastFrame = self | 371 local lastFrame = self |
339 for i = numButtons+ 1, #self.Artifact do | 397 for i = numButtons+ 1, #self.Artifact do |
340 print('hide', i) | 398 print('hide', i) |
341 self.Artifact[i]:Hide() | 399 self.Artifact[i]:Hide() |
342 end | 400 end |
343 | 401 |
344 self:UpdateItemButtons() | 402 return numButtons |
345 | |
346 | |
347 self:SetWidth(64*numButtons + 4 * (numButtons+1)) | |
348 self:SetHeight(12 + self.SummaryHeader:GetHeight() + 64) | |
349 self:Reanchor() | |
350 | |
351 end | 403 end |
352 | 404 |
353 | 405 |
354 function ap:UpdateItemButtons() | 406 function ap:UpdateItemButtons() |
355 print('|cFF00FFFFUpdateItemButtons()|r') | 407 print('|cFF00FFFFUpdateItemButtons()|r') |
356 local lastFrame, upFrame | 408 local lastFrame, upFrame |
357 local numButtons = 0 | 409 local numButtons = 0 |
410 local buttonsHeight = 0 | |
411 local buttonWidth = 0 | |
358 for index, button in ipairs(self.Tokens) do | 412 for index, button in ipairs(self.Tokens) do |
359 if button.numItems >= 1 then | 413 if button.numItems >= 1 then |
360 if button.itemName then | 414 if button.itemName then |
361 self:SetItemAction(button) | 415 self:SetItemAction(button) |
362 end | 416 end |
363 | 417 |
364 button:ClearAllPoints() | 418 button:ClearAllPoints() |
365 numButtons = numButtons + 1 | 419 numButtons = numButtons + 1 |
366 print(index, button:GetID(), button.Icon:GetTexture()) | 420 print(index, button:GetID(), button.Icon:GetTexture()) |
367 if numButtons == 1 then | 421 if numButtons == 1 then |
368 button:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -2) | 422 button:SetPoint('TOPLEFT', self, 'TOPLEFT', 4, -76) |
369 upFrame = button | 423 upFrame = button |
424 buttonsHeight = 52 | |
370 elseif mod(numButtons,8) == 1 then | 425 elseif mod(numButtons,8) == 1 then |
371 button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2) | 426 button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2) |
372 upFrame = button | 427 upFrame = button |
428 buttonsHeight = buttonsHeight + 52 | |
373 else | 429 else |
374 button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0) | 430 button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0) |
375 end | 431 end |
376 button.Count:SetText(button.numItems) | 432 button.Count:SetText(button.numItems) |
377 lastFrame = button | 433 lastFrame = button |
378 button:Show() | 434 button:Show() |
379 else | 435 else |
380 | |
381 button:Hide() | 436 button:Hide() |
382 end | 437 end |
383 | 438 end |
384 end | 439 |
385 | 440 |
441 | |
442 return buttonsHeight | |
386 end | 443 end |
387 | 444 |
388 function ap:SetItemAction(button, name) | 445 function ap:SetItemAction(button, name) |
389 name = name or self.itemName | 446 name = name or self.itemName |
390 if InCombatLockdown() then | 447 if InCombatLockdown() then |
397 end | 454 end |
398 | 455 |
399 function ap:GetItemButton(itemID, texture, itemAP) | 456 function ap:GetItemButton(itemID, texture, itemAP) |
400 print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP) | 457 print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP) |
401 local button = self.ItemButtons[itemID] | 458 local button = self.ItemButtons[itemID] |
459 | |
402 if not button then | 460 if not button then |
403 button = CreateFrame('Button', 'VeneerAPToken'..itemID, self, 'VeneerItemButton') | 461 button = CreateFrame('Button', 'VeneerAPToken'..itemID, self, 'VeneerItemButton') |
462 button.baseAP = itemAP | |
463 | |
404 button:SetPushedTexture([[Interface\Buttons\UI-Quickslot-Depress]]) | 464 button:SetPushedTexture([[Interface\Buttons\UI-Quickslot-Depress]]) |
405 button:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]],"ADD") | 465 button:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]],"ADD") |
406 button:SetID(itemID) | 466 button:SetID(itemID) |
407 button.numItems = 0 | 467 button.numItems = 0 |
408 button.Icon:SetTexture(texture) | 468 button.Icon:SetTexture(texture) |
409 button.Label:SetText(itemAP) | |
410 button:RegisterForClicks("AnyUp") | 469 button:RegisterForClicks("AnyUp") |
411 self:SetItemAction(button, GetItemInfo(itemID)) | 470 self:SetItemAction(button, GetItemInfo(itemID)) |
412 | 471 |
413 print(' created') | 472 print(' created') |
414 self.ItemButtons[itemID] = button | 473 self.ItemButtons[itemID] = button |
415 self.numItems = self.numItems + 1 | 474 self.numItems = self.numItems + 1 |
416 end | 475 end |
417 | 476 |
477 local itemAPtext = itemAP * self.profile.knowledgeMultiplier | |
478 if itemAPtext >= 100000 then | |
479 itemAPtext = floor(itemAPtext/1000) .. 'k' | |
480 elseif itemAPtext >= 1000 then | |
481 itemAPtext = (floor(itemAPtext/100)/10 ) .. 'k' | |
482 end | |
483 button.Label:SetText(itemAPtext) | |
484 | |
418 button.numItems = button.numItems + 1 | 485 button.numItems = button.numItems + 1 |
419 return button | 486 return button |
487 end | |
488 | |
489 function ap:GetItemAP(itemID, itemLink, bagData) | |
490 if not self.cache[itemID] then | |
491 | |
492 print('doing tooltip scan') | |
493 self.tooltip:SetOwner(self, 'ANCHOR_NONE') | |
494 self.tooltip:SetHyperlink(itemLink) | |
495 self.tooltip:Show() | |
496 local numLines = self.tooltip:NumLines() | |
497 if numLines >= 3 then | |
498 local subText = _G[TOOLTIP_NAME .. 'TextLeft2']:GetText() | |
499 if subText and subText:match(ARTIFACT_POWER) then | |
500 for i = 3, numLines do | |
501 local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText() | |
502 if text and text:match(ARTIFACT_POWER) then | |
503 text = text:gsub('[,%D]', '') | |
504 print(itemLink, '-', tonumber(text)) | |
505 local itemAP = tonumber(text) | |
506 if itemAP then | |
507 itemAP = itemAP / self.profile.knowledgeMultiplier | |
508 self.cache[itemID] = itemAP | |
509 return itemAP | |
510 end | |
511 end | |
512 end | |
513 end | |
514 local fishingText = _G[TOOLTIP_NAME .. 'TextLeft3']:GetText() | |
515 if fishingText and fishingText:match('fishing artifact') then | |
516 local fishingAP = fishingText:match("%d+") | |
517 fishingAP = tonumber(fishingAP) | |
518 if fishingAP then | |
519 self.cache[itemID] = fishingAP | |
520 self.fishingCache[itemID] = true | |
521 return fishingAP, true | |
522 end | |
523 end | |
524 else | |
525 | |
526 self.cache[itemID] = 0 | |
527 end | |
528 end | |
529 return self.cache[itemID], self.fishingCache[itemID] | |
420 end | 530 end |
421 | 531 |
422 function ap:ScanBag(id) | 532 function ap:ScanBag(id) |
423 print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id)) | 533 print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id)) |
424 local numSlots = GetContainerNumSlots(id) | 534 local numSlots = GetContainerNumSlots(id) |
436 bagData.items = bagData.items or {} | 546 bagData.items = bagData.items or {} |
437 table.wipe(bagData.items) | 547 table.wipe(bagData.items) |
438 | 548 |
439 for slotID = 1, numSlots do | 549 for slotID = 1, numSlots do |
440 local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID) | 550 local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID) |
441 local itemID = GetContainerItemID(id, slotID) | |
442 | |
443 if link then | 551 if link then |
444 self.tooltip:SetOwner(self, 'ANCHOR_NONE') | 552 local itemID = GetContainerItemID(id, slotID) |
445 self.tooltip:SetHyperlink(link) | 553 local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link) |
446 self.tooltip:Show() | 554 |
447 local numLines = self.tooltip:NumLines() | 555 if class == 'Consumable' and subclass == 'Other' then |
448 if numLines >= 3 then | 556 print(GetItemInfo(link)) |
449 local subText = _G[TOOLTIP_NAME .. 'TextLeft2']:GetText() | 557 local itemAP, isFishingAP = self:GetItemAP(itemID, link) |
450 if subText and subText:match(ARTIFACT_POWER) then | 558 print(itemAP, isFishingAP) |
451 for i = 3, numLines do | 559 if itemAP > 0 then |
452 local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText() | 560 if isFishingAP then |
453 if text and text:match(ARTIFACT_POWER) then | 561 bagData.fishingItems = (bagData.fishingItems or 0) + 1 |
454 text = text:gsub('[,%D]', '') | 562 bagData.fishingAP = (bagData.fishingAP or 0) + itemAP |
455 print(link, '-', tonumber(text)) | 563 else |
456 local itemAP = tonumber(text) | 564 |
457 if itemAP then | 565 bagData.numItems = (bagData.numItems or 0) + 1 |
458 requiresUpdate = true | 566 bagData.totalAP = (bagData.totalAP or 0) + itemAP |
459 bagData.numItems = (bagData.numItems or 0) + 1 | |
460 bagData.totalAP = (bagData.totalAP or 0) + itemAP | |
461 bagData.items[itemID] = (bagData.items[itemID] or 0) + 1 | |
462 | |
463 | |
464 local itemButton = self:GetItemButton(itemID, texture, itemAP) | |
465 end | |
466 end | |
467 end | 567 end |
568 bagData.items[itemID] = (bagData.items[itemID] or 0) + 1 | |
569 local itemButton = self:GetItemButton(itemID, texture, itemAP) | |
468 end | 570 end |
469 local fishingText = _G[TOOLTIP_NAME .. 'TextLeft3']:GetText() | 571 elseif self.profile.artifacts[itemID] then |
470 if fishingText and fishingText:match('fishing artifact') then | 572 print('artfiact weapon', itemID, link, id, slotID) |
471 local fishingAP = fishingText:match("%d+") | 573 self.profile.artifacts[itemID].containerID = id |
472 fishingAP = tonumber(fishingAP) | 574 self.profile.artifacts[itemID].slotID = slotID |
473 if fishingAP then | 575 end |
474 bagData.fishingItems = (bagData.fishingItems or 0) + 1 | 576 |
475 bagData.fishingAP = (bagData.fishingAP or 0) + fishingAP | |
476 bagData.items[itemID] = (bagData.items[itemID] or 0) + 1 | |
477 local itemButton = self:GetItemButton(itemID, texture, fishingAP) | |
478 print(fishingAP, bagData.fishingAP) | |
479 end | |
480 | |
481 end | |
482 | |
483 end | |
484 end | |
485 | |
486 if self.profile.artifacts[itemID] then | |
487 print('artfiact weapon', itemID, link, id, slotID) | |
488 self.profile.artifacts[itemID].containerID = id | |
489 self.profile.artifacts[itemID].slotID = slotID | |
490 end | 577 end |
491 | 578 |
492 end | 579 end |
493 | 580 |
494 end | 581 end |
499 function ap:ScanAllBags() | 586 function ap:ScanAllBags() |
500 if InCombatLockdown() then | 587 if InCombatLockdown() then |
501 self.queuedScan = true | 588 self.queuedScan = true |
502 return | 589 return |
503 end | 590 end |
591 if not self.profile.knowledgeMultiplier then | |
592 print('need to get knowledge level') | |
593 return | |
594 end | |
595 | |
504 self.queuedScan = nil | 596 self.queuedScan = nil |
505 | 597 |
506 print('|cFFFF0088ScanAllBags()|r') | 598 print('|cFFFF0088ScanAllBags()|r', self.profile.knowledgeMultiplier) |
507 | 599 |
508 for _, button in ipairs(self.Tokens) do | 600 for _, button in ipairs(self.Tokens) do |
509 button.numItems = 0 | 601 button.numItems = 0 |
510 end | 602 end |
511 | 603 |
633 if self.level <= 53 then | 725 if self.level <= 53 then |
634 | 726 |
635 self.CurrentProgress.animateFrom = self.CurrentProgress:GetHeight() or 1 | 727 self.CurrentProgress.animateFrom = self.CurrentProgress:GetHeight() or 1 |
636 self.CurrentProgress.animateTo = currentProgress * self:GetHeight() | 728 self.CurrentProgress.animateTo = currentProgress * self:GetHeight() |
637 self.CurrentProgress:Show() | 729 self.CurrentProgress:Show() |
730 self.ProgressLine:Show() | |
638 else | 731 else |
639 self.CurrentProgress:Hide() | 732 self.CurrentProgress:Hide() |
733 self.ProgressLine:Hide() | |
640 end | 734 end |
641 | 735 |
642 if self.potentialXP > self.currentXP then | 736 if self.potentialXP > self.currentXP then |
643 local projectedProgress = (self.potentialAdjustedXP < self.potentialCost) and (self.potentialXP / self.potentialCost) or 1 | 737 local projectedProgress = (self.potentialAdjustedXP < self.potentialCost) and (self.potentialXP / self.potentialCost) or 1 |
644 | 738 |
651 end | 745 end |
652 print('show potential', currentProgress, projectedProgress) | 746 print('show potential', currentProgress, projectedProgress) |
653 self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1 | 747 self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1 |
654 self.AdjustedProgress.animateTo = projectedProgress * self:GetHeight() | 748 self.AdjustedProgress.animateTo = projectedProgress * self:GetHeight() |
655 | 749 |
750 self.AdjustedLine:Show() | |
656 self.AdjustedProgress:Show() | 751 self.AdjustedProgress:Show() |
657 else | 752 else |
658 self.AdjustedProgress:Hide() | 753 self.AdjustedProgress:Hide() |
754 self.AdjustedLine:Hide() | |
659 end | 755 end |
660 | 756 |
661 | 757 |
662 self.Icon:SetTexture(self.texture) | 758 self.Icon:SetTexture(self.texture) |
663 self:SetSize(64,64) | 759 self:SetSize(64,64) |