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