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

http://github.com/Asphyxia/Tukui · Lua · 48 lines · 46 code · 2 blank · 0 comment · 4 complexity · 4dfaf523bd86a3d45595b0ec7e29b286 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. if(self.PvP) then
  6. local factionGroup = UnitFactionGroup(unit)
  7. if(UnitIsPVPFreeForAll(unit)) then
  8. self.PvP:SetTexture[[Interface\TargetingFrame\UI-PVP-FFA]]
  9. self.PvP:Show()
  10. elseif(factionGroup and UnitIsPVP(unit)) then
  11. self.PvP:SetTexture([[Interface\TargetingFrame\UI-PVP-]]..factionGroup)
  12. self.PvP:Show()
  13. else
  14. self.PvP:Hide()
  15. end
  16. end
  17. end
  18. local Path = function(self, ...)
  19. return (self.PvP.Override or Update) (self, ...)
  20. end
  21. local ForceUpdate = function(element)
  22. return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  23. end
  24. local Enable = function(self)
  25. local pvp = self.PvP
  26. if(pvp) then
  27. pvp.__owner = self
  28. pvp.ForceUpdate = ForceUpdate
  29. self:RegisterEvent("UNIT_FACTION", Path)
  30. return true
  31. end
  32. end
  33. local Disable = function(self)
  34. local pvp = self.PvP
  35. if(pvp) then
  36. self:UnregisterEvent("UNIT_FACTION", Path)
  37. end
  38. end
  39. oUF:AddElement('PvP', Path, Enable, Disable)