# HG changeset patch # User Nenue # Date 1485047537 18000 # Node ID f32b63c932750686d71b0ca249d828d1448099f8 # Parent 6bf83e41b08c7cdfb716dc8c2bf15e22d1f70c62 - implement caching to reduce the number of tooltip queries made for each scan prompt diff -r 6bf83e41b08c -r f32b63c93275 Modules/ArtifactPower.lua --- a/Modules/ArtifactPower.lua Fri Jan 20 19:58:37 2017 -0500 +++ b/Modules/ArtifactPower.lua Sat Jan 21 20:12:17 2017 -0500 @@ -8,10 +8,17 @@ VeneerArtifactPowerMixin = { numItems = 0, Tokens = {}, + cache = {}, + fishingCache = {}, + scanQueue = {}, ItemButtons = {}, anchorPoint = 'TOP', anchorFrom = 'TOP', } +local defaultSettings = { + firstUse = true, + autoHide = true, +} local ap = VeneerArtifactPowerMixin local BAGS_TO_SCAN = {BACKPACK_CONTAINER } local TOOLTIP_NAME = 'VeneerAPScanner' @@ -82,12 +89,30 @@ print(self:GetName()..':Setup()') local guid = UnitGUID('player') VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings - VeneerData.ArtifactPower[guid] = VeneerData.ArtifactPower[guid] or {} - self.profile = VeneerData.ArtifactPower[guid] + self.db = VeneerData.ArtifactPower + self.db[guid] = self.db[guid] or {} + self.db.cache = self.db.cache or {} + self.db.fishingCache = self.db.fishingCache or {} + + for i, data in pairs(self.cache) do + -- bring in anything found before player data is active + self.db.cache[i] = data + end + for i, data in pairs(self.fishingCache) do + self.db.fishingCache[i] = data + end + + + self.cache = self.db.cache + self.profile = self.db[guid] self.profile.bagslots = self.profile.bagslots or {} self.profile.artifacts = self.profile.artifacts or {} self.updateSummary = true + VeneerArtifactPowerTimer:SetScript('OnUpdate', function() + self:OnUpdate() + end) + local DoTryToShow = function() self:TryToShow() end @@ -122,6 +147,11 @@ end end end + + if self.db.firstUse then + self.db.firstUse = nil + + end end local UNDERLIGHT_ANGLER_ID = 133755 @@ -132,6 +162,9 @@ end local artifacts = self.profile.artifacts + local multi = C_ArtifactUI.GetArtifactKnowledgeMultiplier() + self.profile.knowledgeMultiplier = multi or self.profile.knowledgeMultiplier + print('multiplier:', multi) if itemID then @@ -274,6 +307,13 @@ end end +function ap:OnUpdate() + if #self.scanQueue >= 1 then + local scanInfo = tremove(self.scanQueue, 1) + + end +end + function ap:OnMouseDown() self.enabled = nil self:Hide() @@ -287,7 +327,9 @@ print('|cFF00FFFFUpdate()|r') local bankText, bagText - if not (self.bankAP and self.bagAP) then + if not self.profile.knowledgeMultiplier then + bankText = '|cFF00FF00Shift-Right-Click an artifact weapon to start building data.' + elseif not (self.bankAP and self.bagAP) then bankText = '|cFFFF0000Open bank frame to count all AP|r ' else if (self.bagAP + self.bankAP) == 0 then @@ -307,6 +349,22 @@ self.SummaryHeader:SetText(bankText) + local numButtons = 0 + local contentsHeight = 64 + if self.profile.knowledgeMultiplier then + numButtons = self:UpdateArtifactButtons() + contentsHeight = contentsHeight + self:UpdateItemButtons() + end + + + + self:SetWidth(64*numButtons + 4 * (numButtons+1)) + self:SetHeight(16 + self.SummaryHeader:GetHeight() + contentsHeight) + self:Reanchor() +end + +function ap:UpdateArtifactButtons() + -- Artifact icons, in no particular order self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo() local numButtons = 0 @@ -341,13 +399,7 @@ self.Artifact[i]:Hide() end - self:UpdateItemButtons() - - - self:SetWidth(64*numButtons + 4 * (numButtons+1)) - self:SetHeight(12 + self.SummaryHeader:GetHeight() + 64) - self:Reanchor() - + return numButtons end @@ -355,6 +407,8 @@ print('|cFF00FFFFUpdateItemButtons()|r') local lastFrame, upFrame local numButtons = 0 + local buttonsHeight = 0 + local buttonWidth = 0 for index, button in ipairs(self.Tokens) do if button.numItems >= 1 then if button.itemName then @@ -365,11 +419,13 @@ numButtons = numButtons + 1 print(index, button:GetID(), button.Icon:GetTexture()) if numButtons == 1 then - button:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -2) + button:SetPoint('TOPLEFT', self, 'TOPLEFT', 4, -76) upFrame = button + buttonsHeight = 52 elseif mod(numButtons,8) == 1 then button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2) upFrame = button + buttonsHeight = buttonsHeight + 52 else button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0) end @@ -377,12 +433,13 @@ lastFrame = button button:Show() else - button:Hide() end - end + + + return buttonsHeight end function ap:SetItemAction(button, name) @@ -399,14 +456,16 @@ function ap:GetItemButton(itemID, texture, itemAP) print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP) local button = self.ItemButtons[itemID] + if not button then button = CreateFrame('Button', 'VeneerAPToken'..itemID, self, 'VeneerItemButton') + button.baseAP = itemAP + button:SetPushedTexture([[Interface\Buttons\UI-Quickslot-Depress]]) button:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]],"ADD") button:SetID(itemID) button.numItems = 0 button.Icon:SetTexture(texture) - button.Label:SetText(itemAP) button:RegisterForClicks("AnyUp") self:SetItemAction(button, GetItemInfo(itemID)) @@ -415,10 +474,61 @@ self.numItems = self.numItems + 1 end + local itemAPtext = itemAP * self.profile.knowledgeMultiplier + if itemAPtext >= 100000 then + itemAPtext = floor(itemAPtext/1000) .. 'k' + elseif itemAPtext >= 1000 then + itemAPtext = (floor(itemAPtext/100)/10 ) .. 'k' + end + button.Label:SetText(itemAPtext) + button.numItems = button.numItems + 1 return button end +function ap:GetItemAP(itemID, itemLink, bagData) + if not self.cache[itemID] then + + print('doing tooltip scan') + self.tooltip:SetOwner(self, 'ANCHOR_NONE') + self.tooltip:SetHyperlink(itemLink) + self.tooltip:Show() + local numLines = self.tooltip:NumLines() + if numLines >= 3 then + local subText = _G[TOOLTIP_NAME .. 'TextLeft2']:GetText() + if subText and subText:match(ARTIFACT_POWER) then + for i = 3, numLines do + local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText() + if text and text:match(ARTIFACT_POWER) then + text = text:gsub('[,%D]', '') + print(itemLink, '-', tonumber(text)) + local itemAP = tonumber(text) + if itemAP then + itemAP = itemAP / self.profile.knowledgeMultiplier + self.cache[itemID] = itemAP + return itemAP + end + end + end + end + local fishingText = _G[TOOLTIP_NAME .. 'TextLeft3']:GetText() + if fishingText and fishingText:match('fishing artifact') then + local fishingAP = fishingText:match("%d+") + fishingAP = tonumber(fishingAP) + if fishingAP then + self.cache[itemID] = fishingAP + self.fishingCache[itemID] = true + return fishingAP, true + end + end + else + + self.cache[itemID] = 0 + end + end + return self.cache[itemID], self.fishingCache[itemID] +end + function ap:ScanBag(id) print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id)) local numSlots = GetContainerNumSlots(id) @@ -438,55 +548,32 @@ for slotID = 1, numSlots do local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID) - local itemID = GetContainerItemID(id, slotID) + if link then + local itemID = GetContainerItemID(id, slotID) + local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link) - if link then - self.tooltip:SetOwner(self, 'ANCHOR_NONE') - self.tooltip:SetHyperlink(link) - self.tooltip:Show() - local numLines = self.tooltip:NumLines() - if numLines >= 3 then - local subText = _G[TOOLTIP_NAME .. 'TextLeft2']:GetText() - if subText and subText:match(ARTIFACT_POWER) then - for i = 3, numLines do - local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText() - if text and text:match(ARTIFACT_POWER) then - text = text:gsub('[,%D]', '') - print(link, '-', tonumber(text)) - local itemAP = tonumber(text) - if itemAP then - requiresUpdate = true - bagData.numItems = (bagData.numItems or 0) + 1 - bagData.totalAP = (bagData.totalAP or 0) + itemAP - bagData.items[itemID] = (bagData.items[itemID] or 0) + 1 + if class == 'Consumable' and subclass == 'Other' then + print(GetItemInfo(link)) + local itemAP, isFishingAP = self:GetItemAP(itemID, link) + print(itemAP, isFishingAP) + if itemAP > 0 then + if isFishingAP then + bagData.fishingItems = (bagData.fishingItems or 0) + 1 + bagData.fishingAP = (bagData.fishingAP or 0) + itemAP + else + bagData.numItems = (bagData.numItems or 0) + 1 + bagData.totalAP = (bagData.totalAP or 0) + itemAP + end + bagData.items[itemID] = (bagData.items[itemID] or 0) + 1 + local itemButton = self:GetItemButton(itemID, texture, itemAP) + end + elseif self.profile.artifacts[itemID] then + print('artfiact weapon', itemID, link, id, slotID) + self.profile.artifacts[itemID].containerID = id + self.profile.artifacts[itemID].slotID = slotID + end - local itemButton = self:GetItemButton(itemID, texture, itemAP) - end - end - end - end - local fishingText = _G[TOOLTIP_NAME .. 'TextLeft3']:GetText() - if fishingText and fishingText:match('fishing artifact') then - local fishingAP = fishingText:match("%d+") - fishingAP = tonumber(fishingAP) - if fishingAP then - bagData.fishingItems = (bagData.fishingItems or 0) + 1 - bagData.fishingAP = (bagData.fishingAP or 0) + fishingAP - bagData.items[itemID] = (bagData.items[itemID] or 0) + 1 - local itemButton = self:GetItemButton(itemID, texture, fishingAP) - print(fishingAP, bagData.fishingAP) - end - - end - - end - end - - if self.profile.artifacts[itemID] then - print('artfiact weapon', itemID, link, id, slotID) - self.profile.artifacts[itemID].containerID = id - self.profile.artifacts[itemID].slotID = slotID end end @@ -501,9 +588,14 @@ self.queuedScan = true return end + if not self.profile.knowledgeMultiplier then + print('need to get knowledge level') + return + end + self.queuedScan = nil - print('|cFFFF0088ScanAllBags()|r') + print('|cFFFF0088ScanAllBags()|r', self.profile.knowledgeMultiplier) for _, button in ipairs(self.Tokens) do button.numItems = 0 @@ -635,8 +727,10 @@ self.CurrentProgress.animateFrom = self.CurrentProgress:GetHeight() or 1 self.CurrentProgress.animateTo = currentProgress * self:GetHeight() self.CurrentProgress:Show() + self.ProgressLine:Show() else self.CurrentProgress:Hide() + self.ProgressLine:Hide() end if self.potentialXP > self.currentXP then @@ -653,9 +747,11 @@ self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1 self.AdjustedProgress.animateTo = projectedProgress * self:GetHeight() + self.AdjustedLine:Show() self.AdjustedProgress:Show() else self.AdjustedProgress:Hide() + self.AdjustedLine:Hide() end diff -r 6bf83e41b08c -r f32b63c93275 Modules/ArtifactPower.xml --- a/Modules/ArtifactPower.xml Fri Jan 20 19:58:37 2017 -0500 +++ b/Modules/ArtifactPower.xml Sat Jan 21 20:12:17 2017 -0500 @@ -82,7 +82,7 @@ - + @@ -94,6 +94,7 @@ +