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

http://github.com/Asphyxia/Tukui · Lua · 65 lines · 54 code · 11 blank · 0 comment · 21 complexity · 113fde63f388049671ec72ee933187b0 MD5 · raw file

  1. local WoW41 = select(4, GetBuildInfo()) == 40100
  2. if(WoW41) then return end
  3. local parent, ns = ...
  4. local oUF = ns.oUF
  5. local Update = function(self, event, unit, powerType)
  6. if(self.unit ~= unit) then return end
  7. local happ = self.Happiness
  8. if(happ and (powerType == 'HAPPINESS' or not powerType)) then
  9. local happiness = GetPetHappiness()
  10. local _, hunterPet = HasPetUI()
  11. if(not (happiness or hunterPet)) then
  12. return happ:Hide()
  13. end
  14. happ:Show()
  15. if(happiness == 1) then
  16. happ:SetTexCoord(0.375, 0.5625, 0, 0.359375)
  17. elseif(happiness == 2) then
  18. happ:SetTexCoord(0.1875, 0.375, 0, 0.359375)
  19. elseif(happiness == 3) then
  20. happ:SetTexCoord(0, 0.1875, 0, 0.359375)
  21. end
  22. if(happ.PostUpdate) then
  23. return happ:PostUpdate(unit, happiness)
  24. end
  25. end
  26. end
  27. local Path = function(self, ...)
  28. return (self.Happiness.Override or Update) (self, ...)
  29. end
  30. local ForceUpdate = function(element)
  31. return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  32. end
  33. local Enable = function(self)
  34. local happiness = self.Happiness
  35. if(happiness) then
  36. happiness.__owner = self
  37. happiness.ForceUpdate = ForceUpdate
  38. self:RegisterEvent('UNIT_POWER', Path)
  39. if(happiness:IsObjectType"Texture" and not happiness:GetTexture()) then
  40. happiness:SetTexture[[Interface\PetPaperDollFrame\UI-PetHappiness]]
  41. end
  42. return true
  43. end
  44. end
  45. local Disable = function(self)
  46. local happiness = self.Happiness
  47. if(happiness) then
  48. self:UnregisterEvent('UNIT_POWER', Path)
  49. end
  50. end
  51. oUF:AddElement('Happiness', Path, Enable, Disable)