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

http://github.com/Asphyxia/Tukui · Lua · 59 lines · 49 code · 10 blank · 0 comment · 11 complexity · cc056007a84a335711c08ac954f2a19a MD5 · raw file

  1. local parent, ns = ...
  2. local oUF = ns.oUF
  3. local Update = function(self, event, unit)
  4. if(unit ~= self.unit) then return end
  5. local threat = self.Threat
  6. if(threat.PreUpdate) then threat:PreUpdate(unit) end
  7. unit = unit or self.unit
  8. local status = UnitThreatSituation(unit)
  9. if(status and status > 0) then
  10. local r, g, b = GetThreatStatusColor(status)
  11. threat:SetVertexColor(r, g, b)
  12. threat:Show()
  13. else
  14. threat:Hide()
  15. end
  16. if(threat.PostUpdate) then
  17. return threat:PostUpdate(unit, status)
  18. end
  19. end
  20. local Path = function(self, ...)
  21. return (self.Threat.Override or Update) (self, ...)
  22. end
  23. local ForceUpdate = function(element)
  24. return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  25. end
  26. local Enable = function(self)
  27. local threat = self.Threat
  28. if(threat) then
  29. threat.__owner = self
  30. threat.ForceUpdate = ForceUpdate
  31. self:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", Path)
  32. threat:Hide()
  33. if(threat:IsObjectType"Texture" and not threat:GetTexture()) then
  34. threat:SetTexture[[Interface\Minimap\ObjectIcons]]
  35. threat:SetTexCoord(1/4, 3/8, 0, 1/4)
  36. end
  37. return true
  38. end
  39. end
  40. local Disable = function(self)
  41. local threat = self.Threat
  42. if(threat) then
  43. self:UnregisterEvent("UNIT_THREAT_SITUATION_UPDATE", Path)
  44. end
  45. end
  46. oUF:AddElement('Threat', Path, Enable, Disable)