annotate Modules/ArtifactPower.lua @ 126:3de635cda288 v7.3.17102017

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