comparison Modules/ArtifactPower.lua @ 119:0f47780a83c4

ArtifactPower: - xp bar animations work beyond concordance rank 3
author Nenue
date Sat, 20 May 2017 06:10:52 -0400
parents 589045559484
children 5f1ba488c395
comparison
equal deleted inserted replaced
118:a86b99c84ccc 119:0f47780a83c4
9 numItems = 0, 9 numItems = 0,
10 Tokens = {}, 10 Tokens = {},
11 cache = {}, 11 cache = {},
12 fishingCache = {}, 12 fishingCache = {},
13 scanQueue = {}, 13 scanQueue = {},
14 worldQuestAP = 0,
15 worldQuestItems = {},
14 ItemButtons = {}, 16 ItemButtons = {},
15 anchorPoint = 'TOP', 17 anchorPoint = 'TOP',
16 anchorPriority = 3, 18 anchorPriority = 3,
17 anchorFrom = 'TOP', 19 anchorFrom = 'TOP',
18 moduleName = 'Artifactor', 20 moduleName = 'Artifactor',
153 VeneerArtifactPower:TryToShow() 155 VeneerArtifactPower:TryToShow()
154 end) 156 end)
155 end 157 end
156 end 158 end
157 local PENDING_HOOKS = {} 159 local PENDING_HOOKS = {}
160 local guid = UnitGUID('player')
158 161
159 local function RegisterInventoryFrame(name, listType, args) 162 local function RegisterInventoryFrame(name, listType, args)
160 print('register', name, 'as inventory frame type =', (listType == BAG_FRAMES) and 'bags' or 'bank') 163 print('register', name, 'as inventory frame type =', (listType == BAG_FRAMES) and 'bags' or 'bank')
161 tinsert(FRAME_LIST, name) 164 tinsert(FRAME_LIST, name)
162 tinsert(listType, name) 165 tinsert(listType, name)
167 end 170 end
168 end 171 end
169 172
170 function Module:Setup() 173 function Module:Setup()
171 print(self:GetName()..':Setup()') 174 print(self:GetName()..':Setup()')
172 local guid = UnitGUID('player') 175 guid = UnitGUID('player')
173 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings 176 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings
174 self.db = VeneerData.ArtifactPower 177 self.db = VeneerData.ArtifactPower
175 self.db[guid] = self.db[guid] or {} 178 self.db[guid] = self.db[guid] or {}
176 self.db.cache = self.db.cache or {} 179 self.db.cache = self.db.cache or {}
177 self.db.fishingCache = self.db.fishingCache or {} 180 self.db.fishingCache = self.db.fishingCache or {}
181 self.db.cache[i] = data 184 self.db.cache[i] = data
182 end 185 end
183 for i, data in pairs(self.fishingCache) do 186 for i, data in pairs(self.fishingCache) do
184 self.db.fishingCache[i] = data 187 self.db.fishingCache[i] = data
185 end 188 end
186
187 189
188 self.profile = self.db[guid] 190 self.profile = self.db[guid]
189 self.profile.cache = self.profile.cache or {} 191 self.profile.cache = self.profile.cache or {}
190 self.profile.cache.bagItems = self.profile.cache.bagItems or {} 192 self.profile.cache.bagItems = self.profile.cache.bagItems or {}
191 self.profile.cache.bags = self.profile.cache.bags or {} 193 self.profile.cache.bags = self.profile.cache.bags or {}
281 AddFrameHooks(_G[name], args) 283 AddFrameHooks(_G[name], args)
282 PENDING_HOOKS[name] = nil 284 PENDING_HOOKS[name] = nil
283 end 285 end
284 end 286 end
285 287
286 288 self:UpdateWorldQuestsAP()
289 self:RegisterEvent('QUEST_LOG_UPDATE')
287 self.enabled = true 290 self.enabled = true
291
288 self:ScanAllBags() 292 self:ScanAllBags()
289 self:Reanchor() 293 self:Reanchor()
290 end 294 end
291 function Module:OnHide() 295 function Module:OnHide()
292 print('|cFF88FF00OnHide()|r', debugstack()) 296 print('|cFF88FF00OnHide()|r', debugstack())
297 self:UnregisterEvent('QUEST_LOG_UPDATE')
293 self:Reanchor() 298 self:Reanchor()
294 end 299 end
295 function Module:OnEnter() 300 function Module:OnEnter()
296 301
297 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR') 302 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
377 end 382 end
378 383
379 if #queued_hooks >= 1 then 384 if #queued_hooks >= 1 then
380 CreateHook() 385 CreateHook()
381 end 386 end
387 elseif event == 'QUEST_LOG_UPDATE' then
388 self:UpdateWorldQuestsAP()
382 elseif event == 'PLAYER_REGEN_DISABLED' then 389 elseif event == 'PLAYER_REGEN_DISABLED' then
383 self:Hide() 390 self:Hide()
384 end 391 end
385 end 392 end
386 393
394 self.Refresh:Hide() 401 self.Refresh:Hide()
395 end 402 end
396 403
397 end 404 end
398 405
399 function Module:OnMouseDown() 406 function Module:OnMouseDown(button)
400 self.enabled = nil 407 self.enabled = nil
401 self:Hide() 408 if button == 'RightButton' then
409 self:Hide()
410 end
411
402 end 412 end
403 413
404 function Module:Update() 414 function Module:Update()
405 if not self:IsShown() then 415 if not self:IsShown() then
406 print('|cFFFF4400Update()|r') 416 print('|cFFFF4400Update()|r')
424 if self.fishingAP and self.fishingAP > 0 then 434 if self.fishingAP and self.fishingAP > 0 then
425 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFF0088FF' .. ShortNumberString(self.fishingAP) .. ' fishing|r' 435 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFF0088FF' .. ShortNumberString(self.fishingAP) .. ' fishing|r'
426 end 436 end
427 end 437 end
428 438
429 self.worldQuestAP = 0 439 if self.worldQuestAP then
430 if WorldPlan then 440 bankText = (bankText and (bankText .. '\n') or '') .. '|cFFFFBB00World Quests:|r |cFFFFFFFF' .. ShortNumberString(self.worldQuestAP) .. ''
431 441 end
432 if not self.worldPlanHooked then 442
433 WorldPlan:RegisterDataCallback(function()
434 print('data udpate callback')
435 self:Update()
436 end)
437 self.worldPlanHooked = true
438 end
439
440
441 local showWQ
442 print('world plan is loaded')
443 local worldQuests = WorldPlan:GetQuestPins()
444 for index, pin in ipairs(worldQuests) do
445 if (pin.rewardType == WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER) and (pin.isActive) and (pin.dataLoaded) then
446 showWQ = true
447 print(pin.itemNumber)
448 self.worldQuestAP = self.worldQuestAP + pin.itemNumber
449 end
450 end
451
452 if showWQ then
453 bankText = (bankText and (bankText .. '\n') or '') .. '|cFFFFBB00World Quests:|r |cFFFFFFFF' .. ShortNumberString(self.worldQuestAP) .. ''
454 end
455
456 end
457 443
458 self.SummaryHeader:SetText(bankText) 444 self.SummaryHeader:SetText(bankText)
459 445
460 local numButtons = 0 446 local numButtons = 0
461 local contentsHeight = 16 + self.SummaryHeader:GetHeight() 447 local contentsHeight = 16 + self.SummaryHeader:GetHeight()
462 local contentsWidth = self.SummaryHeader:GetWidth() + 16 448 local contentsWidth = 400
463 if self.profile.knowledgeMultiplier then 449 if self.profile.knowledgeMultiplier then
464 local artifactsWidth = self:UpdateArtifactButtons() 450 local artifactsWidth = self:UpdateArtifactButtons()
465 451
466 if artifactsWidth ~= 0 then 452 if artifactsWidth ~= 0 then
467 contentsHeight = contentsHeight + 64 453 contentsHeight = contentsHeight + 64
468 end 454 end
469 455
470 contentsWidth = max(contentsWidth, artifactsWidth) 456 contentsWidth = max(contentsWidth, min(artifactsWidth, 400))
471 457
472 local itemsWidth, itemsHeight = self:UpdateItemButtons() 458 local itemsWidth, itemsHeight = self:UpdateItemButtons()
473 contentsHeight = contentsHeight + itemsHeight 459 contentsHeight = contentsHeight + itemsHeight
474 contentsWidth = max(contentsWidth, itemsWidth) 460 contentsWidth = max(contentsWidth, itemsWidth)
475 end 461 end
481 467
482 468
483 self:SetWidth(contentsWidth) 469 self:SetWidth(contentsWidth)
484 self:SetHeight(contentsHeight) 470 self:SetHeight(contentsHeight)
485 self:Reanchor() 471 self:Reanchor()
472 end
473
474 local BROKEN_ISLE_ID = 1007
475
476 function Module:UpdateWorldQuestsAP()
477 self.waitingForQuestRewardData = false
478 self.worldQuestAP = 0
479 wipe(self.worldQuestItems)
480
481 for zoneIndex = 1, C_MapCanvas.GetNumZones(BROKEN_ISLE_ID) do
482 local zoneMapID, zoneName, zoneDepth, left, right, top, bottom = C_MapCanvas.GetZoneInfo(BROKEN_ISLE_ID, zoneIndex);
483 --print(zoneMapID, zoneName)
484 if zoneDepth <= 1 then -- Exclude subzones
485 local taskInfo = C_TaskQuest.GetQuestsForPlayerByMapID(zoneMapID, BROKEN_ISLE_ID);
486
487 if taskInfo then
488 for i, info in ipairs(taskInfo) do
489 local questID = info.questId
490
491 local questTitle, factionID, capped = C_TaskQuest.GetQuestInfoByQuestID(questID)
492 --print(questTitle, HaveQuestRewardData(questID))
493 if HaveQuestRewardData(questID) then
494
495
496 local numQuestRewards = GetNumQuestLogRewards(questID);
497
498 if numQuestRewards > 0 then
499 for i = 1, numQuestRewards do
500 local name, texture, numItems, quality, isUsable, itemID = GetQuestLogRewardInfo(i, questID)
501 if IsArtifactPowerItem(itemID) then
502 local _, link = GetItemInfo(itemID)
503 if link then
504 local ap = self:GetItemAP(itemID, link)
505 --print('ap =', ap)
506 if ap then
507 self.worldQuestAP = self.worldQuestAP + ap
508
509 end
510
511 self.worldQuestItems[itemID] = (self.worldQuestItems[itemID] or 0) + 1
512 end
513
514 --print(self.worldQuestAP)
515 end
516
517 end
518
519 end
520
521
522 else
523 C_TaskQuest.RequestPreloadRewardData(questID);
524 self.waitingForQuestRewardData = true
525 end
526 end
527 end
528 end
529 end
486 end 530 end
487 531
488 function Module:UpdateArtifactButtons() 532 function Module:UpdateArtifactButtons()
489 533
490 -- Artifact icons, in no particular order 534 -- Artifact icons, in no particular order
905 -- total total of invested and inventory XP 949 -- total total of invested and inventory XP
906 -- totalCost total of costs between current and actual level 950 -- totalCost total of costs between current and actual level
907 local actualXP = artifact.currentXP 951 local actualXP = artifact.currentXP
908 local actualLevel = artifact.level 952 local actualLevel = artifact.level
909 local actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier) 953 local actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier)
910 local totalXP = actualXP + unusedXP 954 local totalXP = actualXP
911 local totalCost = actualCost 955 local totalCost = actualCost
912 local totalLevel = actualLevel 956 local totalLevel = actualLevel
913 957
914 print('tier:', artifact.tier) 958 print('tier:', artifact.tier)
915 print('current:', self.level, self.currentXP, '/', self.currentCost) 959 print('current:', self.level, self.currentXP, '/', self.currentCost)
922 end 966 end
923 print('actual:', actualLevel, actualXP, '/', actualCost) 967 print('actual:', actualLevel, actualXP, '/', actualCost)
924 968
925 969
926 if unusedXP > 0 then 970 if unusedXP > 0 then
927 local remaining = totalXP 971 local remaining = totalXP + unusedXP
928 local nextCost = artifact.currentCost 972 local nextCost = artifact.currentCost
929 totalCost = nextCost 973 totalCost = nextCost
930 while remaining > nextCost do 974 while remaining > nextCost do
931 totalLevel = totalLevel + 1 975 totalLevel = totalLevel + 1
932 totalCost = totalCost + nextCost 976 remaining = remaining - nextCost
933 nextCost = C_ArtifactUI.GetCostForPointAtRank(totalLevel, artifact.tier) 977 nextCost = C_ArtifactUI.GetCostForPointAtRank(totalLevel, artifact.tier)
934 remaining = remaining - nextCost 978 print('|cFFFFFF00+ ', totalLevel, remaining, '/', totalCost)
935 print('|cFFFFFF00+ ', totalLevel, remaining, '/', nextCost) 979 end
936 end 980 totalXP = remaining
937 981 totalCost = nextCost
938 end 982 end
939 print('total:', totalLevel, totalXP, '/', totalCost) 983 print('total:', totalLevel, totalXP, '/', totalCost)
940 984
941 self.currentLevel = self.level 985 self.currentLevel = self.level
942 986
975 -- current: amount shown in blizz ui 1019 -- current: amount shown in blizz ui
976 -- actual: amount contributing the next level, will be same until current point cap is reached 1020 -- actual: amount contributing the next level, will be same until current point cap is reached
977 -- potential: total of ap on hand 1021 -- potential: total of ap on hand
978 print(self.currentXP, self.actualXP, self.potentialXP) 1022 print(self.currentXP, self.actualXP, self.potentialXP)
979 if self.actualLevel ~= self.level then 1023 if self.actualLevel ~= self.level then
980
981 levelText = self.actualLevel 1024 levelText = self.actualLevel
982 r1, g1, b1 = 0, 1, 0 1025 r1, g1, b1 = 0, 1, 0
983 --r2, g2, b2 = 0, 1, 0 1026 --r2, g2, b2 = 0, 1, 0
984 xpText = ShortNumberString(self.actualXP) 1027 xpText = ShortNumberString(self.actualXP)
985 costText = ShortNumberString(self.actualCost) 1028 costText = ShortNumberString(self.actualCost)
1009 self:SetSize(48,48) 1052 self:SetSize(48,48)
1010 self:SetNormalTexture(nil, 'ADD') 1053 self:SetNormalTexture(nil, 'ADD')
1011 end 1054 end
1012 1055
1013 local currentProgress = (self.currentXP < self.currentCost) and (self.currentXP / self.currentCost) or 1 1056 local currentProgress = (self.currentXP < self.currentCost) and (self.currentXP / self.currentCost) or 1
1014 if self.level <= 53 then 1057 print('|cFFFF4400', currentProgress)
1058 if self.level <= 92 then
1015 self.CurrentProgress.animateFrom = self.CurrentProgress:GetHeight() or 1 1059 self.CurrentProgress.animateFrom = self.CurrentProgress:GetHeight() or 1
1016 self.CurrentProgress.animateTo = currentProgress * self:GetHeight() 1060 self.CurrentProgress.animateTo = currentProgress * self:GetHeight()
1017 self.CurrentProgress:Show() 1061 self.CurrentProgress:Show()
1018 self.ProgressLine:Show() 1062 self.ProgressLine:Show()
1019 else 1063 else
1020 self.CurrentProgress:Hide() 1064 self.CurrentProgress:Hide()
1021 self.ProgressLine:Hide() 1065 self.ProgressLine:Hide()
1022 end 1066 end
1023 1067
1024 if self.actualXP ~= self.currentXP then 1068 if self.totalXP ~= self.currentXP then
1025 local projectedProgress = (self.actualXP ~= self.actualCost) and (self.actualXP / self.actualCost) or 1 1069 local projectedProgress = (self.totalXP / self.totalCost)
1070 print('|cFF00FFFF', projectedProgress)
1026 if (projectedProgress > currentProgress) then 1071 if (projectedProgress > currentProgress) then
1027 self.AdjustedProgress:SetPoint('BOTTOM', self.CurrentProgress, 'TOP') 1072 self.AdjustedProgress:SetPoint('BOTTOM', self.CurrentProgress, 'TOP')
1028 projectedProgress = projectedProgress - currentProgress 1073 projectedProgress = projectedProgress - currentProgress
1029 else 1074 else
1030 self.CurrentProgress:Hide() 1075 self.CurrentProgress:Hide()
1035 self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1 1080 self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1
1036 self.AdjustedProgress.animateTo = projectedProgress * self:GetHeight() 1081 self.AdjustedProgress.animateTo = projectedProgress * self:GetHeight()
1037 self.AdjustedLine:Show() 1082 self.AdjustedLine:Show()
1038 self.AdjustedProgress:Show() 1083 self.AdjustedProgress:Show()
1039 else 1084 else
1085 self.CurrentProgress:SetPoint('BOTTOM', self, 'BOTTOM')
1040 self.AdjustedProgress:Hide() 1086 self.AdjustedProgress:Hide()
1041 self.AdjustedLine:Hide() 1087 self.AdjustedLine:Hide()
1042 end 1088 end
1089 print(self.CurrentProgress:GetPoint(3))
1090 print(self.CurrentProgress:GetSize())
1043 1091
1044 if self.actualLevel ~= self.currentLevel then 1092 if self.actualLevel ~= self.currentLevel then
1045 self:SetNormalTexture([[Interface\Buttons\UI-Quickslot-Depress]], 'ADD') 1093 self:SetNormalTexture([[Interface\Buttons\UI-Quickslot-Depress]], 'ADD')
1046 self:GetNormalTexture():SetBlendMode('BLEND') 1094 self:GetNormalTexture():SetBlendMode('BLEND')
1047 self:GetNormalTexture():SetVertexColor(1,1,1) 1095 self:GetNormalTexture():SetVertexColor(1,1,1)
1048 else 1096 else
1049 self:SetNormalTexture(nil, 'ADD') 1097 self:SetNormalTexture(nil, 'ADD')
1050 1098 end
1051 end
1052
1053
1054
1055
1056 self.Icon:SetTexture(self.texture) 1099 self.Icon:SetTexture(self.texture)
1057 end 1100 end
1058 1101
1059 1102 local XP_SCALING_DURATION = .5
1060 function Artifact:AnimateProgress(region) 1103 function Artifact:AnimateProgress(region)
1061 local cTime = GetTime() 1104 local cTime = GetTime()
1062 if not region.animateStart then 1105 if not region.animateStart then
1063 region.animateStart = cTime 1106 region.animateStart = cTime
1064 end 1107 end
1065 local progressTo, progressFrom = region.animateTo, region.animateFrom 1108 local progressTo, progressFrom = region.animateTo, region.animateFrom
1066 local elapsed = cTime - region.animateStart 1109 local elapsed = cTime - region.animateStart
1067 if elapsed >= .5 then 1110 if elapsed >= XP_SCALING_DURATION then
1068 region:SetHeight(progressTo) 1111 region:SetHeight(progressTo)
1069 region.animateTo = nil 1112 region.animateTo = nil
1070 region.animateStart = nil 1113 region.animateStart = nil
1071 region.animateFrom = nil 1114 region.animateFrom = nil
1072 else 1115 else
1073 local progress = elapsed / .5 1116 local progress = elapsed / XP_SCALING_DURATION
1074 local height = (progressFrom + (progressTo - progressFrom) * progress) 1117 local height = (progressFrom + (progressTo - progressFrom) * progress)
1075 --print(self:GetName(), progressTo, progressFrom, (progressTo - progressFrom), ceil(progress*10)/10, ceil(height)) 1118 --print(self:GetName(), progressTo, progressFrom, (progressTo - progressFrom), ceil(progress*10)/10, ceil(height))
1076 region:SetHeight(height) 1119 region:SetHeight(height)
1077 end 1120 end
1078 end 1121 end
1088 end 1131 end
1089 1132
1090 function Artifact:OnEnter() 1133 function Artifact:OnEnter()
1091 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR') 1134 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
1092 GameTooltip:SetText(self.name) 1135 GameTooltip:SetText(self.name)
1093 GameTooltip:AddLine(ShortNumberString(self.currentXP) .. ' / '..ShortNumberString(self.currentCost), 1, 1, 0) 1136 GameTooltip:AddLine(ShortNumberString(self.currentXP) .. ' / '..ShortNumberString(self.currentCost), 1, 1, 1)
1094 if self.actualLevel ~= self.level then 1137 if self.actualLevel ~= self.level then
1095 GameTooltip:AddLine(ShortNumberString(self.actualLevel - self.level) .. ' points unlocked', 0, 1, 0) 1138 GameTooltip:AddLine(ShortNumberString(self.actualLevel - self.level) .. ' points unlocked', 1, 1, 0)
1096 end 1139 end
1097 if self.currentXP < self.currentCost then 1140 if self.currentXP < self.currentCost then
1098 GameTooltip:AddLine(ShortNumberString(self.currentCost - self.currentXP) .. ' for level ' .. (self.currentLevel+1), 1, 1, 0) 1141 GameTooltip:AddLine(ShortNumberString(self.currentCost - self.currentXP) .. ' for level ' .. (self.currentLevel+1), 1, 1, 0)
1099 else 1142 else
1100 GameTooltip:AddLine(ShortNumberString(self.actualCost - self.actualXP) .. ' for level ' .. (self.actualLevel+1), 0, 1, 0) 1143 GameTooltip:AddLine(ShortNumberString(self.actualCost - self.actualXP) .. ' for level ' .. (self.actualLevel+1), 0, 1, 0)
1120 function Artifact:OnClick(button, down) 1163 function Artifact:OnClick(button, down)
1121 if self.isEquipped then 1164 if self.isEquipped then
1122 SocketInventoryItem(16) 1165 SocketInventoryItem(16)
1123 else 1166 else
1124 if IsShiftKeyDown() then 1167 if IsShiftKeyDown() then
1125 SocketContainerItem(self.containerID, self.slotID) 1168 SocketContainerItem(self.containerID, self.slotID)
1126 else 1169 else
1127 1170
1128 end 1171 end
1129 end 1172 end
1130 end 1173 end