/Tukui/modules/unitframes/core/oUF/elements/druidmana.lua
Lua | 114 lines | 87 code | 22 blank | 5 comment | 17 complexity | 49d7c9f9a47cc39fce90820c0d2a8f43 MD5 | raw file
1-- Druid Mana Bar for Cat and Bear forms 2-- Authors: Califpornia aka Ennie // some code taken from oUF`s EclipseBar element 3if(select(2, UnitClass('player')) ~= 'DRUID') then return end 4 5local _, ns = ... 6local oUF = ns.oUF 7 8local function Update(self, event, unit, powertype) 9 --only the player frame will have this unit enabled 10 --i mainly place this check for UNIT_DISPLAYPOWER and entering a vehicle 11 if(unit ~= 'player' or (powertype and powertype ~= 'MANA')) then return end 12 13 local druidmana = self.DruidMana 14 if(druidmana.PreUpdate) then druidmana:PreUpdate(unit) end 15 16 --check form 17 if(UnitPowerType('player') == SPELL_POWER_MANA) then 18 return druidmana:Hide() 19 else 20 druidmana:Show() 21 end 22 23 local min, max = UnitPower('player', SPELL_POWER_MANA), UnitPowerMax('player', SPELL_POWER_MANA) 24 druidmana:SetMinMaxValues(0, max) 25 druidmana:SetValue(min) 26 27 local r, g, b, t 28 if(druidmana.colorClass) then 29 t = self.colors.class['DRUID'] 30 elseif(druidmana.colorSmooth) then 31 r, g, b = self.ColorGradient(min / max, unpack(druidmana.smoothGradient or self.colors.smooth)) 32 elseif(druidmana.colorPower) then 33 t = self.colors.power['MANA'] 34 end 35 36 if(t) then 37 r, g, b = t[1], t[2], t[3] 38 end 39 40 if(b) then 41 druidmana:SetStatusBarColor(r, g, b) 42 43 local bg = druidmana.bg 44 if(bg) then 45 local mu = bg.multiplier or 1 46 bg:SetVertexColor(r * mu, g * mu, b * mu) 47 end 48 end 49 50 if(druidmana.PostUpdate) then 51 return druidmana:PostUpdate(unit, min, max) 52 end 53end 54 55local function Path(self, ...) 56 return (self.DruidMana.Override or Update) (self, ...) 57end 58 59local function ForceUpdate(element) 60 return Path(element.__owner, 'ForceUpdate', element.__owner.unit) 61end 62 63local OnDruidManaUpdate 64do 65 local UnitPower = UnitPower 66 OnDruidManaUpdate = function(self) 67 local unit = self.__owner.unit 68 local mana = UnitPower(unit, SPELL_POWER_MANA) 69 70 if(mana ~= self.min) then 71 self.min = mana 72 return Path(self.__owner, 'OnDruidManaUpdate', unit) 73 end 74 end 75end 76 77local Enable = function(self, unit) 78 local druidmana = self.DruidMana 79 if(druidmana and unit == 'player') then 80 druidmana.__owner = self 81 druidmana.ForceUpdate = ForceUpdate 82 83 if(druidmana.frequentUpdates) then 84 druidmana:SetScript('OnUpdate', OnDruidManaUpdate) 85 else 86 self:RegisterEvent('UNIT_POWER', Path) 87 end 88 89 self:RegisterEvent('UNIT_DISPLAYPOWER', Path) 90 self:RegisterEvent('UNIT_MAXPOWER', Path) 91 92 if(not druidmana:GetStatusBarTexture()) then 93 druidmana:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]] 94 end 95 96 return true 97 end 98end 99 100local Disable = function(self) 101 local druidmana = self.DruidMana 102 if(druidmana) then 103 if(druidmana:GetScript'OnUpdate') then 104 druidmana:SetScript("OnUpdate", nil) 105 else 106 self:UnregisterEvent('UNIT_POWER', Path) 107 end 108 109 self:UnregisterEvent('UNIT_DISPLAYPOWER', Path) 110 self:UnregisterEvent('UNIT_MAXPOWER', Path) 111 end 112end 113 114oUF:AddElement('DruidMana', Path, Enable, Disable)