/Tukui/modules/unitframes/core/oUF/elements/soulshards.lua
Lua | 56 lines | 43 code | 13 blank | 0 comment | 8 complexity | 87986a4daee36d7b34e95f2ac52bd9d7 MD5 | raw file
1if(select(2, UnitClass('player')) ~= 'WARLOCK') then return end 2 3local parent, ns = ... 4local oUF = ns.oUF 5 6local SPELL_POWER_SOUL_SHARDS = SPELL_POWER_SOUL_SHARDS 7local SHARD_BAR_NUM_SHARDS = SHARD_BAR_NUM_SHARDS 8 9local Update = function(self, event, unit, powerType) 10 if(self.unit ~= unit or (powerType and powerType ~= 'SOUL_SHARDS')) then return end 11 12 local ss = self.SoulShards 13 if(ss.PreUpdate) then ss:PreUpdate(unit) end 14 15 local num = UnitPower('player', SPELL_POWER_SOUL_SHARDS) 16 for i = 1, SHARD_BAR_NUM_SHARDS do 17 if(i <= num) then 18 ss[i]:SetAlpha(1) 19 else 20 ss[i]:SetAlpha(0) 21 end 22 end 23 24 if(ss.PostUpdate) then 25 return ss:PostUpdate(unit) 26 end 27end 28 29local Path = function(self, ...) 30 return (self.SoulShards.Override or Update) (self, ...) 31end 32 33local ForceUpdate = function(element) 34 return Path(element.__owner, 'ForceUpdate', element.__owner.unit, 'SOUL_SHARDS') 35end 36 37local function Enable(self) 38 local ss = self.SoulShards 39 if(ss) then 40 ss.__owner = self 41 ss.ForceUpdate = ForceUpdate 42 43 self:RegisterEvent('UNIT_POWER', Path) 44 45 return true 46 end 47end 48 49local function Disable(self) 50 local ss = self.SoulShards 51 if(ss) then 52 self:UnregisterEvent('UNIT_POWER', Path) 53 end 54end 55 56oUF:AddElement('SoulShards', Path, Enable, Disable)