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

http://github.com/Asphyxia/Tukui · Lua · 76 lines · 56 code · 14 blank · 6 comment · 17 complexity · 2b7c45a55274f9c2914cd2eb076638c8 MD5 · raw file

  1. local parent, ns = ...
  2. local oUF = ns.oUF
  3. local Update = function(self, event, unit)
  4. if(not unit or not UnitIsUnit(self.unit, unit)) then return end
  5. local portrait = self.Portrait
  6. if(portrait.PreUpdate) then portrait:PreUpdate(unit) end
  7. if(portrait:IsObjectType'Model') then
  8. local guid = UnitGUID(unit)
  9. if(not UnitExists(unit) or not UnitIsConnected(unit) or not UnitIsVisible(unit)) then
  10. portrait:SetModelScale(4.25)
  11. portrait:SetPosition(0, 0, -1.5)
  12. portrait:SetModel"Interface\\Buttons\\talktomequestionmark.mdx"
  13. elseif(portrait.guid ~= guid or event == 'UNIT_MODEL_CHANGED') then
  14. portrait:SetUnit(unit)
  15. portrait:SetCamera(0)
  16. portrait.guid = guid
  17. else
  18. portrait:SetCamera(0)
  19. end
  20. else
  21. SetPortraitTexture(portrait, unit)
  22. end
  23. if(portrait.PostUpdate) then
  24. return portrait:PostUpdate(unit)
  25. end
  26. end
  27. local Path = function(self, ...)
  28. return (self.Portrait.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, unit)
  34. local portrait = self.Portrait
  35. if(portrait) then
  36. portrait.__owner = self
  37. portrait.ForceUpdate = ForceUpdate
  38. self:RegisterEvent("UNIT_PORTRAIT_UPDATE", Path)
  39. self:RegisterEvent("UNIT_MODEL_CHANGED", Path)
  40. self:RegisterEvent('UNIT_CONNECTION', Path)
  41. -- The quest log uses PARTY_MEMBER_{ENABLE,DISABLE} to handle updating of
  42. -- party members overlapping quests. This will probably be enough to handle
  43. -- model updating.
  44. --
  45. -- DISABLE isn't used as it fires when we most likely don't have the
  46. -- information we want.
  47. if(unit == 'party') then
  48. self:RegisterEvent('PARTY_MEMBER_ENABLE', Path)
  49. end
  50. return true
  51. end
  52. end
  53. local Disable = function(self)
  54. local portrait = self.Portrait
  55. if(portrait) then
  56. self:UnregisterEvent("UNIT_PORTRAIT_UPDATE", Path)
  57. self:UnregisterEvent("UNIT_MODEL_CHANGED", Path)
  58. self:UnregisterEvent('PARTY_MEMBER_ENABLE', Path)
  59. self:UnregisterEvent('UNIT_CONNECTION', Path)
  60. end
  61. end
  62. oUF:AddElement('Portrait', Path, Enable, Disable)