AzeriteBar.lua

AzeriteBar.lua (8.2.0.31429; unchanged since 8.2.0.30920)
  1. local AZERITE_XP_BAR_EVENTS = {
  2. "PLAYER_ENTERING_WORLD",
  3. "AZERITE_ITEM_EXPERIENCE_CHANGED",
  4. "CVAR_UPDATE",
  5. "BAG_UPDATE",
  6. };
  7. AzeriteBarMixin = CreateFromMixins(StatusTrackingBarMixin);
  8. function AzeriteBarMixin:ShouldBeVisible()
  9. local isMaxLevel = C_AzeriteItem.IsAzeriteItemAtMaxLevel();
  10. if isMaxLevel then
  11. return false;
  12. end
  13. return C_AzeriteItem.HasActiveAzeriteItem();
  14. end
  15. function AzeriteBarMixin:Update()
  16. local azeriteItemLocation = C_AzeriteItem.FindActiveAzeriteItem();
  17. if (not azeriteItemLocation) then
  18. return;
  19. end
  20. local azeriteItem = Item:CreateFromItemLocation(azeriteItemLocation);
  21. if AzeriteUtil.IsAzeriteItemLocationBankBag(azeriteItemLocation) then
  22. self.xp, self.totalLevelXP = 0, 1;
  23. self.currentLevel = -1;
  24. else
  25. self.xp, self.totalLevelXP = C_AzeriteItem.GetAzeriteItemXPInfo(azeriteItemLocation);
  26. self.currentLevel = C_AzeriteItem.GetPowerLevel(azeriteItemLocation);
  27. end
  28. self.xpToNextLevel = self.totalLevelXP - self.xp;
  29. self:SetBarValues(self.xp, 0, self.totalLevelXP);
  30. self:UpdatePointsTooltip();
  31. self:Show();
  32. end
  33. function AzeriteBarMixin:UpdateOverlayFrameText()
  34. if ( self.OverlayFrame.Text:IsShown() ) then
  35. local xp = self.StatusBar:GetAnimatedValue();
  36. local _, totalLevelXP = self.StatusBar:GetMinMaxValues();
  37. self.OverlayFrame.Text:SetFormattedText(AZERITE_POWER_BAR, FormatPercentage(xp / totalLevelXP, true));
  38. end
  39. end
  40. function AzeriteBarMixin:AnimatedValueChangedCallback()
  41. self:UpdateOverlayFrameText();
  42. self:UpdatePointsTooltip();
  43. end
  44. function AzeriteBarMixin:OnLoad()
  45. self:SetBarColor(ARTIFACT_BAR_COLOR:GetRGB());
  46. self.StatusBar:SetOnAnimatedValueChangedCallback(function() self:AnimatedValueChangedCallback(); end)
  47. self.priority = 0;
  48. end
  49. function AzeriteBarMixin:OnEvent(event, ...)
  50. if ( self:IsVisible() ) then
  51. if ( event == "PLAYER_ENTERING_WORLD" or event == "AZERITE_ITEM_EXPERIENCE_CHANGED") then
  52. self:Update();
  53. elseif ( event == "CVAR_UPDATE" ) then
  54. local name, value = ...;
  55. if ( name == "XP_BAR_TEXT" ) then
  56. self:UpdateTextVisibility();
  57. end
  58. elseif ( event == "BAG_UPDATE" ) then
  59. local bagID = ...;
  60. if bagID > NUM_BAG_SLOTS then
  61. self:Update();
  62. end
  63. end
  64. end
  65. end
  66. function AzeriteBarMixin:OnShow()
  67. FrameUtil.RegisterFrameForEvents(self, AZERITE_XP_BAR_EVENTS);
  68. self:UpdateTextVisibility();
  69. end
  70. function AzeriteBarMixin:OnHide()
  71. FrameUtil.UnregisterFrameForEvents(self, AZERITE_XP_BAR_EVENTS);
  72. end
  73. function AzeriteBarMixin:OnEnter()
  74. self:ShowText();
  75. self:UpdateOverlayFrameText();
  76. if self.currentLevel == -1 then
  77. GameTooltip_SetDefaultAnchor(GameTooltip, UIParent);
  78. GameTooltip:SetText(HEART_OF_AZEROTH_MISSING_ERROR, HIGHLIGHT_FONT_COLOR:GetRGB());
  79. else
  80. self:SetupPointsTooltip();
  81. end
  82. end
  83. function AzeriteBarMixin:OnLeave()
  84. self:HideText();
  85. GameTooltip_Hide();
  86. if self.currentLevel ~= -1 then
  87. self:CancelItemLoadCallback();
  88. end
  89. end
  90. function AzeriteBarMixin:CancelItemLoadCallback()
  91. if self.itemDataLoadedCancelFunc then
  92. self.itemDataLoadedCancelFunc();
  93. self.itemDataLoadedCancelFunc = nil;
  94. end
  95. end
  96. function AzeriteBarMixin:SetupPointsTooltip()
  97. local azeriteItemLocation = C_AzeriteItem.FindActiveAzeriteItem();
  98. local azeriteItem = Item:CreateFromItemLocation(azeriteItemLocation);
  99. self.itemDataLoadedCancelFunc = azeriteItem:ContinueWithCancelOnItemLoad(function()
  100. local azeriteItemName = azeriteItem:GetItemName();
  101. GameTooltip_SetDefaultAnchor(GameTooltip, UIParent);
  102. GameTooltip:SetText(AZERITE_POWER_TOOLTIP_TITLE:format(self.currentLevel, self.xpToNextLevel), HIGHLIGHT_FONT_COLOR:GetRGB());
  103. GameTooltip:AddLine(AZERITE_POWER_TOOLTIP_BODY:format(azeriteItemName));
  104. GameTooltip:Show();
  105. end);
  106. end
  107. function AzeriteBarMixin:UpdatePointsTooltip()
  108. if ( GameTooltip:IsOwned(self) ) then
  109. self:SetupPointsTooltip();
  110. end
  111. end