annotate Modules/ArtifactPower.lua @ 121:1f68c46bc4de

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