Mercurial > wow > buffalo2
diff Modules/ArtifactPower.lua @ 108:a41f6b74709a
- Handler number and boolean cluster arguments as positioning priority layer and "always top" respectively
- Use SetShown and IsShown instead of IsVisible in doing full re-anchor checks
author | Nick@Zahhak |
---|---|
date | Sat, 25 Feb 2017 11:42:07 -0500 |
parents | 8df154a2bfd6 |
children | 1196c2bad31c |
line wrap: on
line diff
--- a/Modules/ArtifactPower.lua Sun Jan 29 09:57:09 2017 -0500 +++ b/Modules/ArtifactPower.lua Sat Feb 25 11:42:07 2017 -0500 @@ -50,7 +50,8 @@ self:RegisterEvent('PLAYER_REGEN_ENABLED') self:RegisterEvent('PLAYER_REGEN_DISABLED') self:RegisterEvent('PLAYER_ENTERING_WORLD') - Veneer:AddHandler(self, self.anchorPoint, true) + self:RegisterEvent('ITEM_LOCK_CHANGED') -- use to clear bag slot cache data + Veneer:AddHandler(self, self.anchorPoint, 2) SLASH_VENEER_AP1 = "/vap" SLASH_VENEER_AP2 = "/veneerap" SlashCmdList.VENEER_AP = function(arg) @@ -62,7 +63,13 @@ end self:Print('Show Underlight Angler:', (VeneerData.ArtifactPower.EnableFishing and 'ON' or 'OFF')) self:Update() - + elseif arg == 'reset' then + if self.db then + table.wipe(self.db.cache) + table.wipe(self.db.fishingCache) + end + self:Print('Cache data reset.') + self:Update() else self:Show() end @@ -73,6 +80,15 @@ end +local ShortNumberString = function (value) + if value >= 100000 then + return tostring(floor(value/1000)) .. 'k' + elseif value >= 1000 then + return tostring(floor(value/100)/10) .. 'k' + else + return value + end +end local IsBagnonOpen = function() @@ -150,11 +166,16 @@ end - self.cache = self.db.cache self.profile = self.db[guid] + self.profile.cache = self.profile.cache or {} + self.profile.cache.bagItems = self.profile.cache.bagItems or {} + self.profile.cache.bags = self.profile.cache.bags or {} + self.profile.cache.fishing = self.profile.cache.fishing or {} + self.profile.cache.items = self.profile.cache.items or {} self.profile.bagslots = self.profile.bagslots or {} self.profile.artifacts = self.profile.artifacts or {} self.updateSummary = true + self.cache = self.profile.cache VeneerArtifactPowerTimer:SetScript('OnUpdate', function() self:OnUpdate() @@ -282,7 +303,19 @@ self:TryToShow() elseif event == 'BAG_UPDATE' then local containerID = ... + + self:QueueBag(containerID) + elseif event == 'ITEM_LOCK_CHANGED' then + + local containerID, slotID = ... + + if self.cache.bags[containerID] and self.cache.bags[containerID][slotID] then + self.cache.bags[containerID][slotID] = nil + self.cache.fishing[containerID][slotID] = nil + end + + elseif event == 'PLAYER_BANKSLOTS_CHANGED' then self:ScanAllBags() elseif event == 'BAG_UPDATE_DELAYED' then @@ -359,23 +392,29 @@ end end end - if self.fishingAP and self.fishingAP >= 1 then + if self.fishingAP and self.fishingAP > 0 then bankText = (bankText and (bankText .. ' ') or '') .. '|cFF0088FF' .. tostring(self.fishingAP) .. ' fishing AP|r' end self.SummaryHeader:SetText(bankText) local numButtons = 0 - local contentsHeight = 64 + local contentsHeight = 16 + self.SummaryHeader:GetHeight() + 64 + local contentsWidth = 64 if self.profile.knowledgeMultiplier then numButtons = self:UpdateArtifactButtons() - contentsHeight = contentsHeight + self:UpdateItemButtons() + + contentsWidth = 64*numButtons + 4 * (numButtons+1) + + local itemsWidth, itemsHeight = self:UpdateItemButtons() + contentsHeight = contentsHeight + itemsHeight + contentsWidth = max(contentsWidth, itemsWidth) end - self:SetWidth(64*numButtons + 4 * (numButtons+1)) - self:SetHeight(16 + self.SummaryHeader:GetHeight() + contentsHeight) + self:SetWidth(contentsWidth) + self:SetHeight(contentsHeight) self:Reanchor() end @@ -395,15 +434,17 @@ end else - numButtons = numButtons + 1 - button = self.Artifact[numButtons] - button.relativeFrame = lastFrame - lastFrame = button:SetButton(itemID, artifact, numButtons, (self.equippedID == itemID)) + if artifact.level ~= 54 then + numButtons = numButtons + 1 + button = self.Artifact[numButtons] + button.relativeFrame = lastFrame + lastFrame = button:SetButton(itemID, artifact, numButtons, (self.equippedID == itemID)) + end end end - if fishingData then + if fishingData and (self.fishingAP and self.fishingAP > 0) then numButtons = numButtons + 1 local button = self.Artifact[numButtons] button.relativeFrame = lastFrame @@ -424,7 +465,7 @@ local lastFrame, upFrame local numButtons = 0 local buttonsHeight = 0 - local buttonWidth = 0 + local buttonsWidth = 0 for index, button in ipairs(self.Tokens) do if button.numItems >= 1 then if button.itemName then @@ -438,12 +479,19 @@ 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 + buttonsWidth = 50 else - button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0) + local col = mod(numButtons,8) + if col == 1 then + button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2) + upFrame = button + buttonsHeight = buttonsHeight + 52 + + else + button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0) + + end + buttonsWidth = max(buttonsWidth, col * 50) end button.Count:SetText(button.numItems) lastFrame = button @@ -455,7 +503,7 @@ - return buttonsHeight + return buttonsWidth, buttonsHeight end function ap:SetItemAction(button, name) @@ -490,7 +538,7 @@ self.numItems = self.numItems + 1 end - local itemAPtext = itemAP * self.profile.knowledgeMultiplier + local itemAPtext = itemAP if itemAPtext >= 100000 then itemAPtext = floor(itemAPtext/1000) .. 'k' elseif itemAPtext >= 1000 then @@ -503,7 +551,7 @@ end function ap:GetItemAP(itemID, itemLink, bagData) - if not self.cache[itemID] then + if not self.cache.items[itemID] then print('doing tooltip scan') self.tooltip:SetOwner(self, 'ANCHOR_NONE') @@ -520,8 +568,8 @@ print(itemLink, '-', tonumber(text)) local itemAP = tonumber(text) if itemAP then - itemAP = itemAP / self.profile.knowledgeMultiplier - self.cache[itemID] = itemAP + itemAP = itemAP + self.cache.items[itemID] = itemAP end end end @@ -531,16 +579,16 @@ local fishingAP = fishingText:match("%d+") fishingAP = tonumber(fishingAP) if fishingAP then - self.cache[itemID] = fishingAP - self.fishingCache[itemID] = true + self.cache.items[itemID] = fishingAP + self.cache.fishing[itemID] = true end end else - self.cache[itemID] = 0 + self.cache.items[itemID] = 0 end end - return self.cache[itemID], self.fishingCache[itemID] + return self.cache.items[itemID], self.cache.fishing[itemID] end function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent) @@ -551,6 +599,11 @@ local artifacts = self.profile.artifacts local multi = C_ArtifactUI.GetArtifactKnowledgeMultiplier() + if multi and (self.profile.knowledgeMultiplier ~= multi) then + table.wipe(self.cache.items) + table.wipe(self.cache.fishing) + end + self.profile.knowledgeMultiplier = multi or self.profile.knowledgeMultiplier print('multiplier:', multi) @@ -567,7 +620,7 @@ artifact.currentXP = currentXP artifact.level = pointsSpent local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent) - artifact.cost = cost + artifact.currentCost = cost local pointsAvailable = pointsSpent local actualCost = cost @@ -603,6 +656,10 @@ bagData.items = bagData.items or {} table.wipe(bagData.items) + self.cache.bagItems[id] = self.cache.bagItems[id] or {} + self.cache.bags[id] = self.cache.bags[id] or {} + self.cache.fishing[id] = self.cache.fishing[id] or {} + for slotID = 1, numSlots do local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID) if link then @@ -611,7 +668,18 @@ if class == 'Consumable' and subclass == 'Other' then --print(GetItemInfo(link)) - local itemAP, isFishingAP = self:GetItemAP(itemID, link) + local itemAP, isFishingAP + if self.cache.bags[id][slotID] and (self.cache.bagItems[id][slotID] == itemID) then + print('slot cache data', id, slotID) + itemAP = self.cache.bags[id][slotID] + else + itemAP, isFishingAP = self:GetItemAP(itemID, link) + self.cache.bagItems[id][slotID] = itemID + self.cache.bags[id][slotID] = itemAP + self.cache.fishing[id][slotID] = isFishingAP + end + + --print(itemAP, isFishingAP) if itemAP and (itemAP > 0) then local itemButton = self:GetItemButton(itemID, texture, itemAP) @@ -620,7 +688,7 @@ bagData.fishingItems = (bagData.fishingItems or 0) + 1 bagData.fishingAP = (bagData.fishingAP or 0) + itemAP else - itemAP = itemAP * self.profile.knowledgeMultiplier + itemAP = itemAP bagData.numItems = (bagData.numItems or 0) + 1 bagData.totalAP = (bagData.totalAP or 0) + itemAP end @@ -701,6 +769,10 @@ print(itemID, index) print(artifact.name, artifact.texture, artifact.currentXP) self:SetID(itemID) + if not artifact.currentCost then + artifact.currentCost = artifact.cost + end + for k,v in pairs(artifact) do --print('::',k,v) self[k] = v @@ -724,7 +796,10 @@ self.potentialLevel = potentialPoints self.potentialAdjustedXP = potentialXP - + self.maxCost = self.currentCost + for i = self.level + 1, #POINT_COSTS do + self.maxCost = self.maxCost + POINT_COSTS[i] + end if index ~= 1 then self:ClearAllPoints() @@ -741,12 +816,11 @@ end function VeneerArtifactButtonMixin:Update() - local r, g, b = 1, 1, 1 local lR, lG, lB = 1, 1, 0 local levelText = self.level local xpValue = self.currentXP - local costValue = self.cost + local costValue = self.currentCost if self.actualLevel ~= self.level then levelText, r,g,b = self.actualLevel, 0,1,0 xpValue, costValue, lR, lG, lB = self.actualXP, self.actualCost, 0, 1, 0 @@ -756,21 +830,9 @@ end - if xpValue >= 100000 then - xpValue = tostring(floor(xpValue/1000))..'k' - elseif xpValue > 1000 then - xpValue = tostring(floor(xpValue/100)/10)..'k' - end - if costValue >= 100000 then - costValue = tostring(floor(costValue/1000))..'k' - elseif costValue >= 1000 then - costValue = tostring(floor(costValue/100)/10)..'k' - end - - self.Level:SetText(levelText) self.Level:SetTextColor(r, g, b) - self.CurrentXP:SetText(xpValue) + self.CurrentXP:SetText(ShortNumberString( xpValue)) self.CurrentXP:SetTextColor(lR, lG, lB) if self.isEquipped then @@ -781,9 +843,8 @@ self:SetNormalTexture(nil, 'ADD') end - local currentProgress = (self.currentXP < self.cost) and (self.currentXP / self.cost) or 1 + local currentProgress = (self.currentXP < self.currentCost) and (self.currentXP / self.currentCost) or 1 if self.level <= 53 then - self.CurrentProgress.animateFrom = self.CurrentProgress:GetHeight() or 1 self.CurrentProgress.animateTo = currentProgress * self:GetHeight() self.CurrentProgress:Show() @@ -795,26 +856,21 @@ if self.potentialXP > self.currentXP then local projectedProgress = (self.potentialAdjustedXP < self.potentialCost) and (self.potentialXP / self.potentialCost) or 1 - if (projectedProgress > currentProgress) then self.AdjustedProgress:SetPoint('BOTTOM', self.CurrentProgress, 'TOP') projectedProgress = projectedProgress - currentProgress - else self.AdjustedProgress:SetPoint('BOTTOM', self, 'BOTTOM') end print('show potential', currentProgress, projectedProgress) 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 - - self.Icon:SetTexture(self.texture) self:SetSize(64,64) end @@ -848,21 +904,23 @@ if self.AdjustedProgress.animateTo then self:AnimateProgress(self.AdjustedProgress) end - end function VeneerArtifactButtonMixin:OnEnter() GameTooltip:SetOwner(self, 'ANCHOR_CURSOR') GameTooltip:SetText(self.name) - GameTooltip:AddLine(tostring(self.currentXP) .. ' / '..tostring(self.cost), 1, 1, 0) + GameTooltip:AddLine(ShortNumberString(self.currentXP) .. ' / '..ShortNumberString(self.currentCost), 1, 1, 0) if self.potentialXP > self.currentXP then - GameTooltip:AddLine(tostring(self.potentialXP) .. ' potential XP', 0, 1, 1) + GameTooltip:AddLine(ShortNumberString(self.potentialXP) .. ' potential XP', 0, 1, 1) if self.potentialAdjustedXP ~= self.potentialXP then - GameTooltip:AddLine(tostring(self.potentialAdjustedXP) .. ' / ' .. tostring(self.potentialCost).. ' after', 0, 1, 0) + GameTooltip:AddLine(ShortNumberString(self.potentialAdjustedXP) .. ' / ' .. ShortNumberString(self.potentialCost).. ' after', 0, 1, 0) end end if self.actualLevel ~= self.level then - GameTooltip:AddLine(tostring(self.actualLevel - self.level) .. ' points unlocked', 0, 1, 1) + GameTooltip:AddLine(ShortNumberString(self.actualLevel - self.level) .. ' points unlocked', 0, 1, 1) + end + if self.currentXP < self.currentCost then + GameTooltip:AddLine(ShortNumberString(self.currentCost - self.currentXP) .. ' needed') end GameTooltip:Show() @@ -872,11 +930,21 @@ GameTooltip:Hide() end end +function VeneerArtifactButtonMixin:OnHide() + + if GameTooltip:IsOwned(self) then + GameTooltip:Hide() + end +end function VeneerArtifactButtonMixin:OnClick(button, down) if self.isEquipped then SocketInventoryItem(16) else + if IsShiftKeyDown() then SocketContainerItem(self.containerID, self.slotID) + else + + end end end \ No newline at end of file