annotate Modules/ArtifactPower.lua @ 123:b3c0258b419d v7.3.0-1

ArtifactPower: - XP progress bar fixes Currency: - More argus stuff - Block dimensions are calculated more consistently TalkingHead - Aesthetic changes - Default right-click behaviour restored (hides the text box)
author Nenue
date Tue, 05 Sep 2017 02:56:33 -0400
parents ea2c616a3b4f
children 3f4794dca91b
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@99 318 print('|cFFFFFF00TryToShow()')
Nenue@99 319
Nenue@99 320 if not InCombatLockdown() then
Nenue@99 321 for _, name in ipairs(FRAME_LIST) do
Nenue@103 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
Nick@111 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@99 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@98 379 elseif event == 'ARTIFACT_XP_UPDATE' then
Nenue@98 380 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetEquippedArtifactInfo()
Nenue@122 381 self:UpdateArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@122 382 --self:ScanAllBags(self.bankAccess)
Nenue@97 383 elseif event == 'PLAYER_REGEN_ENABLED' then
Nenue@103 384
Nenue@103 385 if self.queuedScan then
Nenue@103 386 self:ScanAllBags(self.backAccess)
Nenue@103 387 else
Nenue@103 388 self:TryToShow()
Nenue@97 389 end
Nenue@97 390
Nenue@103 391 if #queued_hooks >= 1 then
Nenue@103 392 CreateHook()
Nenue@103 393 end
Nenue@119 394 elseif event == 'QUEST_LOG_UPDATE' then
Nenue@119 395 self:UpdateWorldQuestsAP()
Nenue@97 396 elseif event == 'PLAYER_REGEN_DISABLED' then
Nenue@97 397 self:Hide()
Nenue@97 398 end
Nenue@97 399 end
Nenue@97 400
Nenue@116 401 function Module:OnUpdate()
Nenue@101 402 if #self.scanQueue >= 1 then
Nenue@101 403 local scanInfo = tremove(self.scanQueue, 1)
Nick@111 404 end
Nick@111 405 if IsShiftKeyDown() then
Nick@111 406 self.Refresh:Show()
Nick@111 407 else
Nick@111 408 self.Refresh:Hide()
Nick@111 409 end
Nenue@101 410
Nenue@101 411 end
Nenue@101 412
Nenue@119 413 function Module:OnMouseDown(button)
Nenue@97 414 self.enabled = nil
Nenue@119 415 if button == 'RightButton' then
Nenue@119 416 self:Hide()
Nenue@119 417 end
Nenue@119 418
Nenue@97 419 end
Nenue@97 420
Nenue@116 421 function Module:Update()
Nenue@97 422 if not self:IsShown() then
Nenue@99 423 print('|cFFFF4400Update()|r')
Nenue@97 424 return
Nenue@97 425 end
Nenue@122 426 print('|cFFFFFF00pdate()|r')
Nenue@122 427
Nenue@122 428 local numButtons = 0
Nenue@122 429 local contentsHeight = 16
Nenue@122 430 local contentsWidth = 400
Nenue@122 431 if self.profile.knowledgeMultiplier then
Nenue@122 432 local artifactsWidth = self:UpdateArtifactButtons()
Nenue@122 433
Nenue@122 434 if artifactsWidth ~= 0 then
Nenue@122 435 contentsHeight = contentsHeight + 64
Nenue@122 436 end
Nenue@122 437
Nenue@122 438 contentsWidth = max(contentsWidth, min(artifactsWidth, 400))
Nenue@122 439
Nenue@122 440 local itemsWidth, itemsHeight = self:UpdateItemButtons()
Nenue@122 441 contentsHeight = contentsHeight + itemsHeight
Nenue@122 442 contentsWidth = max(contentsWidth, itemsWidth)
Nenue@122 443 end
Nenue@122 444
Nenue@122 445
Nenue@97 446
Nenue@97 447 local bankText, bagText
Nenue@101 448 if not self.profile.knowledgeMultiplier then
Nenue@101 449 bankText = '|cFF00FF00Shift-Right-Click an artifact weapon to start building data.'
Nenue@101 450 elseif not (self.bankAP and self.bagAP) then
Nenue@97 451 bankText = '|cFFFF0000Open bank frame to count all AP|r '
Nenue@97 452 else
Nick@111 453
Nick@111 454 if self.bagAP and (self.bagAP > 0) then
Nick@111 455 bankText = 'Inventory: |cFFFFFFFF' .. ShortNumberString(self.bagAP) .. '|r'
Nick@111 456 end
Nick@111 457 if self.bankAP and (self.bankAP > 0) then
Nick@111 458 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFFFFFF00'..ShortNumberString(self.bankAP)..' banked|r'
Nick@111 459 end
Nick@111 460 if self.fishingAP and self.fishingAP > 0 then
Nick@111 461 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFF0088FF' .. ShortNumberString(self.fishingAP) .. ' fishing|r'
Nick@111 462 end
Nick@111 463 end
Nick@111 464
Nenue@119 465 if self.worldQuestAP then
Nenue@119 466 bankText = (bankText and (bankText .. '\n') or '') .. '|cFFFFBB00World Quests:|r |cFFFFFFFF' .. ShortNumberString(self.worldQuestAP) .. ''
Nenue@119 467 end
Nick@111 468
Nenue@99 469
Nenue@97 470 self.SummaryHeader:SetText(bankText)
Nenue@122 471 if not self.lastButton then
Nenue@122 472 contentsHeight = contentsHeight + self.SummaryHeader:GetHeight()
Nenue@101 473 end
Nenue@101 474
Nenue@101 475
Nick@111 476 if not self.hasArtifacts then
Nick@111 477 self:SetShown(false)
Nick@111 478 end
Nick@111 479
Nenue@101 480
Nick@108 481 self:SetWidth(contentsWidth)
Nick@108 482 self:SetHeight(contentsHeight)
Nenue@101 483 self:Reanchor()
Nenue@101 484 end
Nenue@101 485
Nenue@119 486 local BROKEN_ISLE_ID = 1007
Nenue@119 487
Nenue@119 488 function Module:UpdateWorldQuestsAP()
Nenue@119 489 self.waitingForQuestRewardData = false
Nenue@119 490 self.worldQuestAP = 0
Nenue@119 491 wipe(self.worldQuestItems)
Nenue@119 492
Nenue@119 493 for zoneIndex = 1, C_MapCanvas.GetNumZones(BROKEN_ISLE_ID) do
Nenue@119 494 local zoneMapID, zoneName, zoneDepth, left, right, top, bottom = C_MapCanvas.GetZoneInfo(BROKEN_ISLE_ID, zoneIndex);
Nenue@119 495 --print(zoneMapID, zoneName)
Nenue@119 496 if zoneDepth <= 1 then -- Exclude subzones
Nenue@119 497 local taskInfo = C_TaskQuest.GetQuestsForPlayerByMapID(zoneMapID, BROKEN_ISLE_ID);
Nenue@119 498
Nenue@119 499 if taskInfo then
Nenue@119 500 for i, info in ipairs(taskInfo) do
Nenue@119 501 local questID = info.questId
Nenue@119 502
Nenue@119 503 local questTitle, factionID, capped = C_TaskQuest.GetQuestInfoByQuestID(questID)
Nenue@119 504 --print(questTitle, HaveQuestRewardData(questID))
Nenue@119 505 if HaveQuestRewardData(questID) then
Nenue@119 506
Nenue@119 507
Nenue@119 508 local numQuestRewards = GetNumQuestLogRewards(questID);
Nenue@119 509
Nenue@119 510 if numQuestRewards > 0 then
Nenue@119 511 for i = 1, numQuestRewards do
Nenue@119 512 local name, texture, numItems, quality, isUsable, itemID = GetQuestLogRewardInfo(i, questID)
Nenue@119 513 if IsArtifactPowerItem(itemID) then
Nenue@119 514 local _, link = GetItemInfo(itemID)
Nenue@119 515 if link then
Nenue@119 516 local ap = self:GetItemAP(itemID, link)
Nenue@119 517 --print('ap =', ap)
Nenue@119 518 if ap then
Nenue@119 519 self.worldQuestAP = self.worldQuestAP + ap
Nenue@119 520
Nenue@119 521 end
Nenue@119 522
Nenue@119 523 self.worldQuestItems[itemID] = (self.worldQuestItems[itemID] or 0) + 1
Nenue@119 524 end
Nenue@119 525
Nenue@119 526 --print(self.worldQuestAP)
Nenue@119 527 end
Nenue@119 528
Nenue@119 529 end
Nenue@119 530
Nenue@119 531 end
Nenue@119 532
Nenue@119 533
Nenue@119 534 else
Nenue@119 535 C_TaskQuest.RequestPreloadRewardData(questID);
Nenue@119 536 self.waitingForQuestRewardData = true
Nenue@119 537 end
Nenue@119 538 end
Nenue@119 539 end
Nenue@119 540 end
Nenue@119 541 end
Nenue@119 542 end
Nenue@119 543
Nenue@116 544 function Module:UpdateArtifactButtons()
Nenue@101 545
Nenue@97 546 -- Artifact icons, in no particular order
Nenue@99 547 self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo()
Nenue@122 548 self.lastButton = nil
Nick@111 549 self.canAddAP = nil
Nick@111 550 self.canAddFishingAP = nil
Nick@111 551 local hasArtifacts
Nenue@97 552 local numButtons = 0
Nenue@99 553 local lastFrame = self
Nenue@99 554 local fishingID, fishingData
Nenue@98 555 local index, button
Nenue@116 556 local equipped =self.profile.artifacts[self.equippedID]
Nenue@116 557 local buttonsWidth = 0
Nenue@116 558 if equipped then
Nenue@116 559 numButtons = numButtons + 1
Nenue@116 560 button = self.Artifact[numButtons]
Nenue@116 561 button.relativeFrame = self
Nenue@122 562 if self.equippedID ~= button.itemID then
Nenue@122 563 button:SetItem(self.equippedID, equipped, numButtons, true, nil)
Nenue@122 564 hasArtifacts = true
Nenue@122 565 end
Nenue@122 566 lastFrame = button
Nenue@116 567 buttonsWidth = EQUIPPED_SIZE + (FRAME_PADDING * 2)
Nenue@116 568 end
Nenue@97 569 for itemID, artifact in pairs(self.profile.artifacts) do
Nenue@116 570 if (itemID == UNDERLIGHT_ANGLER_ID) then
Nenue@116 571 -- only add if we have fishing AP items and it's not being shown in the equipped slot
Nenue@116 572 if VeneerData.ArtifactPower.EnableFishing and (itemID ~= self.equippedID) then
Nenue@98 573 fishingID = itemID
Nenue@98 574 fishingData = artifact
Nenue@98 575 end
Nenue@97 576
Nick@111 577 if artifact.level < FISHING_MAX_TRAITS then
Nick@111 578 if itemID == self.equippedID then
Nick@111 579 self.canAddFishingAP = true
Nick@111 580 end
Nick@111 581 end
Nenue@98 582 else
Nick@111 583 if artifact.level < WEAPON_MAX_TRAITS then
Nick@111 584 if itemID == self.equippedID then
Nick@111 585 self.canAddAP = true
Nenue@116 586 else
Nenue@116 587
Nenue@116 588 hasArtifacts = true
Nenue@116 589 numButtons = numButtons + 1
Nenue@116 590 button = self.Artifact[numButtons]
Nenue@116 591 button.relativeFrame = lastFrame
Nenue@122 592 if button.itemID ~= itemID then
Nenue@122 593 button:SetItem(itemID, artifact, numButtons, (self.equippedID == itemID), nil)
Nenue@122 594 end
Nenue@122 595 lastFrame = button
Nenue@116 596 buttonsWidth = buttonsWidth + lastFrame:GetWidth() + FRAME_PADDING
Nick@111 597 end
Nick@108 598 end
Nenue@97 599 end
Nick@111 600 end
Nenue@97 601
Nenue@122 602 self.lastButton = lastFrame
Nenue@122 603
Nenue@97 604
Nick@108 605 if fishingData and (self.fishingAP and self.fishingAP > 0) then
Nenue@98 606 numButtons = numButtons + 1
Nick@111 607 hasArtifacts = true
Nenue@99 608 local button = self.Artifact[numButtons]
Nenue@99 609 button.relativeFrame = lastFrame
Nick@111 610 button.isFishing = true
Nenue@122 611 button:SetItem(fishingID, fishingData, numButtons, self.equippedID == fishingID)
Nenue@122 612 self.lastButton = button
Nenue@98 613 end
Nenue@97 614
Nick@111 615 self.hasArtifacts = hasArtifacts
Nenue@99 616 for i = numButtons+ 1, #self.Artifact do
Nenue@97 617 print('hide', i)
Nenue@97 618 self.Artifact[i]:Hide()
Nenue@97 619 end
Nenue@97 620
Nenue@122 621 self.SummaryHeader:ClearAllPoints()
Nenue@122 622 if self.lastButton then
Nenue@122 623 self.SummaryHeader:SetPoint('TOPLEFT', self.lastButton, 'TOPRIGHT', 4, -2)
Nenue@122 624 else
Nenue@122 625 self.SummaryHeader:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 4, 4)
Nenue@122 626 end
Nenue@122 627
Nenue@122 628
Nick@111 629
Nenue@116 630 return buttonsWidth
Nenue@97 631 end
Nenue@97 632
Nenue@99 633
Nenue@116 634 function Module:UpdateItemButtons()
Nenue@99 635 print('|cFF00FFFFUpdateItemButtons()|r')
Nick@111 636
Nick@111 637 local apType
Nick@111 638 if self.canAddFishingAP then
Nick@111 639 apType = true
Nick@111 640 elseif not self.canAddAP then
Nick@111 641 for index, button in ipairs(self.Tokens) do
Nick@111 642 button:Hide()
Nick@111 643 end
Nick@111 644 return 0, 0
Nick@111 645 end
Nick@111 646
Nick@111 647
Nenue@99 648 local lastFrame, upFrame
Nenue@99 649 local numButtons = 0
Nenue@101 650 local buttonsHeight = 0
Nick@108 651 local buttonsWidth = 0
Nick@111 652
Nenue@99 653 for index, button in ipairs(self.Tokens) do
Nick@111 654 if (button.numItems >= 1) and (button.isFishingAP == apType) then
Nenue@99 655 if button.itemName then
Nenue@99 656 self:SetItemAction(button)
Nenue@99 657 end
Nenue@99 658
Nenue@99 659 button:ClearAllPoints()
Nenue@99 660 numButtons = numButtons + 1
Nick@111 661 local col = mod(numButtons,8)
Nenue@99 662 print(index, button:GetID(), button.Icon:GetTexture())
Nenue@99 663 if numButtons == 1 then
Nenue@101 664 button:SetPoint('TOPLEFT', self, 'TOPLEFT', 4, -76)
Nenue@99 665 upFrame = button
Nenue@101 666 buttonsHeight = 52
Nenue@99 667 else
Nick@108 668 if col == 1 then
Nick@108 669 button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2)
Nick@108 670 upFrame = button
Nick@108 671 buttonsHeight = buttonsHeight + 52
Nick@108 672
Nick@108 673 else
Nick@108 674 button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0)
Nick@108 675
Nick@108 676 end
Nenue@99 677 end
Nick@111 678
Nenue@99 679 button.Count:SetText(button.numItems)
Nenue@99 680 lastFrame = button
Nenue@99 681 button:Show()
Nenue@99 682 else
Nenue@99 683 button:Hide()
Nenue@99 684 end
Nick@111 685 buttonsWidth = min(numButtons, 8) * (BUTTON_SIZE)
Nick@111 686 end
Nick@111 687
Nick@111 688
Nick@111 689
Nick@111 690 if buttonsWidth ~= 0 then
Nick@111 691 buttonsWidth = buttonsWidth + 8+ ((min(numButtons, 8)-1)*2)
Nenue@99 692 end
Nenue@99 693
Nenue@101 694
Nenue@101 695
Nick@108 696 return buttonsWidth, buttonsHeight
Nenue@99 697 end
Nenue@99 698
Nenue@116 699 function Module:SetItemAction(button, name)
Nenue@99 700 name = name or self.itemName
Nenue@99 701 if InCombatLockdown() then
Nenue@99 702 self.itemName = name
Nenue@99 703 return
Nenue@99 704 else
Nenue@99 705 button:SetAttribute('*type*','item')
Nenue@99 706 button:SetAttribute('*item*', name)
Nenue@99 707 end
Nenue@99 708 end
Nenue@99 709
Nenue@116 710 function Module:GetItemButton(itemID, texture, itemAP, fishing)
Nenue@99 711 print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP)
Nenue@99 712 local button = self.ItemButtons[itemID]
Nenue@101 713
Nenue@99 714 if not button then
Nenue@99 715 button = CreateFrame('Button', 'VeneerAPToken'..itemID, self, 'VeneerItemButton')
Nenue@101 716 button.baseAP = itemAP
Nenue@101 717
Nenue@99 718 button:SetPushedTexture([[Interface\Buttons\UI-Quickslot-Depress]])
Nenue@99 719 button:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]],"ADD")
Nenue@99 720 button:SetID(itemID)
Nenue@99 721 button.numItems = 0
Nenue@99 722 button.Icon:SetTexture(texture)
Nenue@99 723 button:RegisterForClicks("AnyUp")
Nick@111 724 button.isFishingAP = fishing
Nenue@99 725 self:SetItemAction(button, GetItemInfo(itemID))
Nenue@99 726
Nenue@99 727 print(' created')
Nenue@99 728 self.ItemButtons[itemID] = button
Nenue@99 729 self.numItems = self.numItems + 1
Nenue@99 730 end
Nenue@99 731
Nenue@116 732 button.Label:SetText(ShortNumberString(itemAP))
Nenue@101 733
Nenue@99 734 button.numItems = button.numItems + 1
Nenue@99 735 return button
Nenue@99 736 end
Nenue@99 737
Nenue@116 738 function Module:GetItemAP(itemID, itemLink, bagData)
Nick@108 739 if not self.cache.items[itemID] then
Nenue@101 740
Nick@111 741 print('doing tooltip scan', itemLink, itemID)
Nenue@101 742 self.tooltip:SetOwner(self, 'ANCHOR_NONE')
Nenue@101 743 self.tooltip:SetHyperlink(itemLink)
Nenue@101 744 self.tooltip:Show()
Nenue@101 745 local numLines = self.tooltip:NumLines()
Nenue@101 746 if numLines >= 3 then
Nenue@101 747 for i = 3, numLines do
Nenue@101 748 local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText()
Nick@111 749 if text then
Nick@111 750
Nick@111 751 text = text:lower():gsub(',', '')
Nenue@116 752
Nick@111 753 if text:match('equipped artifact') then
Nick@111 754 print(itemLink, '-', tonumber(text))
Nenue@116 755
Nenue@116 756 local itemAP = text:match('[%d%.]+')
Nick@111 757 if itemAP then
Nenue@116 758 -- tokens > 1M are described as '%f million'
Nenue@116 759 if text:match("million") then
Nenue@116 760 itemAP = tonumber(itemAP) * 1000000
Nenue@116 761 end
Nenue@116 762
Nick@111 763 itemAP = itemAP
Nick@111 764 self.cache.items[itemID] = tonumber(itemAP)
Nick@111 765 end
Nick@111 766 end
Nick@111 767 if text:match('fishing artifact') then
Nick@111 768 local fishingAP = text:match("%d+")
Nick@111 769 fishingAP = fishingAP
Nick@111 770 print(itemLink, 'fishing', tonumber(text))
Nick@111 771 if fishingAP then
Nick@111 772 self.cache.items[itemID] = tonumber(fishingAP)
Nick@111 773 self.cache.fishing[itemID] = true
Nick@111 774 end
Nenue@101 775 end
Nenue@101 776 end
Nenue@101 777 end
Nenue@101 778 else
Nenue@101 779
Nick@108 780 self.cache.items[itemID] = 0
Nenue@101 781 end
Nenue@101 782 end
Nick@108 783 return self.cache.items[itemID], self.cache.fishing[itemID]
Nenue@101 784 end
Nenue@101 785
Nenue@122 786 function Module:UpdateArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@122 787 print('|cFF00FF00UpdateArtifact()|r')
Nenue@103 788 if not self.profile then
Nenue@103 789 return
Nenue@103 790 end
Nenue@103 791 local artifacts = self.profile.artifacts
Nenue@103 792
Nenue@103 793 if itemID then
Nenue@103 794 self.currentEquipped = itemID
Nenue@103 795
Nenue@103 796 artifacts[itemID] = artifacts[itemID] or {}
Nenue@103 797 table.wipe(artifacts[itemID])
Nenue@103 798 local artifact = artifacts[itemID]
Nenue@103 799
Nenue@103 800 artifact.name = name
Nenue@103 801 artifact.texture = texture
Nenue@103 802 artifact.currentXP = currentXP
Nenue@103 803 artifact.level = pointsSpent
Nenue@116 804 artifact.tier = C_ArtifactUI.GetArtifactTier() or ((pointsSpent >= 36) and 2 or 1)
Nenue@122 805 artifact.itemID = itemID
Nenue@116 806
Nenue@116 807 print('tier', artifact.tier)
Nenue@116 808 local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent, artifact.tier)
Nick@108 809 artifact.currentCost = cost
Nenue@103 810
Nenue@122 811 for index, frame in pairs(self.Artifact) do
Nenue@122 812 if frame.itemID == itemID then
Nenue@122 813 frame:SetItem(itemID, artifact, index, (itemID == self.equippedID), (itemID == UNDERLIGHT_ANGLER_ID))
Nenue@122 814 end
Nenue@122 815 end
Nenue@103 816
Nenue@103 817 end
Nenue@103 818 end
Nenue@103 819
Nenue@116 820 function Module:ScanBag(id)
Nenue@97 821 print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id))
Nenue@97 822 local numSlots = GetContainerNumSlots(id)
Nenue@97 823 local requiresUpdate
Nenue@97 824 if numSlots == 0 then
Nenue@97 825 return nil
Nenue@97 826 end
Nenue@97 827
Nenue@97 828
Nenue@97 829 self.profile.bagslots[id] = self.profile.bagslots[id] or {}
Nenue@97 830 table.wipe(self.profile.bagslots[id])
Nenue@97 831 local bagData = self.profile.bagslots[id]
Nenue@97 832 bagData.totalAP = 0
Nenue@99 833 bagData.fishingAP = 0
Nenue@99 834 bagData.items = bagData.items or {}
Nenue@99 835 table.wipe(bagData.items)
Nick@111 836 local c = self.cache
Nenue@99 837
Nick@111 838 c.bagItems[id] = c.bagItems[id] or {}
Nick@111 839 c.bags[id] = c.bags[id] or {}
Nick@111 840 c.fishing[id] = c.fishing[id] or {}
Nick@108 841
Nenue@97 842 for slotID = 1, numSlots do
Nenue@97 843 local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID)
Nenue@101 844 if link then
Nenue@101 845 local itemID = GetContainerItemID(id, slotID)
Nenue@101 846 local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link)
Nenue@97 847
Nick@111 848 if class == 'Consumable' or subclass == 'Cooking' then
Nenue@102 849 --print(GetItemInfo(link))
Nick@108 850 local itemAP, isFishingAP
Nick@111 851 if c.bags[id][slotID] and (c.bagItems[id][slotID] == itemID) then
Nick@111 852 --print('cached slot', id, slotID, name)
Nick@111 853 itemAP = c.bags[id][slotID]
Nick@111 854 isFishingAP = c.fishing[id] and c.fishing[id][slotID]
Nick@108 855 else
Nick@108 856 itemAP, isFishingAP = self:GetItemAP(itemID, link)
Nick@111 857 c.bagItems[id][slotID] = itemID
Nick@111 858 c.bags[id][slotID] = itemAP
Nick@111 859 c.fishing[id][slotID] = isFishingAP
Nick@108 860 end
Nick@108 861
Nick@108 862
Nenue@102 863 --print(itemAP, isFishingAP)
Nenue@102 864 if itemAP and (itemAP > 0) then
Nick@111 865 local itemButton = self:GetItemButton(itemID, texture, itemAP, isFishingAP)
Nenue@102 866
Nenue@101 867 if isFishingAP then
Nenue@101 868 bagData.fishingItems = (bagData.fishingItems or 0) + 1
Nenue@101 869 bagData.fishingAP = (bagData.fishingAP or 0) + itemAP
Nenue@101 870 else
Nick@108 871 itemAP = itemAP
Nenue@101 872 bagData.numItems = (bagData.numItems or 0) + 1
Nenue@101 873 bagData.totalAP = (bagData.totalAP or 0) + itemAP
Nenue@101 874 end
Nenue@101 875 bagData.items[itemID] = (bagData.items[itemID] or 0) + 1
Nenue@101 876 end
Nenue@101 877 elseif self.profile.artifacts[itemID] then
Nick@111 878 --print('artifact weapon', itemID, link, id, slotID)
Nenue@101 879 self.profile.artifacts[itemID].containerID = id
Nenue@101 880 self.profile.artifacts[itemID].slotID = slotID
Nick@111 881 else
Nick@111 882 --print('skipping', class, subclass, link)
Nenue@101 883 end
Nenue@99 884
Nenue@97 885 end
Nenue@97 886
Nenue@97 887 end
Nenue@97 888
Nenue@97 889 end
Nenue@97 890
Nenue@98 891 local BAG_SLOTS = {0, 1, 2, 3, 4 }
Nenue@98 892 local BANK_SLOTS = {-1, 5, 6,7, 8, 9, 10, 11, 12}
Nenue@99 893 local ItemCounts = {}
Nenue@116 894 function Module:ScanAllBags()
Nenue@99 895 if InCombatLockdown() then
Nenue@99 896 self.queuedScan = true
Nenue@99 897 return
Nenue@99 898 end
Nenue@101 899 if not self.profile.knowledgeMultiplier then
Nenue@101 900 print('need to get knowledge level')
Nenue@101 901 return
Nenue@101 902 end
Nenue@101 903
Nenue@99 904 self.queuedScan = nil
Nenue@98 905
Nenue@101 906 print('|cFFFF0088ScanAllBags()|r', self.profile.knowledgeMultiplier)
Nenue@97 907
Nenue@99 908 for _, button in ipairs(self.Tokens) do
Nenue@99 909 button.numItems = 0
Nenue@99 910 end
Nenue@99 911
Nenue@99 912
Nenue@98 913 for _, bagID in ipairs(BAG_SLOTS) do
Nenue@98 914 self:ScanBag(bagID)
Nenue@97 915 end
Nenue@97 916
Nenue@99 917 if self.bankAccess then
Nenue@98 918 for _, bagID in ipairs(BANK_SLOTS) do
Nenue@98 919 self:ScanBag(bagID)
Nenue@98 920 end
Nenue@98 921 end
Nenue@98 922
Nenue@98 923 self.bankAP = 0
Nenue@98 924 self.bagAP = 0
Nenue@99 925 self.fishingAP = 0
Nenue@99 926
Nenue@99 927 table.wipe(ItemCounts)
Nenue@98 928 for id, bagData in pairs(self.profile.bagslots) do
Nick@111 929 print(id, GetBagName(id), bagData.totalAP, bagData.fishingAP)
Nenue@98 930 id = tonumber(id)
Nenue@98 931 if bagData.totalAP then
Nenue@98 932 if (id == BANK_CONTAINER) or (id >= 5) then
Nenue@98 933 self.bankAP = self.bankAP + bagData.totalAP
Nenue@98 934 else
Nenue@98 935 self.bagAP = self.bagAP + bagData.totalAP
Nenue@97 936 end
Nenue@98 937 end
Nenue@99 938 if bagData.fishingAP then
Nenue@99 939 self.fishingAP = self.fishingAP + bagData.fishingAP
Nenue@99 940 end
Nenue@97 941
Nenue@97 942 end
Nenue@98 943 self.lastUpdate = GetTime()
Nenue@103 944 self.queuedScan = nil
Nenue@99 945 self:TryToShow()
Nenue@97 946 end
Nenue@97 947
Nenue@98 948
Nenue@122 949 function Artifact:SetItem(itemID, artifact, index, equipped, fishing)
Nenue@122 950 print('|cFF00FFFFSetItem()|r', itemID, index)
Nenue@98 951 print(artifact.name, artifact.texture, artifact.currentXP)
Nenue@122 952
Nick@108 953 if not artifact.currentCost then
Nick@108 954 artifact.currentCost = artifact.cost
Nick@108 955 end
Nick@108 956
Nenue@98 957 for k,v in pairs(artifact) do
Nenue@98 958 --print('::',k,v)
Nenue@98 959 self[k] = v
Nenue@98 960 end
Nenue@98 961
Nick@111 962 self.isFishing = fishing
Nenue@98 963 -- this can change between artifact parses
Nenue@117 964 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 965 print('unspent:', unusedXP)
Nenue@99 966
Nenue@117 967 -- current standing artifact XP (what appears in the artifact ui)
Nenue@117 968 -- actual artifact XP after any unlocked points are spent
Nenue@117 969 -- total total of invested and inventory XP
Nenue@117 970 -- totalCost total of costs between current and actual level
Nenue@117 971 local actualXP = artifact.currentXP
Nenue@116 972 local actualLevel = artifact.level
Nenue@116 973 local actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier)
Nenue@116 974
Nenue@117 975 print('tier:', artifact.tier)
Nenue@117 976 print('current:', self.level, self.currentXP, '/', self.currentCost)
Nenue@116 977 while actualXP >= actualCost do
Nenue@116 978 actualXP = actualXP - actualCost
Nenue@116 979 actualLevel = actualLevel + 1
Nenue@116 980 actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier)
Nenue@117 981
Nenue@117 982 print('* ', actualLevel, actualXP, actualCost, totalCost)
Nenue@98 983 end
Nenue@117 984 print('actual:', actualLevel, actualXP, '/', actualCost)
Nenue@117 985
Nenue@117 986
Nenue@123 987 local totalXP = actualXP + unusedXP
Nenue@123 988 local totalCost = actualCost
Nenue@123 989 local totalLevel = actualLevel
Nenue@123 990
Nenue@123 991 local remaining = totalXP
Nenue@120 992 local nextCost = artifact.currentCost
Nenue@123 993 print(totalXP, totalCost)
Nenue@120 994 if remaining > nextCost then
Nenue@120 995 while remaining >= nextCost do
Nenue@117 996 totalLevel = totalLevel + 1
Nenue@119 997 remaining = remaining - nextCost
Nenue@117 998 nextCost = C_ArtifactUI.GetCostForPointAtRank(totalLevel, artifact.tier)
Nenue@119 999 print('|cFFFFFF00+ ', totalLevel, remaining, '/', totalCost)
Nenue@117 1000 end
Nenue@119 1001 totalXP = remaining
Nenue@119 1002 totalCost = nextCost
Nenue@117 1003 end
Nenue@117 1004 print('total:', totalLevel, totalXP, '/', totalCost)
Nenue@117 1005
Nenue@117 1006 self.currentLevel = self.level
Nenue@117 1007
Nenue@117 1008
Nenue@116 1009 self.actualCost = actualCost
Nenue@116 1010 self.actualLevel = actualLevel
Nenue@116 1011 self.actualXP = actualXP
Nenue@117 1012
Nenue@117 1013 self.totalXP = totalXP
Nenue@117 1014 self.totalCost = totalCost
Nenue@117 1015 self.totalLevel = totalLevel
Nenue@117 1016
Nenue@98 1017
Nenue@98 1018
Nenue@99 1019 if index ~= 1 then
Nenue@99 1020 self:ClearAllPoints()
Nenue@99 1021 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPRIGHT', 4, 0)
Nenue@99 1022 else
Nenue@99 1023 self:ClearAllPoints()
Nenue@99 1024 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPLEFT', 4, -4)
Nenue@99 1025 end
Nenue@98 1026
Nenue@122 1027 self.itemID = itemID
Nenue@99 1028 self.isEquipped = equipped
Nenue@98 1029 self:Update()
Nenue@98 1030 self:Show()
Nenue@122 1031
Nenue@98 1032 return self
Nenue@98 1033 end
Nenue@98 1034
Nenue@122 1035 function Artifact:UpdateXPBar()
Nenue@122 1036 local r3, g3, b3 = 1, .5, 0 -- main xp bar
Nenue@122 1037 -- current: amount shown in blizz ui
Nenue@122 1038 -- actual: amount contributing the next level, will be same until current point cap is reached
Nenue@122 1039 -- potential: total of ap on hand
Nenue@122 1040 print(self.currentXP, self.actualXP, self.potentialXP)
Nenue@122 1041
Nenue@123 1042 local maxHeight = self:GetHeight() - (XP_INSET*2)
Nenue@122 1043 local currentHeight = self.CurrentProgress:GetHeight() or 1
Nenue@122 1044 local offHeight = self.AdjustedProgress:GetHeight() or 1
Nenue@122 1045
Nenue@122 1046
Nenue@123 1047 self.CurrentProgress:SetPoint('BOTTOM', self, 'BOTTOM', 0, XP_INSET)
Nenue@122 1048 local currentProgress = (self.currentXP < self.currentCost) and (self.currentXP / self.currentCost) or 1
Nenue@122 1049 local projectedProgress = (self.totalXP < self.totalCost) and (self.totalXP / self.totalCost) or 1
Nenue@122 1050 if self.actualLevel ~= self.level then
Nenue@122 1051 r3, g3, b3 = 0, 1, 1
Nenue@122 1052 end
Nenue@122 1053
Nenue@123 1054 print('|cFFFF4400', currentProgress, projectedProgress, self.currentLevel, self.totalLevel)
Nenue@122 1055 if self.level <= WEAPON_MAX_TRAITS then
Nenue@122 1056 self.CurrentProgress.animateFrom = currentHeight or 1
Nenue@122 1057 self.CurrentProgress.animateTo = currentProgress * maxHeight
Nenue@122 1058 self.CurrentProgress:Show()
Nenue@122 1059 else
Nenue@122 1060 self.CurrentProgress:Hide()
Nenue@122 1061 end
Nenue@122 1062
Nenue@123 1063 local nextLevel = (self.totalLevel ~= self.currentLevel)
Nenue@123 1064
Nenue@123 1065 if self.totalXP ~= self.currentXP or nextLevel then
Nenue@123 1066 print('project', 'xp test=', (self.totalXP ~= self.currentXP), 'lvl test=', (self.totalLevel ~= self.currentLevel))
Nenue@123 1067
Nenue@123 1068 local projectedPos = projectedProgress
Nenue@123 1069
Nenue@123 1070 if projectedProgress > currentProgress and (not nextLevel) then
Nenue@123 1071 projectedPos = (projectedProgress - currentProgress)
Nenue@123 1072 self.AdjustedProgress:SetPoint('BOTTOM', self.CurrentProgress, 'TOP', 0, 0)
Nenue@123 1073 print(' set above', projectedPos, self.CurrentProgress:GetPoint(3))
Nenue@122 1074 else
Nenue@123 1075 self.AdjustedProgress:SetPoint('BOTTOM', self, 'BOTTOM', 0 , XP_INSET)
Nenue@123 1076 print(' set under', projectedPos)
Nenue@122 1077 end
Nenue@122 1078 self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1
Nenue@123 1079 self.AdjustedProgress.animateTo = projectedPos * maxHeight
Nenue@122 1080 self.AdjustedProgress:Show()
Nenue@122 1081 else
Nenue@123 1082 print('nothing to project')
Nenue@122 1083 self.AdjustedProgress:Hide()
Nenue@122 1084 end
Nenue@123 1085
Nenue@123 1086
Nenue@122 1087 --print(self.CurrentProgress:GetPoint(3))
Nenue@122 1088 --print(self.CurrentProgress:GetSize())
Nenue@122 1089
Nenue@123 1090 self.XPBackground:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', XP_INSET, XP_INSET)
Nenue@123 1091 self.XPBackground:SetPoint('TOPRIGHT', self, 'TOPLEFT', XP_INSET + XP_WIDTH, -XP_INSET)
Nenue@122 1092 self.CurrentProgress:SetColorTexture(r3,g3,b3,1)
Nenue@122 1093
Nenue@122 1094 end
Nenue@122 1095
Nenue@122 1096 function Artifact:OnLoad()
Nenue@122 1097 print('|cFFFF4400OnLoad()|r', self:GetName(), self:GetID())
Nenue@122 1098 self:RegisterEvent('ARTIFACT_UPDATE')
Nenue@122 1099 self:RegisterEvent('PLAYER_LOGIN')
Nenue@122 1100 end
Nenue@122 1101
Nenue@122 1102 function Artifact:OnEvent(event)
Nenue@122 1103 local itemID, _, _, nextCost = C_ArtifactUI.GetEquippedArtifactInfo()
Nenue@122 1104 print(self:GetID(), '|cFFFF4400OnEvent()|r', event, itemID, '=', self.itemID, (itemID == self.itemID))
Nenue@122 1105 if itemID == self.itemID then
Nenue@122 1106 self:Update()
Nenue@122 1107 end
Nenue@122 1108 end
Nenue@122 1109
Nenue@116 1110 function Artifact:Update()
Nenue@122 1111 if not self.itemID then
Nenue@122 1112 return
Nenue@122 1113 end
Nenue@122 1114
Nenue@122 1115 print(self:GetName(), '|ff00FFFFUpdate()|r')
Nenue@122 1116 local r1, g1, b1 = 1, 1, 1 -- top text
Nenue@122 1117 local r2, g2, b2 = 1, 1, 0 -- bottom text
Nenue@99 1118 local levelText = self.level
Nenue@116 1119 local xpText = ShortNumberString(self.currentXP)
Nenue@116 1120 local costText = ShortNumberString(self.currentCost)
Nenue@116 1121 local remainingText = ShortNumberString(self.currentCost - self.currentXP)
Nenue@122 1122
Nenue@122 1123 local maxHeight = self:GetHeight() - 4
Nenue@122 1124 local currentHeight = self.CurrentProgress:GetHeight() or 1
Nenue@122 1125 local offHeight = self.AdjustedProgress:GetHeight() or 1
Nenue@122 1126
Nenue@97 1127 if self.actualLevel ~= self.level then
Nenue@116 1128 levelText = self.actualLevel
Nenue@116 1129 r1, g1, b1 = 0, 1, 0
Nenue@116 1130 xpText = ShortNumberString(self.actualXP)
Nenue@116 1131 costText = ShortNumberString(self.actualCost)
Nenue@116 1132 remainingText = ShortNumberString(self.actualCost-self.actualXP)
Nenue@116 1133 --[[elseif self.potentialLevel ~= self.level then
Nenue@116 1134 r1, g1, b1 = 0, 1, 1
Nenue@116 1135 r2, g2, b2 = 0, 1, 1
Nenue@116 1136 costText = ShortNumberString(self.potentialCost)
Nenue@116 1137 remainingText = ShortNumberString(self.potentialCost-self.potentialXP)
Nenue@116 1138 --]]
Nenue@97 1139 end
Nenue@97 1140
Nenue@99 1141 self.Level:SetText(levelText)
Nenue@116 1142 self.CurrentXP:SetText( xpText )
Nenue@116 1143 self.RemainingCost:SetText(remainingText)
Nenue@116 1144 self.Level:SetTextColor(r1, g1, b1)
Nenue@116 1145 self.CurrentXP:SetTextColor(r1, g1, b1)
Nenue@99 1146
Nenue@97 1147 if self.isEquipped then
Nenue@116 1148 self:SetSize(64,64)
Nenue@97 1149 self:SetNormalTexture([[Interface\Buttons\ButtonHilight-Square]])
Nenue@97 1150 self:GetNormalTexture():SetBlendMode('ADD')
Nenue@97 1151 self:GetNormalTexture():SetVertexColor(0,1,0)
Nenue@97 1152 else
Nenue@116 1153 self:SetSize(48,48)
Nenue@97 1154 self:SetNormalTexture(nil, 'ADD')
Nenue@97 1155 end
Nenue@97 1156
Nenue@122 1157 self:UpdateXPBar()
Nenue@116 1158
Nenue@117 1159 if self.actualLevel ~= self.currentLevel then
Nenue@117 1160 self:SetNormalTexture([[Interface\Buttons\UI-Quickslot-Depress]], 'ADD')
Nenue@117 1161 self:GetNormalTexture():SetBlendMode('BLEND')
Nenue@117 1162 self:GetNormalTexture():SetVertexColor(1,1,1)
Nenue@117 1163 else
Nenue@117 1164 self:SetNormalTexture(nil, 'ADD')
Nenue@117 1165 end
Nenue@97 1166 self.Icon:SetTexture(self.texture)
Nenue@97 1167 end
Nenue@97 1168
Nenue@119 1169 local XP_SCALING_DURATION = .5
Nenue@116 1170 function Artifact:AnimateProgress(region)
Nenue@98 1171 local cTime = GetTime()
Nenue@98 1172 if not region.animateStart then
Nenue@98 1173 region.animateStart = cTime
Nenue@98 1174 end
Nenue@98 1175 local progressTo, progressFrom = region.animateTo, region.animateFrom
Nenue@98 1176 local elapsed = cTime - region.animateStart
Nenue@119 1177 if elapsed >= XP_SCALING_DURATION then
Nenue@98 1178 region:SetHeight(progressTo)
Nenue@98 1179 region.animateTo = nil
Nenue@98 1180 region.animateStart = nil
Nenue@98 1181 region.animateFrom = nil
Nenue@98 1182 else
Nenue@119 1183 local progress = elapsed / XP_SCALING_DURATION
Nenue@98 1184 local height = (progressFrom + (progressTo - progressFrom) * progress)
Nenue@98 1185 --print(self:GetName(), progressTo, progressFrom, (progressTo - progressFrom), ceil(progress*10)/10, ceil(height))
Nenue@98 1186 region:SetHeight(height)
Nenue@98 1187 end
Nenue@98 1188 end
Nenue@98 1189
Nenue@116 1190 function Artifact:OnUpdate(sinceLast)
Nenue@98 1191 if self.CurrentProgress.animateTo then
Nenue@98 1192 self:AnimateProgress(self.CurrentProgress)
Nenue@98 1193 end
Nenue@98 1194
Nenue@98 1195 if self.AdjustedProgress.animateTo then
Nenue@98 1196 self:AnimateProgress(self.AdjustedProgress)
Nenue@98 1197 end
Nenue@98 1198 end
Nenue@98 1199
Nenue@116 1200 function Artifact:OnEnter()
Nenue@97 1201 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
Nenue@97 1202 GameTooltip:SetText(self.name)
Nenue@119 1203 GameTooltip:AddLine(ShortNumberString(self.currentXP) .. ' / '..ShortNumberString(self.currentCost), 1, 1, 1)
Nenue@99 1204 if self.actualLevel ~= self.level then
Nenue@119 1205 GameTooltip:AddLine(ShortNumberString(self.actualLevel - self.level) .. ' points unlocked', 1, 1, 0)
Nick@108 1206 end
Nick@108 1207 if self.currentXP < self.currentCost then
Nenue@117 1208 GameTooltip:AddLine(ShortNumberString(self.currentCost - self.currentXP) .. ' for level ' .. (self.currentLevel+1), 1, 1, 0)
Nenue@117 1209 else
Nenue@117 1210 GameTooltip:AddLine(ShortNumberString(self.actualCost - self.actualXP) .. ' for level ' .. (self.actualLevel+1), 0, 1, 0)
Nenue@117 1211 end
Nenue@117 1212 if self.totalLevel ~= self.actualLevel then
Nenue@117 1213 GameTooltip:AddLine('Level ' .. self.totalLevel .. ' with unspent tokens', 0, 1, 1)
Nenue@99 1214 end
Nenue@99 1215
Nenue@97 1216 GameTooltip:Show()
Nenue@97 1217 end
Nenue@116 1218 function Artifact:OnLeave()
Nenue@97 1219 if GameTooltip:IsOwned(self) then
Nenue@97 1220 GameTooltip:Hide()
Nenue@97 1221 end
Nenue@97 1222 end
Nenue@116 1223 function Artifact:OnHide()
Nick@108 1224
Nick@108 1225 if GameTooltip:IsOwned(self) then
Nick@108 1226 GameTooltip:Hide()
Nick@108 1227 end
Nick@108 1228 end
Nenue@97 1229
Nenue@116 1230 function Artifact:OnClick(button, down)
Nenue@97 1231 if self.isEquipped then
Nenue@97 1232 SocketInventoryItem(16)
Nenue@97 1233 else
Nick@108 1234 if IsShiftKeyDown() then
Nenue@119 1235 SocketContainerItem(self.containerID, self.slotID)
Nick@108 1236 else
Nick@108 1237
Nick@108 1238 end
Nenue@97 1239 end
Nenue@122 1240 end