/Tukui/modules/unitframes/core/oUF/elements/eclipsebar.lua

http://github.com/Asphyxia/Tukui · Lua · 140 lines · 114 code · 25 blank · 1 comment · 30 complexity · 5fb8c5f535f7ced3751ed2ba487a4592 MD5 · raw file

  1. if(select(2, UnitClass('player')) ~= 'DRUID') then return end
  2. local parent, ns = ...
  3. local oUF = ns.oUF
  4. local ECLIPSE_BAR_SOLAR_BUFF_ID = ECLIPSE_BAR_SOLAR_BUFF_ID
  5. local ECLIPSE_BAR_LUNAR_BUFF_ID = ECLIPSE_BAR_LUNAR_BUFF_ID
  6. local SPELL_POWER_ECLIPSE = SPELL_POWER_ECLIPSE
  7. local MOONKIN_FORM = MOONKIN_FORM
  8. local UNIT_POWER = function(self, event, unit, powerType)
  9. if(self.unit ~= unit or (event == 'UNIT_POWER' and powerType ~= 'ECLIPSE')) then return end
  10. local eb = self.EclipseBar
  11. local power = UnitPower('player', SPELL_POWER_ECLIPSE)
  12. local maxPower = UnitPowerMax('player', SPELL_POWER_ECLIPSE)
  13. if(eb.LunarBar) then
  14. eb.LunarBar:SetMinMaxValues(-maxPower, maxPower)
  15. eb.LunarBar:SetValue(power)
  16. end
  17. if(eb.SolarBar) then
  18. eb.SolarBar:SetMinMaxValues(-maxPower, maxPower)
  19. eb.SolarBar:SetValue(power * -1)
  20. end
  21. if(eb.PostUpdatePower) then
  22. return eb:PostUpdatePower(unit)
  23. end
  24. end
  25. local UPDATE_VISIBILITY = function(self, event)
  26. local eb = self.EclipseBar
  27. -- check form/mastery
  28. local showBar
  29. local form = GetShapeshiftFormID()
  30. if(not form) then
  31. local ptt = GetPrimaryTalentTree()
  32. if(ptt and ptt == 1) then -- player has balance spec
  33. showBar = true
  34. end
  35. elseif(form == MOONKIN_FORM) then
  36. showBar = true
  37. end
  38. if(showBar) then
  39. eb:Show()
  40. else
  41. eb:Hide()
  42. end
  43. if(eb.PostUpdateVisibility) then
  44. return eb:PostUpdateVisibility(self.unit)
  45. end
  46. end
  47. local UNIT_AURA = function(self, event, unit)
  48. if(self.unit ~= unit) then return end
  49. local i = 1
  50. local hasSolarEclipse, hasLunarEclipse
  51. repeat
  52. local _, _, _, _, _, _, _, _, _, _, spellID = UnitAura(unit, i, 'HELPFUL')
  53. if(spellID == ECLIPSE_BAR_SOLAR_BUFF_ID) then
  54. hasSolarEclipse = true
  55. elseif(spellID == ECLIPSE_BAR_LUNAR_BUFF_ID) then
  56. hasLunarEclipse = true
  57. end
  58. i = i + 1
  59. until not spellID
  60. local eb = self.EclipseBar
  61. eb.hasSolarEclipse = hasSolarEclipse
  62. eb.hasLunarEclipse = hasLunarEclipse
  63. if(eb.PostUnitAura) then
  64. return eb:PostUnitAura(unit)
  65. end
  66. end
  67. local ECLIPSE_DIRECTION_CHANGE = function(self, event, isLunar)
  68. local eb = self.EclipseBar
  69. eb.directionIsLunar = isLunar
  70. if(eb.PostDirectionChange) then
  71. return eb:PostDirectionChange(self.unit)
  72. end
  73. end
  74. local Update = function(self, ...)
  75. UNIT_POWER(self, ...)
  76. UNIT_AURA(self, ...)
  77. return UPDATE_VISIBILITY(self, ...)
  78. end
  79. local ForceUpdate = function(element)
  80. return Update(element.__owner, 'ForceUpdate', element.__owner.unit, 'ECLIPSE')
  81. end
  82. local function Enable(self)
  83. local eb = self.EclipseBar
  84. if(eb) then
  85. eb.__owner = self
  86. eb.ForceUpdate = ForceUpdate
  87. if(eb.LunarBar and not eb.LunarBar:GetStatusBarTexture()) then
  88. eb.LunarBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
  89. end
  90. if(eb.SolarBar and not eb.SolarBar:GetStatusBarTexture()) then
  91. eb.SolarBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
  92. end
  93. self:RegisterEvent('ECLIPSE_DIRECTION_CHANGE', ECLIPSE_DIRECTION_CHANGE)
  94. self:RegisterEvent('PLAYER_TALENT_UPDATE', UPDATE_VISIBILITY)
  95. self:RegisterEvent('UNIT_AURA', UNIT_AURA)
  96. self:RegisterEvent('UNIT_POWER', UNIT_POWER)
  97. self:RegisterEvent('UPDATE_SHAPESHIFT_FORM', UPDATE_VISIBILITY)
  98. return true
  99. end
  100. end
  101. local function Disable(self)
  102. local eb = self.EclipseBar
  103. if(eb) then
  104. self:UnregisterEvent('ECLIPSE_DIRECTION_CHANGE', ECLIPSE_DIRECTION_CHANGE)
  105. self:UnregisterEvent('PLAYER_TALENT_UPDATE', UPDATE_VISIBILITY)
  106. self:UnregisterEvent('UNIT_AURA', UNIT_AURA)
  107. self:UnregisterEvent('UNIT_POWER', UNIT_POWER)
  108. self:UnregisterEvent('UPDATE_SHAPESHIFT_FORM', UPDATE_VISIBILITY)
  109. end
  110. end
  111. oUF:AddElement('EclipseBar', Update, Enable, Disable)