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

http://github.com/Asphyxia/Tukui · Lua · 54 lines · 44 code · 10 blank · 0 comment · 18 complexity · 33197eb3870b24c5bf18d20ccb1ed972 MD5 · raw file

  1. local parent, ns = ...
  2. local oUF = ns.oUF
  3. local GetComboPoints = GetComboPoints
  4. local MAX_COMBO_POINTS = MAX_COMBO_POINTS
  5. local Update = function(self, event, unit)
  6. if(unit == 'pet') then return end
  7. local cp
  8. if(UnitHasVehicleUI'player') then
  9. cp = GetComboPoints('vehicle', 'target')
  10. else
  11. cp = GetComboPoints('player', 'target')
  12. end
  13. self.CPoints:SetText(cp)
  14. if cp == 0 then self.CPoints:SetText("") end
  15. if cp == 1 then self.CPoints:SetTextColor(.9,0,.2) end
  16. if cp == 2 then self.CPoints:SetTextColor(217/255, 65/255, .2) end
  17. if cp == 3 then self.CPoints:SetTextColor(159/255, 130/255, .2) end
  18. if cp == 4 then self.CPoints:SetTextColor(39/255, 200/255, .2) end
  19. if cp == 5 then self.CPoints:SetTextColor(0,1,0) end
  20. end
  21. local Path = function(self, ...)
  22. return (self.CPoints.Override or Update) (self, ...)
  23. end
  24. local ForceUpdate = function(element)
  25. return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  26. end
  27. local Enable = function(self)
  28. local cpoints = self.CPoints
  29. if(cpoints) then
  30. cpoints.__owner = self
  31. cpoints.ForceUpdate = ForceUpdate
  32. self:RegisterEvent('UNIT_COMBO_POINTS', Path)
  33. self:RegisterEvent('PLAYER_TARGET_CHANGED', Path)
  34. return true
  35. end
  36. end
  37. local Disable = function(self)
  38. local cpoints = self.CPoints
  39. if(cpoints) then
  40. self:UnregisterEvent('UNIT_COMBO_POINTS', Path)
  41. self:UnregisterEvent('PLAYER_TARGET_CHANGED', Path)
  42. end
  43. end
  44. oUF:AddElement('CPoints', Path, Enable, Disable)