AlternatePowerBar.lua

AlternatePowerBar.lua (9.0.2.36037; unchanged since 9.0.1.35522)
  1. ADDITIONAL_POWER_BAR_NAME = "MANA";
  2. ADDITIONAL_POWER_BAR_INDEX = 0;
  3. function AlternatePowerBar_OnLoad(self)
  4. self.textLockable = 1;
  5. self.cvar = "statusText";
  6. self.cvarLabel = "STATUS_TEXT_PLAYER";
  7. self.capNumericDisplay = true;
  8. AlternatePowerBar_Initialize(self);
  9. TextStatusBar_Initialize(self);
  10. end
  11. function AlternatePowerBar_Initialize(self)
  12. if ( not self.powerName ) then
  13. self.powerName = ADDITIONAL_POWER_BAR_NAME;
  14. self.powerIndex = ADDITIONAL_POWER_BAR_INDEX;
  15. end
  16. self:RegisterEvent("UNIT_POWER_UPDATE");
  17. self:RegisterEvent("UNIT_MAXPOWER");
  18. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  19. self:RegisterEvent("UNIT_DISPLAYPOWER");
  20. self:RegisterEvent("UPDATE_VEHICLE_ACTIONBAR");
  21. self:RegisterEvent("UNIT_EXITED_VEHICLE");
  22. SetTextStatusBarText(self, _G[self:GetName().."Text"])
  23. local info = PowerBarColor[self.powerName];
  24. self:SetStatusBarColor(info.r, info.g, info.b);
  25. end
  26. function AlternatePowerBar_OnEvent(self, event, ...)
  27. if ( event == "UNIT_DISPLAYPOWER" or event == "UPDATE_VEHICLE_ACTIONBAR" or event == "UNIT_EXITED_VEHICLE" ) then
  28. AlternatePowerBar_UpdatePowerType(self);
  29. elseif ( event=="PLAYER_ENTERING_WORLD" ) then
  30. AlternatePowerBar_UpdateMaxValues(self);
  31. AlternatePowerBar_UpdatePowerType(self);
  32. elseif( (event == "UNIT_MAXPOWER") ) then
  33. local unitTag = ...;
  34. local parent = self:GetParent();
  35. if unitTag == parent.unit then
  36. AlternatePowerBar_UpdateMaxValues(self);
  37. end
  38. elseif ( self:IsShown() ) then
  39. if ( (event == "UNIT_POWER_UPDATE") ) then
  40. local unitTag = ...;
  41. local parent = self:GetParent();
  42. if unitTag == parent.unit then
  43. AlternatePowerBar_UpdateValue(self);
  44. end
  45. end
  46. end
  47. end
  48. function AlternatePowerBar_OnUpdate(self, elapsed)
  49. AlternatePowerBar_UpdateValue(self);
  50. TextStatusBar_UpdateTextString(self);
  51. end
  52. function AlternatePowerBar_UpdateValue(self)
  53. local currentPower = UnitPower(self:GetParent().unit,self.powerIndex);
  54. self:SetValue(currentPower);
  55. self.value = currentPower
  56. end
  57. function AlternatePowerBar_UpdateMaxValues(self)
  58. local maxPower = UnitPowerMax(self:GetParent().unit,self.powerIndex);
  59. self:SetMinMaxValues(0, maxPower);
  60. end
  61. ALT_MANA_BAR_PAIR_DISPLAY_INFO = {
  62. DRUID = {
  63. [Enum.PowerType.LunarPower] = true,
  64. },
  65. PRIEST = {
  66. [Enum.PowerType.Insanity] = true,
  67. },
  68. SHAMAN = {
  69. [Enum.PowerType.Maelstrom] = true,
  70. },
  71. };
  72. function AlternatePowerBar_ShouldDisplayPower(self)
  73. if UnitHasVehiclePlayerFrameUI("player") then
  74. return false;
  75. end
  76. if UnitPowerMax(self:GetParent().unit, self.powerIndex) == 0 then
  77. return false;
  78. end
  79. local _, class = UnitClass(self:GetParent().unit);
  80. if ALT_MANA_BAR_PAIR_DISPLAY_INFO[class] then
  81. local powerType = UnitPowerType(self:GetParent().unit);
  82. return ALT_MANA_BAR_PAIR_DISPLAY_INFO[class][powerType];
  83. end
  84. return false;
  85. end
  86. function AlternatePowerBar_UpdatePowerType(self)
  87. if AlternatePowerBar_ShouldDisplayPower(self) then
  88. self.pauseUpdates = false;
  89. AlternatePowerBar_UpdateValue(self);
  90. self:Show();
  91. else
  92. self.pauseUpdates = true;
  93. self:Hide();
  94. end
  95. end