annotate Modules/ArtifactPower.lua @ 99:74d6d97a2d24 v7.1.5-r100

- artifact progress visualizations, green for current, blue for attainable - force fishing artifact to list last - support for fishing artifact power
author Nenue
date Fri, 20 Jan 2017 19:40:55 -0500
parents dadddb8a551f
children f32b63c93275
rev   line source
Nenue@97 1 -- Veneer
Nenue@97 2 -- ArtifactPower.lua
Nenue@97 3 -- Created: 1/15/2017 11:44 PM
Nenue@97 4 -- %file-revision%
Nenue@97 5 --
Nenue@97 6
Nenue@97 7 local print = DEVIAN_WORKSPACE and function(...) print('VnAP', ...) end or nop
Nenue@97 8 VeneerArtifactPowerMixin = {
Nenue@99 9 numItems = 0,
Nenue@99 10 Tokens = {},
Nenue@99 11 ItemButtons = {},
Nenue@97 12 anchorPoint = 'TOP',
Nenue@97 13 anchorFrom = 'TOP',
Nenue@97 14 }
Nenue@97 15 local ap = VeneerArtifactPowerMixin
Nenue@97 16 local BAGS_TO_SCAN = {BACKPACK_CONTAINER }
Nenue@97 17 local TOOLTIP_NAME = 'VeneerAPScanner'
Nenue@98 18 local POINT_COSTS = {
Nenue@98 19 100, 300, 325, 350, 375,
Nenue@98 20 400, 425, 450, 525, 625,
Nenue@98 21 750, 875, 1000, 6840, 8830,
Nenue@98 22 11280, 14400, 18620, 24000, 30600,
Nenue@98 23 39520, 50880, 64800, 82500, 105280,
Nenue@98 24 138650, 182780, 240870, 325520, 417560,
Nenue@98 25 546000, 718200, 946660, 1245840, 1635200,
Nenue@98 26 191500, 2010000, 2110000, 2215000, 2325000,
Nenue@98 27 2440000, 2560000, 2690000, 2825000, 2965000,
Nenue@98 28 3115000, 3270000, 3435000, 3605000, 3785000,
Nenue@98 29 3975000, 4175000, 4385000, 4605000
Nenue@98 30 }
Nenue@97 31
Nenue@99 32 local FRAME_LIST = {'ContainerFrame1', 'BankFrame'}
Nenue@99 33 local BAG_FRAMES = {'ContainerFrame1'}
Nenue@99 34 local BANK_FRAMES = {'BankFrame'}
Nenue@99 35
Nenue@97 36 function ap:OnLoad()
Nenue@97 37 self:RegisterEvent('BAG_UPDATE') -- use to obtain bag IDs to scan
Nenue@97 38 self:RegisterEvent('BAG_UPDATE_DELAYED') -- use to trigger actual scan activity
Nenue@97 39 self:RegisterEvent('BANKFRAME_OPENED') -- determine when bank info is available
Nenue@97 40 self:RegisterEvent('BANKFRAME_CLOSED') -- " " "
Nenue@97 41 self:RegisterEvent('ARTIFACT_UPDATE') -- when artifact data has changed
Nenue@98 42 self:RegisterEvent('ARTIFACT_XP_UPDATE') -- when artifact xp has changed (but not necessarily data)
Nenue@97 43 self:RegisterEvent('PLAYER_REGEN_ENABLED')
Nenue@97 44 self:RegisterEvent('PLAYER_REGEN_DISABLED')
Nenue@99 45 self:RegisterEvent('PLAYER_ENTERING_WORLD')
Nenue@97 46 Veneer:AddHandler(self, self.anchorPoint, true)
Nenue@97 47 SLASH_VENEER_AP1 = "/vap"
Nenue@97 48 SLASH_VENEER_AP2 = "/veneerap"
Nenue@98 49 SlashCmdList.VENEER_AP = function(arg)
Nenue@98 50 if arg == 'fishing' then
Nenue@98 51 if VeneerData.ArtifactPower.EnableFishing then
Nenue@98 52 VeneerData.ArtifactPower.EnableFishing = nil
Nenue@98 53 else
Nenue@98 54 VeneerData.ArtifactPower.EnableFishing = true
Nenue@98 55 end
Nenue@98 56 self:Print('Show Underlight Angler:', (VeneerData.ArtifactPower.EnableFishing and 'ON' or 'OFF'))
Nenue@98 57 self:Update()
Nenue@98 58
Nenue@98 59 else
Nenue@98 60 self:Show()
Nenue@98 61 end
Nenue@97 62 end
Nenue@97 63
Nenue@97 64 self.tooltip = CreateFrame('GameTooltip', TOOLTIP_NAME, self, 'GameTooltipTemplate')
Nenue@99 65 tinsert(UISpecialFrames, self:GetName())
Nenue@99 66
Nenue@97 67
Nenue@97 68 end
Nenue@97 69
Nenue@99 70 local addonCompatibility = {
Nenue@99 71 ['Bagnon'] = {
Nenue@99 72 BagFrames = {'BagnonFrameinventory'},
Nenue@99 73 BankFrames = {'BagnonFramebank'},
Nenue@99 74 PostHooks = {'ToggleAllBags', 'ToggleBackpack' },
Nenue@99 75 MethodClass = 'Bagnon',
Nenue@99 76 MethodHooks = {'BANK_OPENED', 'BANKFRAME_CLOSED'}
Nenue@99 77 }
Nenue@97 78 }
Nenue@97 79
Nenue@99 80
Nenue@97 81 function ap:Setup()
Nenue@97 82 print(self:GetName()..':Setup()')
Nenue@97 83 local guid = UnitGUID('player')
Nenue@97 84 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings
Nenue@97 85 VeneerData.ArtifactPower[guid] = VeneerData.ArtifactPower[guid] or {}
Nenue@97 86 self.profile = VeneerData.ArtifactPower[guid]
Nenue@97 87 self.profile.bagslots = self.profile.bagslots or {}
Nenue@97 88 self.profile.artifacts = self.profile.artifacts or {}
Nenue@97 89 self.updateSummary = true
Nenue@97 90
Nenue@99 91 local DoTryToShow = function()
Nenue@99 92 self:TryToShow()
Nenue@99 93 end
Nenue@99 94 hooksecurefunc("OpenBackpack", DoTryToShow)
Nenue@99 95 hooksecurefunc("CloseBackpack", DoTryToShow)
Nenue@99 96
Nenue@97 97 -- Bagnon compatibility
Nenue@97 98 -- todo: ArkInventory, Elv, etc
Nenue@99 99 for addon, args in pairs(addonCompatibility) do
Nenue@99 100 if IsAddOnLoaded(addon) then
Nenue@99 101 for _, name in ipairs(args.BagFrames) do
Nenue@99 102 tinsert(FRAME_LIST, name)
Nenue@99 103 tinsert(BAG_FRAMES, name)
Nenue@99 104 end
Nenue@99 105 for _, name in ipairs(args.BankFrames) do
Nenue@99 106 tinsert(FRAME_LIST, name)
Nenue@99 107 tinsert(BAG_FRAMES, name)
Nenue@99 108 end
Nenue@99 109 for _, name in ipairs(args.PostHooks) do
Nenue@99 110 local oFunc = _G[name]
Nenue@99 111 _G[name] = function(...)
Nenue@99 112 print('|cFFFF0088' .. name .. '|r', ...)
Nenue@99 113 oFunc(...)
Nenue@99 114 self:TryToShow()
Nenue@99 115 end
Nenue@99 116 end
Nenue@99 117 local frame = _G[args.MethodClass]
Nenue@99 118 if frame then
Nenue@99 119 for _, name in ipairs(args.MethodHooks) do
Nenue@99 120 hooksecurefunc(frame, name, DoTryToShow)
Nenue@99 121 end
Nenue@97 122 end
Nenue@97 123 end
Nenue@97 124 end
Nenue@99 125 end
Nenue@97 126
Nenue@97 127 local UNDERLIGHT_ANGLER_ID = 133755
Nenue@98 128 function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@98 129 print('|cFF00FF00SetArtifact()|r')
Nenue@97 130 if not self.profile then
Nenue@97 131 return
Nenue@97 132 end
Nenue@97 133 local artifacts = self.profile.artifacts
Nenue@97 134
Nenue@97 135
Nenue@97 136 if itemID then
Nenue@99 137
Nenue@99 138 self.currentEquipped = itemID
Nenue@99 139
Nenue@98 140 artifacts[itemID] = artifacts[itemID] or {}
Nenue@98 141 table.wipe(artifacts[itemID])
Nenue@98 142 local artifact = artifacts[itemID]
Nenue@97 143
Nenue@98 144 artifact.name = name
Nenue@98 145 artifact.texture = texture
Nenue@98 146 artifact.currentXP = currentXP
Nenue@98 147 artifact.level = pointsSpent
Nenue@98 148 local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent)
Nenue@98 149 artifact.cost = cost
Nenue@97 150
Nenue@98 151 local pointsAvailable = pointsSpent
Nenue@98 152 local actualCost = cost
Nenue@98 153 local actualXP = currentXP
Nenue@98 154 while actualXP >= actualCost do
Nenue@98 155 pointsAvailable = pointsAvailable + 1
Nenue@98 156 actualXP = actualXP - actualCost
Nenue@98 157 print(pointsAvailable, '-', actualCost, '=', actualXP)
Nenue@98 158 actualCost = C_ArtifactUI.GetCostForPointAtRank(pointsAvailable)
Nenue@98 159 end
Nenue@98 160 print('updating', itemID, name, currentXP, pointsSpent, pointsAvailable, actualXP)
Nenue@98 161 artifact.actualXP = actualXP
Nenue@98 162 artifact.actualLevel = pointsAvailable
Nenue@98 163 artifact.actualCost = actualCost
Nenue@97 164
Nenue@97 165 end
Nenue@97 166 end
Nenue@97 167 function ap:QueueBag(containerID)
Nenue@97 168 containerID = tonumber(containerID)
Nenue@97 169 if not containerID then
Nenue@97 170 return
Nenue@97 171 end
Nenue@97 172
Nenue@97 173 if not tContains(BAGS_TO_SCAN, containerID) then
Nenue@97 174 print(' queueing', containerID, type(containerID), #BAGS_TO_SCAN , 'in line')
Nenue@97 175 BAGS_TO_SCAN[#BAGS_TO_SCAN + 1] = containerID
Nenue@97 176 end
Nenue@97 177 end
Nenue@97 178
Nenue@99 179 function ap:Reanchor()
Nenue@99 180 if Veneer then
Nenue@99 181 Veneer:DynamicReanchor()
Nenue@99 182 end
Nenue@99 183 end
Nenue@99 184
Nenue@97 185 function ap:OnShow()
Nenue@99 186 print('|cFFFFFF00OnShow()|r')
Nenue@97 187 self.enabled = true
Nenue@99 188 self:ScanAllBags()
Nenue@99 189 self:Reanchor()
Nenue@99 190 if not self.postShowSetup then
Nenue@99 191 self.postShowSetup = true
Nenue@99 192 hooksecurefunc("HideUIPanel", function() self:TryToShow() end)
Nenue@99 193 end
Nenue@97 194 end
Nenue@97 195 function ap:OnHide()
Nenue@99 196 print('|cFF88FF00OnHide()|r')
Nenue@99 197 self:Reanchor()
Nenue@97 198 end
Nenue@97 199 function ap:OnEnter()
Nenue@97 200
Nenue@97 201 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
Nenue@97 202
Nenue@99 203
Nenue@97 204 GameTooltip:AddLine(self.bagAP)
Nenue@97 205 GameTooltip:AddLine(self.bankAP)
Nenue@97 206
Nenue@97 207 end
Nenue@97 208
Nenue@99 209 function ap:TryToShow()
Nenue@99 210
Nenue@99 211 print('|cFFFFFF00TryToShow()')
Nenue@99 212
Nenue@99 213 if not InCombatLockdown() then
Nenue@99 214 for _, name in ipairs(FRAME_LIST) do
Nenue@99 215 --print(name, (_G[name] and _G[name]:IsShown()))
Nenue@99 216 if _G[name] and _G[name]:IsShown() then
Nenue@99 217 if self:IsShown() then
Nenue@99 218 self:Update()
Nenue@99 219 else
Nenue@99 220 self:Show()
Nenue@99 221 end
Nenue@99 222 return
Nenue@99 223 end
Nenue@99 224 end
Nenue@99 225 end
Nenue@99 226
Nenue@99 227
Nenue@99 228 self:Hide()
Nenue@99 229 end
Nenue@99 230
Nenue@99 231
Nenue@97 232 function ap:OnEvent(event, ...)
Nenue@99 233 print('|cFF00FF88OnEvent()', event, ...)
Nenue@99 234 if event == 'PLAYER_ENTERING_WORLD' then
Nenue@99 235 self:TryToShow()
Nenue@99 236 elseif event == 'BAG_UPDATE' then
Nenue@97 237 local containerID = ...
Nenue@97 238 self:QueueBag(containerID)
Nenue@97 239 elseif event == 'PLAYER_BANKSLOTS_CHANGED' then
Nenue@99 240 self:ScanAllBags()
Nenue@97 241 elseif event == 'BAG_UPDATE_DELAYED' then
Nenue@99 242 if not self.firstHit then
Nenue@99 243 self.firstHit = true
Nenue@99 244 else
Nenue@99 245 self:ScanAllBags()
Nenue@99 246 end
Nenue@97 247 elseif event == 'BANKFRAME_OPENED' then
Nenue@97 248 self.bankAccess = true
Nenue@99 249 self:ScanAllBags()
Nenue@97 250 elseif event == 'BANKFRAME_CLOSED' then
Nenue@99 251 self.bankAccess = nil
Nenue@97 252 elseif event == 'ARTIFACT_UPDATE' then
Nenue@98 253 local newItem = ...
Nenue@98 254 if newItem then
Nenue@98 255 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetArtifactInfo()
Nenue@98 256 self:SetArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@98 257 self:ScanAllBags(self.bankAccess)
Nenue@98 258 end
Nenue@98 259 elseif event == 'ARTIFACT_XP_UPDATE' then
Nenue@98 260 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetEquippedArtifactInfo()
Nenue@98 261 self:SetArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@98 262 self:ScanAllBags(self.bankAccess)
Nenue@97 263 elseif event == 'PLAYER_REGEN_ENABLED' then
Nenue@97 264 if self.enabled then
Nenue@99 265 if self.queuedScan then
Nenue@99 266 self:ScanAllBags(self.backAccess)
Nenue@99 267 else
Nenue@99 268 self:TryToShow()
Nenue@99 269 end
Nenue@97 270 end
Nenue@97 271
Nenue@97 272 elseif event == 'PLAYER_REGEN_DISABLED' then
Nenue@97 273 self:Hide()
Nenue@97 274 end
Nenue@97 275 end
Nenue@97 276
Nenue@97 277 function ap:OnMouseDown()
Nenue@97 278 self.enabled = nil
Nenue@97 279 self:Hide()
Nenue@97 280 end
Nenue@97 281
Nenue@97 282 function ap:Update()
Nenue@97 283 if not self:IsShown() then
Nenue@99 284 print('|cFFFF4400Update()|r')
Nenue@97 285 return
Nenue@97 286 end
Nenue@97 287 print('|cFF00FFFFUpdate()|r')
Nenue@97 288
Nenue@97 289 local bankText, bagText
Nenue@97 290 if not (self.bankAP and self.bagAP) then
Nenue@97 291 bankText = '|cFFFF0000Open bank frame to count all AP|r '
Nenue@97 292 else
Nenue@98 293 if (self.bagAP + self.bankAP) == 0 then
Nenue@99 294 bankText = '|cFFFF4400No Artifact Power tokens on hand|r'
Nenue@98 295 else
Nenue@98 296 if self.bagAP and (self.bagAP > 0) then
Nenue@98 297 bankText = '|cFFFFFFFF' .. tostring(self.bagAP) .. '|r'
Nenue@98 298 end
Nenue@98 299 if self.bankAP and (self.bankAP > 0) then
Nenue@98 300 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFFFFFF00'..tostring(self.bankAP)..'|r'
Nenue@98 301 end
Nenue@98 302 end
Nenue@97 303 end
Nenue@99 304 if self.fishingAP and self.fishingAP >= 1 then
Nenue@99 305 bankText = (bankText and (bankText .. ' ') or '') .. '|cFF0088FF' .. tostring(self.fishingAP) .. ' fishing AP|r'
Nenue@99 306 end
Nenue@99 307
Nenue@97 308 self.SummaryHeader:SetText(bankText)
Nenue@97 309
Nenue@97 310 -- Artifact icons, in no particular order
Nenue@99 311 self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo()
Nenue@97 312 local numButtons = 0
Nenue@99 313 local lastFrame = self
Nenue@99 314 local fishingID, fishingData
Nenue@98 315 local index, button
Nenue@97 316 for itemID, artifact in pairs(self.profile.artifacts) do
Nenue@99 317 if (itemID == UNDERLIGHT_ANGLER_ID) then
Nenue@98 318 if VeneerData.ArtifactPower.EnableFishing then
Nenue@98 319 fishingID = itemID
Nenue@98 320 fishingData = artifact
Nenue@98 321 end
Nenue@97 322
Nenue@98 323 else
Nenue@98 324 numButtons = numButtons + 1
Nenue@98 325 button = self.Artifact[numButtons]
Nenue@99 326 button.relativeFrame = lastFrame
Nenue@99 327 lastFrame = button:SetButton(itemID, artifact, numButtons, (self.equippedID == itemID))
Nenue@97 328 end
Nenue@97 329
Nenue@98 330 end
Nenue@97 331
Nenue@98 332 if fishingData then
Nenue@98 333 numButtons = numButtons + 1
Nenue@99 334 local button = self.Artifact[numButtons]
Nenue@99 335 button.relativeFrame = lastFrame
Nenue@99 336 button:SetButton(fishingID, fishingData, numButtons, self.equippedID == fishingID)
Nenue@98 337 end
Nenue@97 338
Nenue@99 339 for i = numButtons+ 1, #self.Artifact do
Nenue@97 340 print('hide', i)
Nenue@97 341 self.Artifact[i]:Hide()
Nenue@97 342 end
Nenue@97 343
Nenue@99 344 self:UpdateItemButtons()
Nenue@97 345
Nenue@97 346
Nenue@98 347 self:SetWidth(64*numButtons + 4 * (numButtons+1))
Nenue@98 348 self:SetHeight(12 + self.SummaryHeader:GetHeight() + 64)
Nenue@97 349 self:Reanchor()
Nenue@97 350
Nenue@97 351 end
Nenue@97 352
Nenue@99 353
Nenue@99 354 function ap:UpdateItemButtons()
Nenue@99 355 print('|cFF00FFFFUpdateItemButtons()|r')
Nenue@99 356 local lastFrame, upFrame
Nenue@99 357 local numButtons = 0
Nenue@99 358 for index, button in ipairs(self.Tokens) do
Nenue@99 359 if button.numItems >= 1 then
Nenue@99 360 if button.itemName then
Nenue@99 361 self:SetItemAction(button)
Nenue@99 362 end
Nenue@99 363
Nenue@99 364 button:ClearAllPoints()
Nenue@99 365 numButtons = numButtons + 1
Nenue@99 366 print(index, button:GetID(), button.Icon:GetTexture())
Nenue@99 367 if numButtons == 1 then
Nenue@99 368 button:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -2)
Nenue@99 369 upFrame = button
Nenue@99 370 elseif mod(numButtons,8) == 1 then
Nenue@99 371 button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2)
Nenue@99 372 upFrame = button
Nenue@99 373 else
Nenue@99 374 button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0)
Nenue@99 375 end
Nenue@99 376 button.Count:SetText(button.numItems)
Nenue@99 377 lastFrame = button
Nenue@99 378 button:Show()
Nenue@99 379 else
Nenue@99 380
Nenue@99 381 button:Hide()
Nenue@99 382 end
Nenue@99 383
Nenue@99 384 end
Nenue@99 385
Nenue@99 386 end
Nenue@99 387
Nenue@99 388 function ap:SetItemAction(button, name)
Nenue@99 389 name = name or self.itemName
Nenue@99 390 if InCombatLockdown() then
Nenue@99 391 self.itemName = name
Nenue@99 392 return
Nenue@99 393 else
Nenue@99 394 button:SetAttribute('*type*','item')
Nenue@99 395 button:SetAttribute('*item*', name)
Nenue@99 396 end
Nenue@99 397 end
Nenue@99 398
Nenue@99 399 function ap:GetItemButton(itemID, texture, itemAP)
Nenue@99 400 print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP)
Nenue@99 401 local button = self.ItemButtons[itemID]
Nenue@99 402 if not button then
Nenue@99 403 button = CreateFrame('Button', 'VeneerAPToken'..itemID, self, 'VeneerItemButton')
Nenue@99 404 button:SetPushedTexture([[Interface\Buttons\UI-Quickslot-Depress]])
Nenue@99 405 button:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]],"ADD")
Nenue@99 406 button:SetID(itemID)
Nenue@99 407 button.numItems = 0
Nenue@99 408 button.Icon:SetTexture(texture)
Nenue@99 409 button.Label:SetText(itemAP)
Nenue@99 410 button:RegisterForClicks("AnyUp")
Nenue@99 411 self:SetItemAction(button, GetItemInfo(itemID))
Nenue@99 412
Nenue@99 413 print(' created')
Nenue@99 414 self.ItemButtons[itemID] = button
Nenue@99 415 self.numItems = self.numItems + 1
Nenue@99 416 end
Nenue@99 417
Nenue@99 418 button.numItems = button.numItems + 1
Nenue@99 419 return button
Nenue@99 420 end
Nenue@99 421
Nenue@97 422 function ap:ScanBag(id)
Nenue@97 423 print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id))
Nenue@97 424 local numSlots = GetContainerNumSlots(id)
Nenue@97 425 local requiresUpdate
Nenue@97 426 if numSlots == 0 then
Nenue@97 427 return nil
Nenue@97 428 end
Nenue@97 429
Nenue@97 430
Nenue@97 431 self.profile.bagslots[id] = self.profile.bagslots[id] or {}
Nenue@97 432 table.wipe(self.profile.bagslots[id])
Nenue@97 433 local bagData = self.profile.bagslots[id]
Nenue@97 434 bagData.totalAP = 0
Nenue@99 435 bagData.fishingAP = 0
Nenue@99 436 bagData.items = bagData.items or {}
Nenue@99 437 table.wipe(bagData.items)
Nenue@99 438
Nenue@97 439 for slotID = 1, numSlots do
Nenue@97 440 local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID)
Nenue@97 441 local itemID = GetContainerItemID(id, slotID)
Nenue@97 442
Nenue@97 443 if link then
Nenue@97 444 self.tooltip:SetOwner(self, 'ANCHOR_NONE')
Nenue@97 445 self.tooltip:SetHyperlink(link)
Nenue@97 446 self.tooltip:Show()
Nenue@97 447 local numLines = self.tooltip:NumLines()
Nenue@97 448 if numLines >= 3 then
Nenue@97 449 local subText = _G[TOOLTIP_NAME .. 'TextLeft2']:GetText()
Nenue@97 450 if subText and subText:match(ARTIFACT_POWER) then
Nenue@97 451 for i = 3, numLines do
Nenue@97 452 local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText()
Nenue@97 453 if text and text:match(ARTIFACT_POWER) then
Nenue@97 454 text = text:gsub('[,%D]', '')
Nenue@97 455 print(link, '-', tonumber(text))
Nenue@97 456 local itemAP = tonumber(text)
Nenue@97 457 if itemAP then
Nenue@98 458 requiresUpdate = true
Nenue@97 459 bagData.numItems = (bagData.numItems or 0) + 1
Nenue@97 460 bagData.totalAP = (bagData.totalAP or 0) + itemAP
Nenue@99 461 bagData.items[itemID] = (bagData.items[itemID] or 0) + 1
Nenue@99 462
Nenue@99 463
Nenue@99 464 local itemButton = self:GetItemButton(itemID, texture, itemAP)
Nenue@97 465 end
Nenue@97 466 end
Nenue@97 467 end
Nenue@97 468 end
Nenue@99 469 local fishingText = _G[TOOLTIP_NAME .. 'TextLeft3']:GetText()
Nenue@99 470 if fishingText and fishingText:match('fishing artifact') then
Nenue@99 471 local fishingAP = fishingText:match("%d+")
Nenue@99 472 fishingAP = tonumber(fishingAP)
Nenue@99 473 if fishingAP then
Nenue@99 474 bagData.fishingItems = (bagData.fishingItems or 0) + 1
Nenue@99 475 bagData.fishingAP = (bagData.fishingAP or 0) + fishingAP
Nenue@99 476 bagData.items[itemID] = (bagData.items[itemID] or 0) + 1
Nenue@99 477 local itemButton = self:GetItemButton(itemID, texture, fishingAP)
Nenue@99 478 print(fishingAP, bagData.fishingAP)
Nenue@99 479 end
Nenue@99 480
Nenue@99 481 end
Nenue@99 482
Nenue@97 483 end
Nenue@97 484 end
Nenue@97 485
Nenue@97 486 if self.profile.artifacts[itemID] then
Nenue@97 487 print('artfiact weapon', itemID, link, id, slotID)
Nenue@97 488 self.profile.artifacts[itemID].containerID = id
Nenue@97 489 self.profile.artifacts[itemID].slotID = slotID
Nenue@97 490 end
Nenue@97 491
Nenue@97 492 end
Nenue@97 493
Nenue@97 494 end
Nenue@97 495
Nenue@98 496 local BAG_SLOTS = {0, 1, 2, 3, 4 }
Nenue@98 497 local BANK_SLOTS = {-1, 5, 6,7, 8, 9, 10, 11, 12}
Nenue@99 498 local ItemCounts = {}
Nenue@99 499 function ap:ScanAllBags()
Nenue@99 500 if InCombatLockdown() then
Nenue@99 501 self.queuedScan = true
Nenue@99 502 return
Nenue@99 503 end
Nenue@99 504 self.queuedScan = nil
Nenue@98 505
Nenue@97 506 print('|cFFFF0088ScanAllBags()|r')
Nenue@97 507
Nenue@99 508 for _, button in ipairs(self.Tokens) do
Nenue@99 509 button.numItems = 0
Nenue@99 510 end
Nenue@99 511
Nenue@99 512
Nenue@98 513 for _, bagID in ipairs(BAG_SLOTS) do
Nenue@98 514 self:ScanBag(bagID)
Nenue@97 515 end
Nenue@97 516
Nenue@99 517 if self.bankAccess then
Nenue@98 518 for _, bagID in ipairs(BANK_SLOTS) do
Nenue@98 519 self:ScanBag(bagID)
Nenue@98 520 end
Nenue@98 521 end
Nenue@98 522
Nenue@98 523 self.bankAP = 0
Nenue@98 524 self.bagAP = 0
Nenue@99 525 self.fishingAP = 0
Nenue@99 526
Nenue@99 527 table.wipe(ItemCounts)
Nenue@98 528 for id, bagData in pairs(self.profile.bagslots) do
Nenue@98 529 print(id, GetBagName(id), bagData.totalAP)
Nenue@98 530 id = tonumber(id)
Nenue@98 531 if bagData.totalAP then
Nenue@98 532 if (id == BANK_CONTAINER) or (id >= 5) then
Nenue@98 533 self.bankAP = self.bankAP + bagData.totalAP
Nenue@98 534 else
Nenue@98 535 self.bagAP = self.bagAP + bagData.totalAP
Nenue@97 536 end
Nenue@98 537 end
Nenue@99 538 if bagData.fishingAP then
Nenue@99 539 self.fishingAP = self.fishingAP + bagData.fishingAP
Nenue@99 540 end
Nenue@97 541
Nenue@97 542 end
Nenue@98 543 self.lastUpdate = GetTime()
Nenue@99 544 self:TryToShow()
Nenue@97 545 end
Nenue@97 546
Nenue@97 547 VeneerArtifactButtonMixin = {}
Nenue@98 548
Nenue@99 549 function VeneerArtifactButtonMixin:SetButton(itemID, artifact, index, equipped)
Nenue@99 550 print(itemID, index)
Nenue@98 551 print(artifact.name, artifact.texture, artifact.currentXP)
Nenue@98 552 self:SetID(itemID)
Nenue@98 553 for k,v in pairs(artifact) do
Nenue@98 554 --print('::',k,v)
Nenue@98 555 self[k] = v
Nenue@98 556 end
Nenue@98 557
Nenue@98 558 -- this can change between artifact parses
Nenue@98 559 local potentialPoints = self.actualLevel
Nenue@99 560 local totalAP = (itemID ~= UNDERLIGHT_ANGLER_ID) and ((self:GetParent().bankAP or 0) + (self:GetParent().bagAP or 0)) or (self:GetParent().fishingAP or 0)
Nenue@99 561 print(totalAP)
Nenue@98 562 local potentialXP = self.actualXP + totalAP
Nenue@99 563
Nenue@98 564 self.potentialXP = potentialXP
Nenue@98 565 local potentialCost = C_ArtifactUI.GetCostForPointAtRank(potentialPoints)
Nenue@98 566 while potentialXP >= potentialCost do
Nenue@98 567 potentialXP = potentialXP - potentialCost
Nenue@98 568 potentialPoints = potentialPoints + 1
Nenue@98 569 print('inc estimate', potentialXP, potentialPoints)
Nenue@98 570 potentialCost = C_ArtifactUI.GetCostForPointAtRank(potentialPoints)
Nenue@98 571 end
Nenue@98 572 self.potentialCost = potentialCost
Nenue@98 573 self.potentialLevel = potentialPoints
Nenue@98 574 self.potentialAdjustedXP = potentialXP
Nenue@98 575
Nenue@98 576
Nenue@99 577 if index ~= 1 then
Nenue@99 578 self:ClearAllPoints()
Nenue@99 579 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPRIGHT', 4, 0)
Nenue@99 580 else
Nenue@99 581 self:ClearAllPoints()
Nenue@99 582 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPLEFT', 4, -4)
Nenue@99 583 end
Nenue@98 584
Nenue@99 585 self.isEquipped = equipped
Nenue@98 586 self:Update()
Nenue@98 587 self:Show()
Nenue@98 588 return self
Nenue@98 589 end
Nenue@98 590
Nenue@97 591 function VeneerArtifactButtonMixin:Update()
Nenue@97 592
Nenue@99 593 local r, g, b = 1, 1, 1
Nenue@99 594 local lR, lG, lB = 1, 1, 0
Nenue@99 595 local levelText = self.level
Nenue@99 596 local xpValue = self.currentXP
Nenue@99 597 local costValue = self.cost
Nenue@97 598 if self.actualLevel ~= self.level then
Nenue@99 599 levelText, r,g,b = self.actualLevel, 0,1,0
Nenue@99 600 xpValue, costValue, lR, lG, lB = self.actualXP, self.actualCost, 0, 1, 0
Nenue@99 601 elseif self.potentialLevel ~= self.level then
Nenue@99 602 levelText, r, g, b = self.potentialLevel, 0,1,1
Nenue@99 603 xpValue, costValue, lR, lG, lB = self.potentialAdjustedXP, self.potentialCost, 0,1,0
Nenue@99 604
Nenue@97 605 end
Nenue@97 606
Nenue@99 607 if xpValue >= 100000 then
Nenue@99 608 xpValue = tostring(floor(xpValue/1000))..'k'
Nenue@99 609 elseif xpValue > 1000 then
Nenue@99 610 xpValue = tostring(floor(xpValue/100)/10)..'k'
Nenue@99 611 end
Nenue@99 612 if costValue >= 100000 then
Nenue@99 613 costValue = tostring(floor(costValue/1000))..'k'
Nenue@99 614 elseif costValue >= 1000 then
Nenue@99 615 costValue = tostring(floor(costValue/100)/10)..'k'
Nenue@99 616 end
Nenue@99 617
Nenue@99 618
Nenue@99 619 self.Level:SetText(levelText)
Nenue@99 620 self.Level:SetTextColor(r, g, b)
Nenue@99 621 self.CurrentXP:SetText(xpValue)
Nenue@99 622 self.CurrentXP:SetTextColor(lR, lG, lB)
Nenue@99 623
Nenue@97 624 if self.isEquipped then
Nenue@97 625 self:SetNormalTexture([[Interface\Buttons\ButtonHilight-Square]])
Nenue@97 626 self:GetNormalTexture():SetBlendMode('ADD')
Nenue@97 627 self:GetNormalTexture():SetVertexColor(0,1,0)
Nenue@97 628 else
Nenue@97 629 self:SetNormalTexture(nil, 'ADD')
Nenue@97 630 end
Nenue@97 631
Nenue@98 632 local currentProgress = (self.currentXP < self.cost) and (self.currentXP / self.cost) or 1
Nenue@98 633 if self.level <= 53 then
Nenue@99 634
Nenue@98 635 self.CurrentProgress.animateFrom = self.CurrentProgress:GetHeight() or 1
Nenue@98 636 self.CurrentProgress.animateTo = currentProgress * self:GetHeight()
Nenue@98 637 self.CurrentProgress:Show()
Nenue@98 638 else
Nenue@98 639 self.CurrentProgress:Hide()
Nenue@98 640 end
Nenue@99 641
Nenue@98 642 if self.potentialXP > self.currentXP then
Nenue@99 643 local projectedProgress = (self.potentialAdjustedXP < self.potentialCost) and (self.potentialXP / self.potentialCost) or 1
Nenue@99 644
Nenue@98 645 if (projectedProgress > currentProgress) then
Nenue@98 646 self.AdjustedProgress:SetPoint('BOTTOM', self.CurrentProgress, 'TOP')
Nenue@98 647 projectedProgress = projectedProgress - currentProgress
Nenue@99 648
Nenue@98 649 else
Nenue@98 650 self.AdjustedProgress:SetPoint('BOTTOM', self, 'BOTTOM')
Nenue@98 651 end
Nenue@99 652 print('show potential', currentProgress, projectedProgress)
Nenue@98 653 self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1
Nenue@98 654 self.AdjustedProgress.animateTo = projectedProgress * self:GetHeight()
Nenue@97 655
Nenue@98 656 self.AdjustedProgress:Show()
Nenue@98 657 else
Nenue@98 658 self.AdjustedProgress:Hide()
Nenue@98 659 end
Nenue@97 660
Nenue@99 661
Nenue@97 662 self.Icon:SetTexture(self.texture)
Nenue@97 663 self:SetSize(64,64)
Nenue@97 664 end
Nenue@97 665
Nenue@98 666
Nenue@98 667 function VeneerArtifactButtonMixin:AnimateProgress(region)
Nenue@98 668 local cTime = GetTime()
Nenue@98 669 if not region.animateStart then
Nenue@98 670 region.animateStart = cTime
Nenue@98 671 end
Nenue@98 672 local progressTo, progressFrom = region.animateTo, region.animateFrom
Nenue@98 673 local elapsed = cTime - region.animateStart
Nenue@98 674 if elapsed >= .5 then
Nenue@98 675 region:SetHeight(progressTo)
Nenue@98 676 region.animateTo = nil
Nenue@98 677 region.animateStart = nil
Nenue@98 678 region.animateFrom = nil
Nenue@98 679 else
Nenue@98 680 local progress = elapsed / .5
Nenue@98 681 local height = (progressFrom + (progressTo - progressFrom) * progress)
Nenue@98 682 --print(self:GetName(), progressTo, progressFrom, (progressTo - progressFrom), ceil(progress*10)/10, ceil(height))
Nenue@98 683 region:SetHeight(height)
Nenue@98 684 end
Nenue@98 685 end
Nenue@98 686
Nenue@98 687 function VeneerArtifactButtonMixin:OnUpdate(sinceLast)
Nenue@98 688 if self.CurrentProgress.animateTo then
Nenue@98 689 self:AnimateProgress(self.CurrentProgress)
Nenue@98 690 end
Nenue@98 691
Nenue@98 692 if self.AdjustedProgress.animateTo then
Nenue@98 693 self:AnimateProgress(self.AdjustedProgress)
Nenue@98 694 end
Nenue@98 695
Nenue@98 696 end
Nenue@98 697
Nenue@97 698 function VeneerArtifactButtonMixin:OnEnter()
Nenue@97 699 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
Nenue@97 700 GameTooltip:SetText(self.name)
Nenue@98 701 GameTooltip:AddLine(tostring(self.currentXP) .. ' / '..tostring(self.cost), 1, 1, 0)
Nenue@98 702 if self.potentialXP > self.currentXP then
Nenue@98 703 GameTooltip:AddLine(tostring(self.potentialXP) .. ' potential XP', 0, 1, 1)
Nenue@99 704 if self.potentialAdjustedXP ~= self.potentialXP then
Nenue@99 705 GameTooltip:AddLine(tostring(self.potentialAdjustedXP) .. ' / ' .. tostring(self.potentialCost).. ' after', 0, 1, 0)
Nenue@98 706 end
Nenue@97 707 end
Nenue@99 708 if self.actualLevel ~= self.level then
Nenue@99 709 GameTooltip:AddLine(tostring(self.actualLevel - self.level) .. ' points unlocked', 0, 1, 1)
Nenue@99 710 end
Nenue@99 711
Nenue@97 712 GameTooltip:Show()
Nenue@97 713 end
Nenue@97 714 function VeneerArtifactButtonMixin:OnLeave()
Nenue@97 715 if GameTooltip:IsOwned(self) then
Nenue@97 716 GameTooltip:Hide()
Nenue@97 717 end
Nenue@97 718 end
Nenue@97 719
Nenue@97 720 function VeneerArtifactButtonMixin:OnClick(button, down)
Nenue@97 721 if self.isEquipped then
Nenue@97 722 SocketInventoryItem(16)
Nenue@97 723 else
Nenue@97 724 SocketContainerItem(self.containerID, self.slotID)
Nenue@97 725 end
Nenue@97 726 end