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

http://github.com/Asphyxia/Tukui · Lua · 56 lines · 43 code · 13 blank · 0 comment · 14 complexity · 87986a4daee36d7b34e95f2ac52bd9d7 MD5 · raw file

  1. if(select(2, UnitClass('player')) ~= 'WARLOCK') then return end
  2. local parent, ns = ...
  3. local oUF = ns.oUF
  4. local SPELL_POWER_SOUL_SHARDS = SPELL_POWER_SOUL_SHARDS
  5. local SHARD_BAR_NUM_SHARDS = SHARD_BAR_NUM_SHARDS
  6. local Update = function(self, event, unit, powerType)
  7. if(self.unit ~= unit or (powerType and powerType ~= 'SOUL_SHARDS')) then return end
  8. local ss = self.SoulShards
  9. if(ss.PreUpdate) then ss:PreUpdate(unit) end
  10. local num = UnitPower('player', SPELL_POWER_SOUL_SHARDS)
  11. for i = 1, SHARD_BAR_NUM_SHARDS do
  12. if(i <= num) then
  13. ss[i]:SetAlpha(1)
  14. else
  15. ss[i]:SetAlpha(0)
  16. end
  17. end
  18. if(ss.PostUpdate) then
  19. return ss:PostUpdate(unit)
  20. end
  21. end
  22. local Path = function(self, ...)
  23. return (self.SoulShards.Override or Update) (self, ...)
  24. end
  25. local ForceUpdate = function(element)
  26. return Path(element.__owner, 'ForceUpdate', element.__owner.unit, 'SOUL_SHARDS')
  27. end
  28. local function Enable(self)
  29. local ss = self.SoulShards
  30. if(ss) then
  31. ss.__owner = self
  32. ss.ForceUpdate = ForceUpdate
  33. self:RegisterEvent('UNIT_POWER', Path)
  34. return true
  35. end
  36. end
  37. local function Disable(self)
  38. local ss = self.SoulShards
  39. if(ss) then
  40. self:UnregisterEvent('UNIT_POWER', Path)
  41. end
  42. end
  43. oUF:AddElement('SoulShards', Path, Enable, Disable)