1. local parent, ns = ...
  2. local oUF = ns.oUF or _G.oUF
  3. local Update = function(self, event, unit)
  4. if (unit ~= self.unit) then
  5. return
  6. end
  7. local unit = unit or self.unit
  8. if (UnitIsConnected(unit)) then
  9. self.OfflineIcon:Hide()
  10. else
  11. self.OfflineIcon:Show()
  12. end
  13. end
  14. local Path = function(self, ...)
  15. return (self.OfflineIcon.Override or Update)(self, ...)
  16. end
  17. local ForceUpdate = function(element)
  18. return Path(element.__owner, "ForceUpdate")
  19. end
  20. local Enable = function(self)
  21. local officon = self.OfflineIcon
  22. if (officon) then
  23. officon.__owner = self
  24. officon.ForceUpdate = ForceUpdate
  25. self:RegisterEvent("PARTY_MEMBER_DISABLE", Path)
  26. self:RegisterEvent("PARTY_MEMBER_ENABLE", Path)
  27. self:RegisterEvent("PLAYER_TARGET_CHANGED", Path)
  28. if (officon:IsObjectType("Texture") and not officon:GetTexture()) then
  29. officon:SetTexture("Interface\\CharacterFrame\\Disconnect-Icon")
  30. end
  31. return true
  32. end
  33. end
  34. local Disable = function(self)
  35. local officon = self.OfflineIcon
  36. if (officon) then
  37. self:UnregisterEvent("PARTY_MEMBER_DISABLE", Path)
  38. self:UnregisterEvent("PARTY_MEMBER_ENABLE", Path)
  39. self:UnregisterEvent("PLAYER_TARGET_CHANGED", Path)
  40. end
  41. end
  42. oUF:AddElement("OfflineIcon", Path, Enable, Disable)

oUF_Offline.lua