annotate Modules/ArtifactPower.lua @ 138:6e2f20230190 tip

- 8.1 TOC - disabled Currency and WorldState modules for lack of use - BoD progress link buttons for group finder
author Nenue
date Fri, 22 Feb 2019 17:34:58 -0500
parents 414e37af1b1b
children
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@101 11 cache = {},
Nenue@101 12 fishingCache = {},
Nenue@101 13 scanQueue = {},
Nenue@119 14 worldQuestAP = 0,
Nenue@119 15 worldQuestItems = {},
Nenue@99 16 ItemButtons = {},
Nenue@121 17 anchorGroup = 'TOP',
Nenue@122 18 anchorPoint = 'TOPLEFT',
Nenue@116 19 anchorPriority = 3,
Nenue@121 20 anchorFrom = 'BOTTOMLEFT',
Nenue@115 21 moduleName = 'Artifactor',
Nenue@115 22 HideCombat = true
Nenue@97 23 }
Nenue@122 24
Nenue@122 25 VeneerArtifactButtonMixin = {}
Nenue@122 26 local Artifact = VeneerArtifactButtonMixin
Nenue@122 27
Nenue@101 28 local defaultSettings = {
Nenue@101 29 firstUse = true,
Nenue@101 30 autoHide = true,
Nenue@101 31 }
Nenue@116 32 local Module = VeneerArtifactPowerMixin
Nenue@122 33 local BAGS_TO_SCAN = {BACKPACK_CONTAINER}
Nenue@97 34 local TOOLTIP_NAME = 'VeneerAPScanner'
Nenue@123 35 local XP_INSET = 1
Nenue@123 36 local XP_WIDTH = 4
Nick@111 37 local FISHING_MAX_TRAITS = 24
Nenue@116 38 local WEAPON_MAX_TRAITS = 92
Nenue@116 39 local FRAME_PADDING = 4
Nenue@116 40 local EQUIPPED_SIZE = 64
Nick@111 41 local BUTTON_SIZE = 48
Nenue@99 42 local FRAME_LIST = {'ContainerFrame1', 'BankFrame'}
Nenue@99 43 local BAG_FRAMES = {'ContainerFrame1'}
Nenue@129 44 local BANK_FRAMES = {'BankFrame' }
Nenue@129 45 local ZONE_ID_ARGUS = 1184
Nenue@129 46 local ZONE_ID_BROKEN_ISLE = 1007
Nenue@99 47
Nenue@116 48 function Module:OnLoad()
Nenue@97 49 self:RegisterEvent('BAG_UPDATE') -- use to obtain bag IDs to scan
Nenue@97 50 self:RegisterEvent('BAG_UPDATE_DELAYED') -- use to trigger actual scan activity
Nenue@122 51 self:RegisterEvent('BANKFRAME_OPENED') -- bank info available
Nenue@122 52 self:RegisterEvent('BANKFRAME_CLOSED') --
Nenue@122 53 self:RegisterEvent('ARTIFACT_UPDATE') -- visible data change
Nenue@122 54 self:RegisterEvent('ARTIFACT_XP_UPDATE') -- xp for equipped artifact
Nenue@122 55 self:RegisterEvent('PLAYER_REGEN_ENABLED') -- combat
Nenue@122 56 self:RegisterEvent('PLAYER_REGEN_DISABLED') --
Nenue@122 57 self:RegisterEvent('PLAYER_ENTERING_WORLD') -- zone/instance transfer
Nick@108 58 self:RegisterEvent('ITEM_LOCK_CHANGED') -- use to clear bag slot cache data
Nenue@115 59 Veneer:AddHandler(self)
Nenue@97 60 SLASH_VENEER_AP1 = "/vap"
Nenue@97 61 SLASH_VENEER_AP2 = "/veneerap"
Nenue@98 62 SlashCmdList.VENEER_AP = function(arg)
Nenue@98 63 if arg == 'fishing' then
Nenue@98 64 if VeneerData.ArtifactPower.EnableFishing then
Nenue@98 65 VeneerData.ArtifactPower.EnableFishing = nil
Nenue@98 66 else
Nenue@98 67 VeneerData.ArtifactPower.EnableFishing = true
Nenue@98 68 end
Nenue@98 69 self:Print('Show Underlight Angler:', (VeneerData.ArtifactPower.EnableFishing and 'ON' or 'OFF'))
Nenue@98 70 self:Update()
Nick@108 71 elseif arg == 'reset' then
Nick@108 72 if self.db then
Nenue@136 73 self:ResetCache()
Nick@108 74 end
Nenue@136 75 self:Print('Forced refresh.')
Nick@108 76 self:Update()
Nenue@122 77 elseif arg:match('item') then
Nenue@122 78 print('name', arg:match("^item (%S.+)"))
Nenue@122 79 print('num', arg:match("Hitem:(%d+)"))
Nenue@122 80 local linkOrID = arg:match("item:(%d+)") or arg:match("^item (%S+)")
Nenue@122 81 if linkOrID then
Nenue@122 82 local name, etc = GetItemInfo(linkOrID)
Nenue@122 83 end
Nenue@122 84
Nenue@98 85 else
Nenue@122 86
Nenue@98 87 self:Show()
Nenue@98 88 end
Nenue@97 89 end
Nenue@97 90
Nenue@97 91 self.tooltip = CreateFrame('GameTooltip', TOOLTIP_NAME, self, 'GameTooltipTemplate')
Nenue@99 92
Nenue@97 93
Nenue@97 94 end
Nick@108 95 local ShortNumberString = function (value)
Nenue@122 96 if value >= 1000000000 then
Nenue@122 97
Nenue@122 98 return tostring(floor(value/10000000)/100) .. 'B'
Nenue@122 99 elseif value >= 1000000 then
Nenue@116 100 return tostring(floor(value/100000)/10) .. 'M'
Nenue@116 101 elseif value >= 100000 then
Nick@108 102 return tostring(floor(value/1000)) .. 'k'
Nick@108 103 elseif value >= 1000 then
Nick@108 104 return tostring(floor(value/100)/10) .. 'k'
Nick@108 105 else
Nick@108 106 return value
Nick@108 107 end
Nick@108 108 end
Nenue@97 109
Nenue@102 110
Nenue@102 111 local IsBagnonOpen = function()
Nenue@102 112 return ((BagnonFramebank and BagnonFramebank:IsShown()) or (BagnonFrameinventory and BagnonFrameinventory:IsShown()))
Nenue@102 113 end
Nenue@99 114 local addonCompatibility = {
Nenue@99 115 ['Bagnon'] = {
Nenue@99 116 BagFrames = {'BagnonFrameinventory'},
Nenue@99 117 BankFrames = {'BagnonFramebank'},
Nenue@102 118 FrameMethods = {
Nenue@103 119 ['Hide'] = IsBagnonOpen,
Nenue@103 120 ['Show'] = IsBagnonOpen
Nenue@102 121 },
Nenue@103 122 PostHooks = {},
Nenue@99 123 MethodClass = 'Bagnon',
Nenue@102 124 MethodHooks = {'BANK_OPENED', 'BANKFRAME_CLOSED'},
Nenue@102 125
Nenue@99 126 }
Nenue@97 127 }
Nenue@97 128
Nenue@103 129
Nenue@103 130
Nenue@103 131 local queued_hooks = {}
Nenue@103 132 local function CreateHook(...)
Nenue@103 133 if select('#', ...) >= 2 then
Nenue@103 134 tinsert(queued_hooks, {...})
Nenue@103 135 end
Nenue@103 136 if not InCombatLockdown() then
Nenue@103 137 local info = tremove(queued_hooks)
Nenue@103 138 while info do
Nick@111 139 --[[local oFunc = tremove(info, #info)
Nick@111 140 local args = info
Nick@111 141
Nick@111 142 local func = function(...)
Nick@111 143 print('|cFFFF0088Callback:|r', unpack(args))
Nick@111 144
Nick@111 145 oFunc(...)
Nick@111 146 end
Nick@111 147 print('hooking', unpack(info), oFunc, func)
Nick@111 148 hooksecurefunc(unpack(info), func)
Nick@111 149 --]]
Nenue@103 150 hooksecurefunc(unpack(info))
Nenue@103 151 info = tremove(queued_hooks)
Nenue@103 152 end
Nenue@103 153
Nenue@103 154 end
Nenue@103 155 end
Nenue@103 156
Nenue@102 157 local function AddFrameHooks(frame, args)
Nenue@102 158 for funcName, func in pairs(args.FrameMethods) do
Nenue@102 159 print('binding', frame:GetName(), funcName, 'to', tostring(func))
Nenue@103 160 CreateHook(frame, funcName, function()
Nick@111 161 print(frame:GetName(), funcName, 'hook')
Nenue@103 162 VeneerArtifactPower:TryToShow()
Nenue@103 163 end)
Nenue@102 164 end
Nenue@102 165 end
Nenue@102 166 local PENDING_HOOKS = {}
Nenue@119 167 local guid = UnitGUID('player')
Nenue@102 168
Nenue@102 169 local function RegisterInventoryFrame(name, listType, args)
Nenue@102 170 print('register', name, 'as inventory frame type =', (listType == BAG_FRAMES) and 'bags' or 'bank')
Nenue@102 171 tinsert(FRAME_LIST, name)
Nenue@102 172 tinsert(listType, name)
Nenue@102 173 if _G[name] then
Nenue@102 174 AddFrameHooks(_G[name], args)
Nenue@102 175 else
Nenue@102 176 PENDING_HOOKS[name] = args
Nenue@102 177 end
Nenue@102 178 end
Nenue@102 179
Nenue@116 180 function Module:Setup()
Nenue@97 181 print(self:GetName()..':Setup()')
Nenue@119 182 guid = UnitGUID('player')
Nenue@97 183 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings
Nenue@101 184 self.db = VeneerData.ArtifactPower
Nenue@101 185 self.db[guid] = self.db[guid] or {}
Nenue@101 186 self.db.cache = self.db.cache or {}
Nenue@101 187 self.db.fishingCache = self.db.fishingCache or {}
Nenue@101 188
Nenue@101 189 for i, data in pairs(self.cache) do
Nenue@101 190 -- bring in anything found before player data is active
Nenue@101 191 self.db.cache[i] = data
Nenue@101 192 end
Nenue@101 193 for i, data in pairs(self.fishingCache) do
Nenue@101 194 self.db.fishingCache[i] = data
Nenue@101 195 end
Nenue@101 196
Nenue@101 197 self.profile = self.db[guid]
Nick@108 198 self.profile.cache = self.profile.cache or {}
Nick@108 199 self.profile.cache.bagItems = self.profile.cache.bagItems or {}
Nick@108 200 self.profile.cache.bags = self.profile.cache.bags or {}
Nick@108 201 self.profile.cache.fishing = self.profile.cache.fishing or {}
Nick@108 202 self.profile.cache.items = self.profile.cache.items or {}
Nenue@97 203 self.profile.bagslots = self.profile.bagslots or {}
Nenue@97 204 self.profile.artifacts = self.profile.artifacts or {}
Nenue@97 205 self.updateSummary = true
Nick@108 206 self.cache = self.profile.cache
Nenue@97 207
Nenue@101 208 VeneerArtifactPowerTimer:SetScript('OnUpdate', function()
Nenue@101 209 self:OnUpdate()
Nenue@101 210 end)
Nenue@101 211
Nenue@99 212 local DoTryToShow = function()
Nick@111 213
Nenue@99 214 self:TryToShow()
Nenue@99 215 end
Nenue@103 216 CreateHook("OpenBackpack", DoTryToShow)
Nenue@103 217 CreateHook("CloseBackpack", DoTryToShow)
Nenue@99 218
Nenue@97 219 -- Bagnon compatibility
Nenue@97 220 -- todo: ArkInventory, Elv, etc
Nenue@99 221 for addon, args in pairs(addonCompatibility) do
Nenue@99 222 if IsAddOnLoaded(addon) then
Nenue@102 223
Nenue@99 224 for _, name in ipairs(args.BagFrames) do
Nenue@102 225 RegisterInventoryFrame(name, BAG_FRAMES, args)
Nenue@99 226 end
Nenue@99 227 for _, name in ipairs(args.BankFrames) do
Nenue@102 228 RegisterInventoryFrame(name, BANK_FRAMES, args)
Nenue@99 229 end
Nenue@102 230
Nenue@102 231 -- should only specify non-secure functions in this table
Nenue@99 232 for _, name in ipairs(args.PostHooks) do
Nenue@99 233 local oFunc = _G[name]
Nenue@103 234 print('hook entry', name, tostring(oFunc))
Nenue@103 235 CreateHook(name, function(...)
Nenue@103 236 print('|cFFFF0088' .. name .. '|r', ..., 'original', tostring(oFunc))
Nenue@99 237 oFunc(...)
Nenue@99 238 self:TryToShow()
Nenue@103 239 end)
Nenue@99 240 end
Nenue@99 241 local frame = _G[args.MethodClass]
Nenue@99 242 if frame then
Nenue@103 243 print()
Nenue@99 244 for _, name in ipairs(args.MethodHooks) do
Nenue@103 245 CreateHook(frame, name, DoTryToShow)
Nenue@99 246 end
Nenue@97 247 end
Nenue@97 248 end
Nenue@97 249 end
Nenue@101 250
Nenue@101 251 if self.db.firstUse then
Nenue@101 252 self.db.firstUse = nil
Nenue@101 253
Nenue@101 254 end
Nenue@99 255 end
Nenue@97 256
Nenue@97 257 local UNDERLIGHT_ANGLER_ID = 133755
Nenue@97 258
Nenue@116 259 function Module:ResetCache()
Nick@111 260 table.wipe(self.cache.items)
Nick@111 261 table.wipe(self.cache.fishing)
Nick@111 262 table.wipe(self.cache.bags)
Nick@111 263 table.wipe(self.cache.bagItems)
Nick@111 264 self:ScanAllBags()
Nick@111 265 end
Nick@111 266
Nenue@116 267 function Module:QueueBag(containerID)
Nenue@97 268 containerID = tonumber(containerID)
Nenue@97 269 if not containerID then
Nenue@97 270 return
Nenue@97 271 end
Nenue@97 272
Nenue@97 273 if not tContains(BAGS_TO_SCAN, containerID) then
Nenue@97 274 print(' queueing', containerID, type(containerID), #BAGS_TO_SCAN , 'in line')
Nenue@97 275 BAGS_TO_SCAN[#BAGS_TO_SCAN + 1] = containerID
Nenue@97 276 end
Nenue@97 277 end
Nenue@97 278
Nenue@116 279 function Module:Reanchor()
Nenue@99 280 if Veneer then
Nenue@99 281 Veneer:DynamicReanchor()
Nenue@99 282 end
Nenue@99 283 end
Nenue@99 284
Nenue@116 285 function Module:OnShow()
Nenue@99 286 print('|cFFFFFF00OnShow()|r')
Nenue@102 287
Nenue@102 288 for name, args in pairs(PENDING_HOOKS) do
Nenue@102 289 if _G[name] then
Nenue@102 290 AddFrameHooks(_G[name], args)
Nenue@102 291 PENDING_HOOKS[name] = nil
Nenue@102 292 end
Nenue@102 293 end
Nenue@102 294
Nenue@119 295 self:UpdateWorldQuestsAP()
Nenue@119 296 self:RegisterEvent('QUEST_LOG_UPDATE')
Nenue@119 297 self.enabled = true
Nenue@102 298
Nenue@99 299 self:ScanAllBags()
Nenue@136 300 self:TryToShow()
Nenue@99 301 self:Reanchor()
Nenue@97 302 end
Nenue@116 303 function Module:OnHide()
Nick@111 304 print('|cFF88FF00OnHide()|r', debugstack())
Nenue@119 305 self:UnregisterEvent('QUEST_LOG_UPDATE')
Nenue@99 306 self:Reanchor()
Nenue@97 307 end
Nenue@116 308 function Module:OnEnter()
Nenue@97 309
Nenue@97 310 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
Nenue@97 311
Nenue@99 312
Nenue@97 313 GameTooltip:AddLine(self.bagAP)
Nenue@97 314 GameTooltip:AddLine(self.bankAP)
Nenue@97 315
Nenue@97 316 end
Nenue@97 317
Nenue@116 318 function Module:TryToShow()
Nenue@99 319
Nenue@125 320 --print('|cFFFFFF00TryToShow()')
Nenue@99 321
Nenue@99 322 if not InCombatLockdown() then
Nenue@99 323 for _, name in ipairs(FRAME_LIST) do
Nenue@125 324 --print('test:', name, (_G[name] and _G[name]:IsShown()))
Nick@111 325 if _G[name] and _G[name]:IsVisible() then
Nenue@99 326 if self:IsShown() then
Nenue@99 327 self:Update()
Nenue@99 328 else
Nenue@99 329 self:Show()
Nenue@99 330 end
Nenue@99 331 return
Nenue@99 332 end
Nenue@99 333 end
Nenue@99 334 end
Nenue@99 335
Nenue@125 336 --print('failed tests')
Nenue@99 337 self:Hide()
Nenue@99 338 end
Nenue@99 339
Nenue@99 340
Nenue@116 341 function Module:OnEvent(event, ...)
Nenue@125 342 --print('|cFF00FF88OnEvent()', event, ...)
Nenue@99 343 if event == 'PLAYER_ENTERING_WORLD' then
Nenue@99 344 self:TryToShow()
Nenue@136 345
Nenue@136 346 elseif event == 'UNIT_LEVEL' then
Nenue@136 347
Nenue@136 348 if UnitLevel('player') == 110 then
Nenue@136 349 self.profile.knowledgeMultiplier = 52
Nenue@136 350 end
Nenue@136 351
Nenue@99 352 elseif event == 'BAG_UPDATE' then
Nenue@136 353
Nenue@97 354 local containerID = ...
Nenue@97 355 self:QueueBag(containerID)
Nick@108 356 elseif event == 'ITEM_LOCK_CHANGED' then
Nick@108 357
Nick@108 358 local containerID, slotID = ...
Nick@108 359
Nick@108 360 if self.cache.bags[containerID] and self.cache.bags[containerID][slotID] then
Nick@108 361 self.cache.bags[containerID][slotID] = nil
Nick@108 362 self.cache.fishing[containerID][slotID] = nil
Nick@108 363 end
Nick@108 364
Nick@108 365
Nenue@97 366 elseif event == 'PLAYER_BANKSLOTS_CHANGED' then
Nenue@99 367 self:ScanAllBags()
Nenue@136 368 self:TryToShow()
Nenue@97 369 elseif event == 'BAG_UPDATE_DELAYED' then
Nenue@99 370 if not self.firstHit then
Nenue@122 371 -- prevent double call from login
Nenue@99 372 self.firstHit = true
Nenue@99 373 else
Nenue@99 374 self:ScanAllBags()
Nenue@136 375 self:TryToShow()
Nenue@99 376 end
Nenue@97 377 elseif event == 'BANKFRAME_OPENED' then
Nenue@97 378 self.bankAccess = true
Nenue@99 379 self:ScanAllBags()
Nenue@136 380 self:TryToShow()
Nenue@97 381 elseif event == 'BANKFRAME_CLOSED' then
Nenue@99 382 self.bankAccess = nil
Nenue@97 383 elseif event == 'ARTIFACT_UPDATE' then
Nenue@98 384 local newItem = ...
Nenue@98 385 if newItem then
Nenue@98 386 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetArtifactInfo()
Nenue@122 387 self:UpdateArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@122 388 --self:ScanAllBags(self.bankAccess)
Nenue@98 389 end
Nenue@125 390 self:UpdateArtifactButtons()
Nenue@98 391 elseif event == 'ARTIFACT_XP_UPDATE' then
Nenue@98 392 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetEquippedArtifactInfo()
Nenue@122 393 self:UpdateArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@122 394 --self:ScanAllBags(self.bankAccess)
Nenue@125 395 self:UpdateArtifactButtons()
Nenue@97 396 elseif event == 'PLAYER_REGEN_ENABLED' then
Nenue@103 397
Nenue@103 398 if self.queuedScan then
Nenue@103 399 self:ScanAllBags(self.backAccess)
Nenue@97 400 end
Nenue@97 401
Nenue@136 402 self:TryToShow()
Nenue@136 403
Nenue@103 404 if #queued_hooks >= 1 then
Nenue@103 405 CreateHook()
Nenue@103 406 end
Nenue@119 407 elseif event == 'QUEST_LOG_UPDATE' then
Nenue@119 408 self:UpdateWorldQuestsAP()
Nenue@97 409 elseif event == 'PLAYER_REGEN_DISABLED' then
Nenue@97 410 self:Hide()
Nenue@97 411 end
Nenue@97 412 end
Nenue@97 413
Nenue@133 414 local hasShownHeaderTip
Nenue@116 415 function Module:OnUpdate()
Nenue@101 416 if #self.scanQueue >= 1 then
Nenue@101 417 local scanInfo = tremove(self.scanQueue, 1)
Nick@111 418 end
Nick@111 419 if IsShiftKeyDown() then
Nick@111 420 self.Refresh:Show()
Nick@111 421 else
Nick@111 422 self.Refresh:Hide()
Nick@111 423 end
Nenue@101 424
Nenue@133 425 if self.SummaryHeader:IsMouseOver() and self:IsShown() then
Nenue@133 426 if not hasShownHeaderTip then
Nenue@133 427 hasShownHeaderTip = true
Nenue@133 428 GameTooltip:SetOwner(self, 'ANCHOR_BOTTOM')
Nenue@133 429 GameTooltip:AddLine("World Quests")
Nenue@133 430
Nenue@133 431 for zone, data in pairs(self.apQuests) do
Nenue@133 432
Nenue@133 433 if #data >= 1 then
Nenue@133 434 GameTooltip:AddLine(zone)
Nenue@133 435 for i, quest in ipairs(data) do
Nenue@133 436
Nenue@133 437 if IsQuestComplete(quest[1]) then
Nenue@133 438 GameTooltip:AddDoubleLine(quest[2], ShortNumberString(quest[3]), 0.5,0.5,0.5, 0.5,0.5,0.5)
Nenue@133 439 else
Nenue@133 440 GameTooltip:AddDoubleLine(quest[2], ShortNumberString(quest[3]), 1,1,1, 0,1,0)
Nenue@133 441
Nenue@133 442 end
Nenue@133 443
Nenue@133 444 end
Nenue@133 445 end
Nenue@133 446
Nenue@133 447
Nenue@133 448 end
Nenue@133 449
Nenue@133 450 GameTooltip:Show()
Nenue@133 451 end
Nenue@133 452 else
Nenue@133 453 if GameTooltip:IsOwned(self) then
Nenue@133 454 hasShownHeaderTip = nil
Nenue@133 455 GameTooltip:Hide()
Nenue@133 456 end
Nenue@133 457
Nenue@133 458 end
Nenue@133 459
Nenue@133 460
Nenue@101 461 end
Nenue@101 462
Nenue@119 463 function Module:OnMouseDown(button)
Nenue@97 464 self.enabled = nil
Nenue@119 465 if button == 'RightButton' then
Nenue@119 466 self:Hide()
Nenue@119 467 end
Nenue@119 468
Nenue@97 469 end
Nenue@97 470
Nenue@116 471 function Module:Update()
Nenue@97 472 if not self:IsShown() then
Nenue@99 473 print('|cFFFF4400Update()|r')
Nenue@97 474 return
Nenue@97 475 end
Nenue@122 476 print('|cFFFFFF00pdate()|r')
Nenue@122 477
Nenue@136 478
Nenue@136 479 local level = UnitLevel('player')
Nenue@136 480 if level ~= self.profile.playerLevel then
Nenue@136 481 self.profile.playerLevel = level
Nenue@136 482 self:ResetCache()
Nenue@136 483 end
Nenue@136 484
Nenue@136 485
Nenue@122 486 local numButtons = 0
Nenue@122 487 local contentsHeight = 16
Nenue@122 488 local contentsWidth = 400
Nenue@122 489 local artifactsWidth = self:UpdateArtifactButtons()
Nenue@122 490
Nenue@122 491 if artifactsWidth ~= 0 then
Nenue@122 492 contentsHeight = contentsHeight + 64
Nenue@122 493 end
Nenue@122 494
Nenue@122 495 contentsWidth = max(contentsWidth, min(artifactsWidth, 400))
Nenue@122 496
Nenue@122 497 local itemsWidth, itemsHeight = self:UpdateItemButtons()
Nenue@122 498 contentsHeight = contentsHeight + itemsHeight
Nenue@122 499 contentsWidth = max(contentsWidth, itemsWidth)
Nenue@122 500
Nenue@122 501
Nenue@97 502
Nenue@97 503 local bankText, bagText
Nenue@136 504 if artifactsWidth == 0 then
Nenue@101 505 bankText = '|cFF00FF00Shift-Right-Click an artifact weapon to start building data.'
Nenue@101 506 elseif not (self.bankAP and self.bagAP) then
Nenue@97 507 bankText = '|cFFFF0000Open bank frame to count all AP|r '
Nenue@97 508 else
Nick@111 509
Nick@111 510 if self.bagAP and (self.bagAP > 0) then
Nick@111 511 bankText = 'Inventory: |cFFFFFFFF' .. ShortNumberString(self.bagAP) .. '|r'
Nick@111 512 end
Nick@111 513 if self.bankAP and (self.bankAP > 0) then
Nick@111 514 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFFFFFF00'..ShortNumberString(self.bankAP)..' banked|r'
Nick@111 515 end
Nick@111 516 if self.fishingAP and self.fishingAP > 0 then
Nick@111 517 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFF0088FF' .. ShortNumberString(self.fishingAP) .. ' fishing|r'
Nick@111 518 end
Nick@111 519 end
Nick@111 520
Nenue@119 521 if self.worldQuestAP then
Nenue@119 522 bankText = (bankText and (bankText .. '\n') or '') .. '|cFFFFBB00World Quests:|r |cFFFFFFFF' .. ShortNumberString(self.worldQuestAP) .. ''
Nenue@119 523 end
Nick@111 524
Nenue@129 525 if self.argusAP then
Nenue@129 526 bankText = (bankText and (bankText .. '\n') or '') .. '|cFF88FF00Argus WQ:|r |cFFFFFFFF' .. ShortNumberString(self.argusAP) .. ''
Nenue@129 527 end
Nenue@129 528
Nenue@129 529
Nenue@99 530
Nenue@97 531 self.SummaryHeader:SetText(bankText)
Nenue@122 532 if not self.lastButton then
Nenue@122 533 contentsHeight = contentsHeight + self.SummaryHeader:GetHeight()
Nenue@101 534 end
Nenue@101 535
Nenue@101 536
Nick@111 537 if not self.hasArtifacts then
Nick@111 538 self:SetShown(false)
Nick@111 539 end
Nick@111 540
Nenue@101 541
Nick@108 542 self:SetWidth(contentsWidth)
Nick@108 543 self:SetHeight(contentsHeight)
Nenue@101 544 self:Reanchor()
Nenue@101 545 end
Nenue@101 546
Nenue@133 547 Module.apQuests = {}
Nenue@129 548 function Module:GetContinentAP(mapAreaID)
Nenue@119 549
Nenue@129 550 for zoneIndex = 1, C_MapCanvas.GetNumZones(mapAreaID) do
Nenue@129 551 local zoneMapID, zoneName, zoneDepth, left, right, top, bottom = C_MapCanvas.GetZoneInfo(mapAreaID, zoneIndex);
Nenue@119 552 --print(zoneMapID, zoneName)
Nenue@119 553 if zoneDepth <= 1 then -- Exclude subzones
Nenue@129 554 local taskInfo = C_TaskQuest.GetQuestsForPlayerByMapID(zoneMapID, mapAreaID, (mapAreaID == 1184) and 1 or nil);
Nenue@119 555
Nenue@133 556 self.apQuests[zoneName] = self.apQuests[zoneName] or {}
Nenue@133 557 wipe(self.apQuests[zoneName])
Nenue@133 558
Nenue@119 559 if taskInfo then
Nenue@119 560 for i, info in ipairs(taskInfo) do
Nenue@119 561 local questID = info.questId
Nenue@119 562
Nenue@119 563 local questTitle, factionID, capped = C_TaskQuest.GetQuestInfoByQuestID(questID)
Nenue@133 564 if HaveQuestRewardData(questID) then
Nenue@119 565
Nenue@119 566
Nenue@131 567 for i = 1, GetNumQuestLogRewards(questID) or 0 do
Nenue@119 568 local name, texture, numItems, quality, isUsable, itemID = GetQuestLogRewardInfo(i, questID)
Nenue@119 569 if IsArtifactPowerItem(itemID) then
Nenue@133 570
Nenue@133 571 print(questTitle, HaveQuestRewardData(questID))
Nenue@119 572 local _, link = GetItemInfo(itemID)
Nenue@119 573 if link then
Nenue@119 574 local ap = self:GetItemAP(itemID, link)
Nenue@119 575 --print('ap =', ap)
Nenue@119 576 if ap then
Nenue@133 577
Nenue@133 578 if not IsQuestComplete(questID) then
Nenue@133 579 self.worldQuestAP = self.worldQuestAP + ap
Nenue@133 580 if mapAreaID == ZONE_ID_ARGUS then
Nenue@133 581 self.argusAP = self.argusAP + ap
Nenue@133 582 end
Nenue@129 583 end
Nenue@119 584
Nenue@133 585
Nenue@133 586 tinsert(self.apQuests[zoneName], {questID, questTitle, ap})
Nenue@133 587
Nenue@133 588
Nenue@119 589 end
Nenue@119 590
Nenue@119 591 self.worldQuestItems[itemID] = (self.worldQuestItems[itemID] or 0) + 1
Nenue@119 592 end
Nenue@119 593
Nenue@119 594 --print(self.worldQuestAP)
Nenue@119 595 end
Nenue@119 596
Nenue@119 597 end
Nenue@119 598
Nenue@119 599
Nenue@119 600 else
Nenue@119 601 C_TaskQuest.RequestPreloadRewardData(questID);
Nenue@119 602 self.waitingForQuestRewardData = true
Nenue@119 603 end
Nenue@119 604 end
Nenue@119 605 end
Nenue@119 606 end
Nenue@119 607 end
Nenue@129 608
Nenue@129 609 end
Nenue@129 610
Nenue@129 611 function Module:UpdateWorldQuestsAP()
Nenue@129 612 self.waitingForQuestRewardData = false
Nenue@129 613 self.worldQuestAP = 0
Nenue@129 614 self.argusAP = 0
Nenue@129 615 wipe(self.worldQuestItems)
Nenue@133 616 wipe(self.apQuests)
Nenue@129 617 self:GetContinentAP(ZONE_ID_BROKEN_ISLE)
Nenue@129 618 self:GetContinentAP(ZONE_ID_ARGUS)
Nenue@129 619
Nenue@119 620 end
Nenue@119 621
Nenue@116 622 function Module:UpdateArtifactButtons()
Nenue@101 623
Nenue@97 624 -- Artifact icons, in no particular order
Nenue@99 625 self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo()
Nenue@122 626 self.lastButton = nil
Nick@111 627 self.canAddAP = nil
Nick@111 628 self.canAddFishingAP = nil
Nick@111 629 local hasArtifacts
Nenue@97 630 local numButtons = 0
Nenue@99 631 local lastFrame = self
Nenue@99 632 local fishingID, fishingData
Nenue@98 633 local index, button
Nenue@116 634 local equipped =self.profile.artifacts[self.equippedID]
Nenue@116 635 local buttonsWidth = 0
Nenue@116 636 if equipped then
Nenue@116 637 numButtons = numButtons + 1
Nenue@116 638 button = self.Artifact[numButtons]
Nenue@116 639 button.relativeFrame = self
Nenue@125 640 button:SetItem(self.equippedID, equipped, numButtons, true, nil)
Nenue@125 641
Nenue@122 642 if self.equippedID ~= button.itemID then
Nenue@125 643
Nenue@122 644 hasArtifacts = true
Nenue@122 645 end
Nenue@122 646 lastFrame = button
Nenue@116 647 buttonsWidth = EQUIPPED_SIZE + (FRAME_PADDING * 2)
Nenue@116 648 end
Nenue@97 649 for itemID, artifact in pairs(self.profile.artifacts) do
Nenue@116 650 if (itemID == UNDERLIGHT_ANGLER_ID) then
Nenue@116 651 -- only add if we have fishing AP items and it's not being shown in the equipped slot
Nenue@116 652 if VeneerData.ArtifactPower.EnableFishing and (itemID ~= self.equippedID) then
Nenue@98 653 fishingID = itemID
Nenue@98 654 fishingData = artifact
Nenue@98 655 end
Nenue@97 656
Nick@111 657 if artifact.level < FISHING_MAX_TRAITS then
Nick@111 658 if itemID == self.equippedID then
Nick@111 659 self.canAddFishingAP = true
Nick@111 660 end
Nick@111 661 end
Nenue@98 662 else
Nick@111 663 if artifact.level < WEAPON_MAX_TRAITS then
Nick@111 664 if itemID == self.equippedID then
Nick@111 665 self.canAddAP = true
Nenue@116 666 else
Nenue@116 667
Nenue@116 668 hasArtifacts = true
Nenue@116 669 numButtons = numButtons + 1
Nenue@116 670 button = self.Artifact[numButtons]
Nenue@116 671 button.relativeFrame = lastFrame
Nenue@125 672 button:SetItem(itemID, artifact, numButtons, (self.equippedID == itemID), nil)
Nenue@122 673 lastFrame = button
Nenue@116 674 buttonsWidth = buttonsWidth + lastFrame:GetWidth() + FRAME_PADDING
Nick@111 675 end
Nick@108 676 end
Nenue@97 677 end
Nick@111 678 end
Nenue@97 679
Nenue@122 680 self.lastButton = lastFrame
Nenue@122 681
Nenue@97 682
Nick@108 683 if fishingData and (self.fishingAP and self.fishingAP > 0) then
Nenue@98 684 numButtons = numButtons + 1
Nick@111 685 hasArtifacts = true
Nenue@99 686 local button = self.Artifact[numButtons]
Nenue@99 687 button.relativeFrame = lastFrame
Nick@111 688 button.isFishing = true
Nenue@122 689 button:SetItem(fishingID, fishingData, numButtons, self.equippedID == fishingID)
Nenue@122 690 self.lastButton = button
Nenue@98 691 end
Nenue@97 692
Nick@111 693 self.hasArtifacts = hasArtifacts
Nenue@99 694 for i = numButtons+ 1, #self.Artifact do
Nenue@97 695 print('hide', i)
Nenue@97 696 self.Artifact[i]:Hide()
Nenue@97 697 end
Nenue@97 698
Nenue@122 699 self.SummaryHeader:ClearAllPoints()
Nenue@122 700 if self.lastButton then
Nenue@122 701 self.SummaryHeader:SetPoint('TOPLEFT', self.lastButton, 'TOPRIGHT', 4, -2)
Nenue@122 702 else
Nenue@122 703 self.SummaryHeader:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 4, 4)
Nenue@122 704 end
Nenue@122 705
Nenue@122 706
Nick@111 707
Nenue@116 708 return buttonsWidth
Nenue@97 709 end
Nenue@97 710
Nenue@99 711
Nenue@116 712 function Module:UpdateItemButtons()
Nenue@99 713 print('|cFF00FFFFUpdateItemButtons()|r')
Nick@111 714
Nick@111 715 local apType
Nick@111 716 if self.canAddFishingAP then
Nick@111 717 apType = true
Nick@111 718 elseif not self.canAddAP then
Nick@111 719 for index, button in ipairs(self.Tokens) do
Nick@111 720 button:Hide()
Nick@111 721 end
Nick@111 722 return 0, 0
Nick@111 723 end
Nick@111 724
Nick@111 725
Nenue@99 726 local lastFrame, upFrame
Nenue@99 727 local numButtons = 0
Nenue@101 728 local buttonsHeight = 0
Nick@108 729 local buttonsWidth = 0
Nick@111 730
Nenue@99 731 for index, button in ipairs(self.Tokens) do
Nick@111 732 if (button.numItems >= 1) and (button.isFishingAP == apType) then
Nenue@99 733 if button.itemName then
Nenue@99 734 self:SetItemAction(button)
Nenue@99 735 end
Nenue@99 736
Nenue@99 737 button:ClearAllPoints()
Nenue@99 738 numButtons = numButtons + 1
Nick@111 739 local col = mod(numButtons,8)
Nenue@99 740 print(index, button:GetID(), button.Icon:GetTexture())
Nenue@99 741 if numButtons == 1 then
Nenue@101 742 button:SetPoint('TOPLEFT', self, 'TOPLEFT', 4, -76)
Nenue@99 743 upFrame = button
Nenue@101 744 buttonsHeight = 52
Nenue@99 745 else
Nick@108 746 if col == 1 then
Nick@108 747 button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2)
Nick@108 748 upFrame = button
Nick@108 749 buttonsHeight = buttonsHeight + 52
Nick@108 750
Nick@108 751 else
Nick@108 752 button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0)
Nick@108 753
Nick@108 754 end
Nenue@99 755 end
Nick@111 756
Nenue@99 757 button.Count:SetText(button.numItems)
Nenue@99 758 lastFrame = button
Nenue@99 759 button:Show()
Nenue@99 760 else
Nenue@99 761 button:Hide()
Nenue@99 762 end
Nick@111 763 buttonsWidth = min(numButtons, 8) * (BUTTON_SIZE)
Nick@111 764 end
Nick@111 765
Nick@111 766
Nick@111 767
Nick@111 768 if buttonsWidth ~= 0 then
Nick@111 769 buttonsWidth = buttonsWidth + 8+ ((min(numButtons, 8)-1)*2)
Nenue@99 770 end
Nenue@99 771
Nenue@101 772
Nenue@101 773
Nick@108 774 return buttonsWidth, buttonsHeight
Nenue@99 775 end
Nenue@99 776
Nenue@116 777 function Module:SetItemAction(button, name)
Nenue@99 778 name = name or self.itemName
Nenue@99 779 if InCombatLockdown() then
Nenue@99 780 self.itemName = name
Nenue@99 781 return
Nenue@99 782 else
Nenue@99 783 button:SetAttribute('*type*','item')
Nenue@99 784 button:SetAttribute('*item*', name)
Nenue@99 785 end
Nenue@99 786 end
Nenue@99 787
Nenue@116 788 function Module:GetItemButton(itemID, texture, itemAP, fishing)
Nenue@99 789 print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP)
Nenue@99 790 local button = self.ItemButtons[itemID]
Nenue@101 791
Nenue@99 792 if not button then
Nenue@99 793 button = CreateFrame('Button', 'VeneerAPToken'..itemID, self, 'VeneerItemButton')
Nenue@101 794 button.baseAP = itemAP
Nenue@101 795
Nenue@99 796 button:SetPushedTexture([[Interface\Buttons\UI-Quickslot-Depress]])
Nenue@99 797 button:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]],"ADD")
Nenue@99 798 button:SetID(itemID)
Nenue@99 799 button.numItems = 0
Nenue@99 800 button.Icon:SetTexture(texture)
Nenue@99 801 button:RegisterForClicks("AnyUp")
Nick@111 802 button.isFishingAP = fishing
Nenue@99 803 self:SetItemAction(button, GetItemInfo(itemID))
Nenue@99 804
Nenue@99 805 print(' created')
Nenue@99 806 self.ItemButtons[itemID] = button
Nenue@99 807 self.numItems = self.numItems + 1
Nenue@99 808 end
Nenue@99 809
Nenue@116 810 button.Label:SetText(ShortNumberString(itemAP))
Nenue@101 811
Nenue@99 812 button.numItems = button.numItems + 1
Nenue@99 813 return button
Nenue@99 814 end
Nenue@99 815
Nenue@116 816 function Module:GetItemAP(itemID, itemLink, bagData)
Nick@108 817 if not self.cache.items[itemID] then
Nenue@101 818
Nick@111 819 print('doing tooltip scan', itemLink, itemID)
Nenue@101 820 self.tooltip:SetOwner(self, 'ANCHOR_NONE')
Nenue@101 821 self.tooltip:SetHyperlink(itemLink)
Nenue@101 822 self.tooltip:Show()
Nenue@101 823 local numLines = self.tooltip:NumLines()
Nenue@101 824 if numLines >= 3 then
Nenue@101 825 for i = 3, numLines do
Nenue@101 826 local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText()
Nick@111 827 if text then
Nick@111 828
Nick@111 829 text = text:lower():gsub(',', '')
Nenue@116 830
Nick@111 831 if text:match('equipped artifact') then
Nick@111 832 print(itemLink, '-', tonumber(text))
Nenue@116 833
Nenue@116 834 local itemAP = text:match('[%d%.]+')
Nick@111 835 if itemAP then
Nenue@116 836 -- tokens > 1M are described as '%f million'
Nenue@116 837 if text:match("million") then
Nenue@116 838 itemAP = tonumber(itemAP) * 1000000
Nenue@129 839 elseif text:match("billion") then
Nenue@129 840 itemAP = tonumber(itemAP) * 1000000000
Nenue@116 841 end
Nenue@116 842
Nick@111 843 itemAP = itemAP
Nick@111 844 self.cache.items[itemID] = tonumber(itemAP)
Nick@111 845 end
Nick@111 846 end
Nick@111 847 if text:match('fishing artifact') then
Nick@111 848 local fishingAP = text:match("%d+")
Nick@111 849 fishingAP = fishingAP
Nick@111 850 print(itemLink, 'fishing', tonumber(text))
Nick@111 851 if fishingAP then
Nick@111 852 self.cache.items[itemID] = tonumber(fishingAP)
Nick@111 853 self.cache.fishing[itemID] = true
Nick@111 854 end
Nenue@101 855 end
Nenue@101 856 end
Nenue@101 857 end
Nenue@101 858 else
Nenue@101 859
Nick@108 860 self.cache.items[itemID] = 0
Nenue@101 861 end
Nenue@101 862 end
Nick@108 863 return self.cache.items[itemID], self.cache.fishing[itemID]
Nenue@101 864 end
Nenue@101 865
Nenue@122 866 function Module:UpdateArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@122 867 print('|cFF00FF00UpdateArtifact()|r')
Nenue@103 868 if not self.profile then
Nenue@103 869 return
Nenue@103 870 end
Nenue@103 871 local artifacts = self.profile.artifacts
Nenue@103 872
Nenue@103 873 if itemID then
Nenue@103 874
Nenue@103 875 artifacts[itemID] = artifacts[itemID] or {}
Nenue@103 876 table.wipe(artifacts[itemID])
Nenue@103 877 local artifact = artifacts[itemID]
Nenue@103 878
Nenue@103 879 artifact.name = name
Nenue@103 880 artifact.texture = texture
Nenue@103 881 artifact.currentXP = currentXP
Nenue@103 882 artifact.level = pointsSpent
Nenue@116 883 artifact.tier = C_ArtifactUI.GetArtifactTier() or ((pointsSpent >= 36) and 2 or 1)
Nenue@122 884 artifact.itemID = itemID
Nenue@116 885
Nenue@116 886 print('tier', artifact.tier)
Nenue@116 887 local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent, artifact.tier)
Nick@108 888 artifact.currentCost = cost
Nenue@125 889 end
Nenue@103 890
Nenue@125 891 local equippedID = C_ArtifactUI:GetEquippedArtifactInfo()
Nenue@125 892 self.currentEquipped = equippedID
Nenue@103 893 end
Nenue@103 894
Nenue@116 895 function Module:ScanBag(id)
Nenue@97 896 print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id))
Nenue@97 897 local numSlots = GetContainerNumSlots(id)
Nenue@97 898 local requiresUpdate
Nenue@97 899 if numSlots == 0 then
Nenue@97 900 return nil
Nenue@97 901 end
Nenue@97 902
Nenue@97 903
Nenue@97 904 self.profile.bagslots[id] = self.profile.bagslots[id] or {}
Nenue@97 905 table.wipe(self.profile.bagslots[id])
Nenue@97 906 local bagData = self.profile.bagslots[id]
Nenue@97 907 bagData.totalAP = 0
Nenue@99 908 bagData.fishingAP = 0
Nenue@99 909 bagData.items = bagData.items or {}
Nenue@99 910 table.wipe(bagData.items)
Nick@111 911 local c = self.cache
Nenue@99 912
Nick@111 913 c.bagItems[id] = c.bagItems[id] or {}
Nick@111 914 c.bags[id] = c.bags[id] or {}
Nick@111 915 c.fishing[id] = c.fishing[id] or {}
Nick@108 916
Nenue@97 917 for slotID = 1, numSlots do
Nenue@97 918 local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID)
Nenue@101 919 if link then
Nenue@101 920 local itemID = GetContainerItemID(id, slotID)
Nenue@101 921 local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link)
Nenue@97 922
Nick@111 923 if class == 'Consumable' or subclass == 'Cooking' then
Nenue@102 924 --print(GetItemInfo(link))
Nick@108 925 local itemAP, isFishingAP
Nick@111 926 if c.bags[id][slotID] and (c.bagItems[id][slotID] == itemID) then
Nick@111 927 --print('cached slot', id, slotID, name)
Nick@111 928 itemAP = c.bags[id][slotID]
Nick@111 929 isFishingAP = c.fishing[id] and c.fishing[id][slotID]
Nick@108 930 else
Nick@108 931 itemAP, isFishingAP = self:GetItemAP(itemID, link)
Nick@111 932 c.bagItems[id][slotID] = itemID
Nick@111 933 c.bags[id][slotID] = itemAP
Nick@111 934 c.fishing[id][slotID] = isFishingAP
Nick@108 935 end
Nick@108 936
Nick@108 937
Nenue@102 938 --print(itemAP, isFishingAP)
Nenue@102 939 if itemAP and (itemAP > 0) then
Nick@111 940 local itemButton = self:GetItemButton(itemID, texture, itemAP, isFishingAP)
Nenue@102 941
Nenue@101 942 if isFishingAP then
Nenue@101 943 bagData.fishingItems = (bagData.fishingItems or 0) + 1
Nenue@101 944 bagData.fishingAP = (bagData.fishingAP or 0) + itemAP
Nenue@101 945 else
Nick@108 946 itemAP = itemAP
Nenue@101 947 bagData.numItems = (bagData.numItems or 0) + 1
Nenue@101 948 bagData.totalAP = (bagData.totalAP or 0) + itemAP
Nenue@101 949 end
Nenue@101 950 bagData.items[itemID] = (bagData.items[itemID] or 0) + 1
Nenue@101 951 end
Nenue@101 952 elseif self.profile.artifacts[itemID] then
Nick@111 953 --print('artifact weapon', itemID, link, id, slotID)
Nenue@101 954 self.profile.artifacts[itemID].containerID = id
Nenue@101 955 self.profile.artifacts[itemID].slotID = slotID
Nick@111 956 else
Nick@111 957 --print('skipping', class, subclass, link)
Nenue@101 958 end
Nenue@99 959
Nenue@97 960 end
Nenue@97 961
Nenue@97 962 end
Nenue@97 963
Nenue@97 964 end
Nenue@97 965
Nenue@98 966 local BAG_SLOTS = {0, 1, 2, 3, 4 }
Nenue@98 967 local BANK_SLOTS = {-1, 5, 6,7, 8, 9, 10, 11, 12}
Nenue@99 968 local ItemCounts = {}
Nenue@116 969 function Module:ScanAllBags()
Nenue@99 970 if InCombatLockdown() then
Nenue@99 971 self.queuedScan = true
Nenue@99 972 return
Nenue@99 973 end
Nenue@136 974
Nenue@136 975
Nenue@136 976
Nenue@101 977
Nenue@99 978 self.queuedScan = nil
Nenue@98 979
Nenue@101 980 print('|cFFFF0088ScanAllBags()|r', self.profile.knowledgeMultiplier)
Nenue@97 981
Nenue@99 982 for _, button in ipairs(self.Tokens) do
Nenue@99 983 button.numItems = 0
Nenue@99 984 end
Nenue@99 985
Nenue@99 986
Nenue@98 987 for _, bagID in ipairs(BAG_SLOTS) do
Nenue@98 988 self:ScanBag(bagID)
Nenue@97 989 end
Nenue@97 990
Nenue@99 991 if self.bankAccess then
Nenue@98 992 for _, bagID in ipairs(BANK_SLOTS) do
Nenue@98 993 self:ScanBag(bagID)
Nenue@98 994 end
Nenue@98 995 end
Nenue@98 996
Nenue@125 997
Nenue@125 998
Nenue@98 999 self.bankAP = 0
Nenue@98 1000 self.bagAP = 0
Nenue@99 1001 self.fishingAP = 0
Nenue@99 1002
Nenue@99 1003 table.wipe(ItemCounts)
Nenue@98 1004 for id, bagData in pairs(self.profile.bagslots) do
Nick@111 1005 print(id, GetBagName(id), bagData.totalAP, bagData.fishingAP)
Nenue@98 1006 id = tonumber(id)
Nenue@98 1007 if bagData.totalAP then
Nenue@98 1008 if (id == BANK_CONTAINER) or (id >= 5) then
Nenue@98 1009 self.bankAP = self.bankAP + bagData.totalAP
Nenue@98 1010 else
Nenue@98 1011 self.bagAP = self.bagAP + bagData.totalAP
Nenue@97 1012 end
Nenue@98 1013 end
Nenue@99 1014 if bagData.fishingAP then
Nenue@99 1015 self.fishingAP = self.fishingAP + bagData.fishingAP
Nenue@99 1016 end
Nenue@97 1017
Nenue@97 1018 end
Nenue@98 1019 self.lastUpdate = GetTime()
Nenue@103 1020 self.queuedScan = nil
Nenue@97 1021 end
Nenue@97 1022
Nenue@98 1023
Nenue@122 1024 function Artifact:SetItem(itemID, artifact, index, equipped, fishing)
Nenue@122 1025 print('|cFF00FFFFSetItem()|r', itemID, index)
Nenue@98 1026 print(artifact.name, artifact.texture, artifact.currentXP)
Nenue@122 1027
Nick@108 1028 if not artifact.currentCost then
Nick@108 1029 artifact.currentCost = artifact.cost
Nick@108 1030 end
Nick@108 1031
Nenue@98 1032 for k,v in pairs(artifact) do
Nenue@98 1033 --print('::',k,v)
Nenue@98 1034 self[k] = v
Nenue@98 1035 end
Nenue@98 1036
Nick@111 1037 self.isFishing = fishing
Nenue@98 1038 -- this can change between artifact parses
Nenue@117 1039 local unusedXP = (itemID ~= UNDERLIGHT_ANGLER_ID) and ((self:GetParent().bankAP or 0) + (self:GetParent().bagAP or 0)) or (self:GetParent().fishingAP or 0)
Nenue@117 1040 print('unspent:', unusedXP)
Nenue@99 1041
Nenue@117 1042 -- current standing artifact XP (what appears in the artifact ui)
Nenue@117 1043 -- actual artifact XP after any unlocked points are spent
Nenue@117 1044 -- total total of invested and inventory XP
Nenue@117 1045 -- totalCost total of costs between current and actual level
Nenue@117 1046 local actualXP = artifact.currentXP
Nenue@116 1047 local actualLevel = artifact.level
Nenue@116 1048 local actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier)
Nenue@136 1049 local actualTier = artifact.tier
Nenue@116 1050
Nenue@117 1051 print('tier:', artifact.tier)
Nenue@117 1052 print('current:', self.level, self.currentXP, '/', self.currentCost)
Nenue@131 1053 while (actualXP >= actualCost) and (actualCost > 0) do
Nenue@116 1054 actualXP = actualXP - actualCost
Nenue@116 1055 actualLevel = actualLevel + 1
Nenue@136 1056 if actualLevel == 35 then
Nenue@136 1057 -- accomodate the auto-empowerment that occurs at 35 as of patch 7.3
Nenue@136 1058 actualTier = 2
Nenue@136 1059 print('tier =', actualTier)
Nenue@136 1060 end
Nenue@136 1061 actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, actualTier)
Nenue@117 1062
Nenue@136 1063 print('* ', actualLevel, actualXP, actualCost, actualCost)
Nenue@98 1064 end
Nenue@117 1065 print('actual:', actualLevel, actualXP, '/', actualCost)
Nenue@117 1066
Nenue@117 1067
Nenue@123 1068 local totalXP = actualXP + unusedXP
Nenue@123 1069 local totalCost = actualCost
Nenue@123 1070 local totalLevel = actualLevel
Nenue@123 1071
Nenue@123 1072 local remaining = totalXP
Nenue@120 1073 local nextCost = artifact.currentCost
Nenue@123 1074 print(totalXP, totalCost)
Nenue@120 1075 if remaining > nextCost then
Nenue@131 1076 while (remaining >= nextCost) and (nextCost > 0) do
Nenue@117 1077 totalLevel = totalLevel + 1
Nenue@119 1078 remaining = remaining - nextCost
Nenue@136 1079 nextCost = C_ArtifactUI.GetCostForPointAtRank(totalLevel, actualTier)
Nenue@119 1080 print('|cFFFFFF00+ ', totalLevel, remaining, '/', totalCost)
Nenue@117 1081 end
Nenue@119 1082 totalXP = remaining
Nenue@119 1083 totalCost = nextCost
Nenue@117 1084 end
Nenue@117 1085 print('total:', totalLevel, totalXP, '/', totalCost)
Nenue@117 1086
Nenue@117 1087 self.currentLevel = self.level
Nenue@117 1088
Nenue@117 1089
Nenue@116 1090 self.actualCost = actualCost
Nenue@116 1091 self.actualLevel = actualLevel
Nenue@116 1092 self.actualXP = actualXP
Nenue@136 1093 self.actualTier = actualTier
Nenue@117 1094
Nenue@117 1095 self.totalXP = totalXP
Nenue@117 1096 self.totalCost = totalCost
Nenue@117 1097 self.totalLevel = totalLevel
Nenue@136 1098 self.totalTier = totalTier
Nenue@117 1099
Nenue@98 1100
Nenue@98 1101
Nenue@99 1102 if index ~= 1 then
Nenue@99 1103 self:ClearAllPoints()
Nenue@99 1104 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPRIGHT', 4, 0)
Nenue@99 1105 else
Nenue@99 1106 self:ClearAllPoints()
Nenue@99 1107 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPLEFT', 4, -4)
Nenue@99 1108 end
Nenue@98 1109
Nenue@122 1110 self.itemID = itemID
Nenue@99 1111 self.isEquipped = equipped
Nenue@98 1112 self:Update()
Nenue@125 1113 self:SetShown(true)
Nenue@122 1114
Nenue@98 1115 return self
Nenue@98 1116 end
Nenue@98 1117
Nenue@122 1118 function Artifact:UpdateXPBar()
Nenue@122 1119 local r3, g3, b3 = 1, .5, 0 -- main xp bar
Nenue@122 1120 -- current: amount shown in blizz ui
Nenue@122 1121 -- actual: amount contributing the next level, will be same until current point cap is reached
Nenue@122 1122 -- potential: total of ap on hand
Nenue@122 1123 print(self.currentXP, self.actualXP, self.potentialXP)
Nenue@122 1124
Nenue@123 1125 local maxHeight = self:GetHeight() - (XP_INSET*2)
Nenue@122 1126 local currentHeight = self.CurrentProgress:GetHeight() or 1
Nenue@122 1127 local offHeight = self.AdjustedProgress:GetHeight() or 1
Nenue@122 1128
Nenue@122 1129
Nenue@129 1130 self.CurrentProgress:SetPoint('BOTTOM', self.XPBackground, 'BOTTOM', 0, 0)
Nenue@122 1131 local currentProgress = (self.currentXP < self.currentCost) and (self.currentXP / self.currentCost) or 1
Nenue@122 1132 local projectedProgress = (self.totalXP < self.totalCost) and (self.totalXP / self.totalCost) or 1
Nenue@122 1133 if self.actualLevel ~= self.level then
Nenue@122 1134 r3, g3, b3 = 0, 1, 1
Nenue@122 1135 end
Nenue@122 1136
Nenue@123 1137 print('|cFFFF4400', currentProgress, projectedProgress, self.currentLevel, self.totalLevel)
Nenue@122 1138 if self.level <= WEAPON_MAX_TRAITS then
Nenue@122 1139 self.CurrentProgress.animateFrom = currentHeight or 1
Nenue@122 1140 self.CurrentProgress.animateTo = currentProgress * maxHeight
Nenue@122 1141 self.CurrentProgress:Show()
Nenue@122 1142 else
Nenue@122 1143 self.CurrentProgress:Hide()
Nenue@122 1144 end
Nenue@122 1145
Nenue@123 1146 local nextLevel = (self.totalLevel ~= self.currentLevel)
Nenue@123 1147
Nenue@123 1148 if self.totalXP ~= self.currentXP or nextLevel then
Nenue@123 1149 print('project', 'xp test=', (self.totalXP ~= self.currentXP), 'lvl test=', (self.totalLevel ~= self.currentLevel))
Nenue@123 1150
Nenue@123 1151 local projectedPos = projectedProgress
Nenue@123 1152
Nenue@123 1153 if projectedProgress > currentProgress and (not nextLevel) then
Nenue@123 1154 projectedPos = (projectedProgress - currentProgress)
Nenue@123 1155 self.AdjustedProgress:SetPoint('BOTTOM', self.CurrentProgress, 'TOP', 0, 0)
Nenue@123 1156 print(' set above', projectedPos, self.CurrentProgress:GetPoint(3))
Nenue@122 1157 else
Nenue@123 1158 self.AdjustedProgress:SetPoint('BOTTOM', self, 'BOTTOM', 0 , XP_INSET)
Nenue@123 1159 print(' set under', projectedPos)
Nenue@122 1160 end
Nenue@122 1161 self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1
Nenue@123 1162 self.AdjustedProgress.animateTo = projectedPos * maxHeight
Nenue@122 1163 self.AdjustedProgress:Show()
Nenue@122 1164 else
Nenue@123 1165 print('nothing to project')
Nenue@122 1166 self.AdjustedProgress:Hide()
Nenue@122 1167 end
Nenue@123 1168
Nenue@123 1169
Nenue@122 1170 --print(self.CurrentProgress:GetPoint(3))
Nenue@122 1171 --print(self.CurrentProgress:GetSize())
Nenue@122 1172
Nenue@123 1173 self.XPBackground:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', XP_INSET, XP_INSET)
Nenue@123 1174 self.XPBackground:SetPoint('TOPRIGHT', self, 'TOPLEFT', XP_INSET + XP_WIDTH, -XP_INSET)
Nenue@122 1175 self.CurrentProgress:SetColorTexture(r3,g3,b3,1)
Nenue@122 1176
Nenue@122 1177 end
Nenue@122 1178
Nenue@122 1179 function Artifact:OnLoad()
Nenue@122 1180 print('|cFFFF4400OnLoad()|r', self:GetName(), self:GetID())
Nenue@122 1181 end
Nenue@122 1182
Nenue@116 1183 function Artifact:Update()
Nenue@122 1184 if not self.itemID then
Nenue@122 1185 return
Nenue@122 1186 end
Nenue@122 1187
Nenue@125 1188 print(self:GetName(), '|cff00FFFFUpdate()|r')
Nenue@122 1189 local r1, g1, b1 = 1, 1, 1 -- top text
Nenue@122 1190 local r2, g2, b2 = 1, 1, 0 -- bottom text
Nenue@99 1191 local levelText = self.level
Nenue@116 1192 local xpText = ShortNumberString(self.currentXP)
Nenue@116 1193 local costText = ShortNumberString(self.currentCost)
Nenue@116 1194 local remainingText = ShortNumberString(self.currentCost - self.currentXP)
Nenue@122 1195
Nenue@122 1196 local maxHeight = self:GetHeight() - 4
Nenue@122 1197 local currentHeight = self.CurrentProgress:GetHeight() or 1
Nenue@122 1198 local offHeight = self.AdjustedProgress:GetHeight() or 1
Nenue@122 1199
Nenue@97 1200 if self.actualLevel ~= self.level then
Nenue@116 1201 levelText = self.actualLevel
Nenue@116 1202 r1, g1, b1 = 0, 1, 0
Nenue@116 1203 xpText = ShortNumberString(self.actualXP)
Nenue@116 1204 costText = ShortNumberString(self.actualCost)
Nenue@116 1205 remainingText = ShortNumberString(self.actualCost-self.actualXP)
Nenue@116 1206 --[[elseif self.potentialLevel ~= self.level then
Nenue@116 1207 r1, g1, b1 = 0, 1, 1
Nenue@116 1208 r2, g2, b2 = 0, 1, 1
Nenue@116 1209 costText = ShortNumberString(self.potentialCost)
Nenue@116 1210 remainingText = ShortNumberString(self.potentialCost-self.potentialXP)
Nenue@116 1211 --]]
Nenue@97 1212 end
Nenue@97 1213
Nenue@99 1214 self.Level:SetText(levelText)
Nenue@116 1215 self.CurrentXP:SetText( xpText )
Nenue@116 1216 self.RemainingCost:SetText(remainingText)
Nenue@116 1217 self.Level:SetTextColor(r1, g1, b1)
Nenue@116 1218 self.CurrentXP:SetTextColor(r1, g1, b1)
Nenue@99 1219
Nenue@97 1220 if self.isEquipped then
Nenue@116 1221 self:SetSize(64,64)
Nenue@97 1222 self:SetNormalTexture([[Interface\Buttons\ButtonHilight-Square]])
Nenue@97 1223 self:GetNormalTexture():SetBlendMode('ADD')
Nenue@97 1224 self:GetNormalTexture():SetVertexColor(0,1,0)
Nenue@97 1225 else
Nenue@116 1226 self:SetSize(48,48)
Nenue@97 1227 self:SetNormalTexture(nil, 'ADD')
Nenue@97 1228 end
Nenue@97 1229
Nenue@122 1230 self:UpdateXPBar()
Nenue@116 1231
Nenue@117 1232 if self.actualLevel ~= self.currentLevel then
Nenue@117 1233 self:SetNormalTexture([[Interface\Buttons\UI-Quickslot-Depress]], 'ADD')
Nenue@117 1234 self:GetNormalTexture():SetBlendMode('BLEND')
Nenue@117 1235 self:GetNormalTexture():SetVertexColor(1,1,1)
Nenue@117 1236 else
Nenue@117 1237 self:SetNormalTexture(nil, 'ADD')
Nenue@117 1238 end
Nenue@97 1239 self.Icon:SetTexture(self.texture)
Nenue@97 1240 end
Nenue@97 1241
Nenue@119 1242 local XP_SCALING_DURATION = .5
Nenue@116 1243 function Artifact:AnimateProgress(region)
Nenue@98 1244 local cTime = GetTime()
Nenue@98 1245 if not region.animateStart then
Nenue@98 1246 region.animateStart = cTime
Nenue@98 1247 end
Nenue@98 1248 local progressTo, progressFrom = region.animateTo, region.animateFrom
Nenue@98 1249 local elapsed = cTime - region.animateStart
Nenue@119 1250 if elapsed >= XP_SCALING_DURATION then
Nenue@98 1251 region:SetHeight(progressTo)
Nenue@98 1252 region.animateTo = nil
Nenue@98 1253 region.animateStart = nil
Nenue@98 1254 region.animateFrom = nil
Nenue@98 1255 else
Nenue@119 1256 local progress = elapsed / XP_SCALING_DURATION
Nenue@98 1257 local height = (progressFrom + (progressTo - progressFrom) * progress)
Nenue@98 1258 --print(self:GetName(), progressTo, progressFrom, (progressTo - progressFrom), ceil(progress*10)/10, ceil(height))
Nenue@98 1259 region:SetHeight(height)
Nenue@98 1260 end
Nenue@98 1261 end
Nenue@98 1262
Nenue@116 1263 function Artifact:OnUpdate(sinceLast)
Nenue@98 1264 if self.CurrentProgress.animateTo then
Nenue@98 1265 self:AnimateProgress(self.CurrentProgress)
Nenue@98 1266 end
Nenue@98 1267
Nenue@98 1268 if self.AdjustedProgress.animateTo then
Nenue@98 1269 self:AnimateProgress(self.AdjustedProgress)
Nenue@98 1270 end
Nenue@98 1271 end
Nenue@98 1272
Nenue@116 1273 function Artifact:OnEnter()
Nenue@97 1274 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
Nenue@97 1275 GameTooltip:SetText(self.name)
Nenue@119 1276 GameTooltip:AddLine(ShortNumberString(self.currentXP) .. ' / '..ShortNumberString(self.currentCost), 1, 1, 1)
Nenue@99 1277 if self.actualLevel ~= self.level then
Nenue@119 1278 GameTooltip:AddLine(ShortNumberString(self.actualLevel - self.level) .. ' points unlocked', 1, 1, 0)
Nick@108 1279 end
Nick@108 1280 if self.currentXP < self.currentCost then
Nenue@117 1281 GameTooltip:AddLine(ShortNumberString(self.currentCost - self.currentXP) .. ' for level ' .. (self.currentLevel+1), 1, 1, 0)
Nenue@117 1282 else
Nenue@117 1283 GameTooltip:AddLine(ShortNumberString(self.actualCost - self.actualXP) .. ' for level ' .. (self.actualLevel+1), 0, 1, 0)
Nenue@117 1284 end
Nenue@117 1285 if self.totalLevel ~= self.actualLevel then
Nenue@117 1286 GameTooltip:AddLine('Level ' .. self.totalLevel .. ' with unspent tokens', 0, 1, 1)
Nenue@99 1287 end
Nenue@99 1288
Nenue@97 1289 GameTooltip:Show()
Nenue@97 1290 end
Nenue@116 1291 function Artifact:OnLeave()
Nenue@97 1292 if GameTooltip:IsOwned(self) then
Nenue@97 1293 GameTooltip:Hide()
Nenue@97 1294 end
Nenue@97 1295 end
Nenue@116 1296 function Artifact:OnHide()
Nick@108 1297
Nick@108 1298 if GameTooltip:IsOwned(self) then
Nick@108 1299 GameTooltip:Hide()
Nick@108 1300 end
Nick@108 1301 end
Nenue@97 1302
Nenue@116 1303 function Artifact:OnClick(button, down)
Nenue@97 1304 if self.isEquipped then
Nenue@97 1305 SocketInventoryItem(16)
Nenue@97 1306 else
Nick@108 1307 if IsShiftKeyDown() then
Nenue@119 1308 SocketContainerItem(self.containerID, self.slotID)
Nick@108 1309 else
Nick@108 1310
Nick@108 1311 end
Nenue@97 1312 end
Nenue@122 1313 end