PageRenderTime 173ms CodeModel.GetById 70ms app.highlight 4ms RepoModel.GetById 97ms app.codeStats 0ms

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

http://github.com/Asphyxia/Tukui
Lua | 76 lines | 56 code | 14 blank | 6 comment | 10 complexity | 2b7c45a55274f9c2914cd2eb076638c8 MD5 | raw file
 1local parent, ns = ...
 2local oUF = ns.oUF
 3
 4local Update = function(self, event, unit)
 5	if(not unit or not UnitIsUnit(self.unit, unit)) then return end
 6
 7	local portrait = self.Portrait
 8	if(portrait.PreUpdate) then portrait:PreUpdate(unit) end
 9
10	if(portrait:IsObjectType'Model') then
11		local guid = UnitGUID(unit)
12		if(not UnitExists(unit) or not UnitIsConnected(unit) or not UnitIsVisible(unit)) then
13			portrait:SetModelScale(4.25)
14			portrait:SetPosition(0, 0, -1.5)
15			portrait:SetModel"Interface\\Buttons\\talktomequestionmark.mdx"
16		elseif(portrait.guid ~= guid or event == 'UNIT_MODEL_CHANGED') then
17			portrait:SetUnit(unit)
18			portrait:SetCamera(0)
19
20			portrait.guid = guid
21		else
22			portrait:SetCamera(0)
23		end
24	else
25		SetPortraitTexture(portrait, unit)
26	end
27
28	if(portrait.PostUpdate) then
29		return portrait:PostUpdate(unit)
30	end
31end
32
33local Path = function(self, ...)
34	return (self.Portrait.Override or Update) (self, ...)
35end
36
37local ForceUpdate = function(element)
38	return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
39end
40
41local Enable = function(self, unit)
42	local portrait = self.Portrait
43	if(portrait) then
44		portrait.__owner = self
45		portrait.ForceUpdate = ForceUpdate
46
47		self:RegisterEvent("UNIT_PORTRAIT_UPDATE", Path)
48		self:RegisterEvent("UNIT_MODEL_CHANGED", Path)
49		self:RegisterEvent('UNIT_CONNECTION', Path)
50
51		-- The quest log uses PARTY_MEMBER_{ENABLE,DISABLE} to handle updating of
52		-- party members overlapping quests. This will probably be enough to handle
53		-- model updating.
54		--
55		-- DISABLE isn't used as it fires when we most likely don't have the
56		-- information we want.
57		if(unit == 'party') then
58			self:RegisterEvent('PARTY_MEMBER_ENABLE', Path)
59		end
60
61		return true
62	end
63end
64
65local Disable = function(self)
66	local portrait = self.Portrait
67	if(portrait) then
68		self:UnregisterEvent("UNIT_PORTRAIT_UPDATE", Path)
69		self:UnregisterEvent("UNIT_MODEL_CHANGED", Path)
70		self:UnregisterEvent('PARTY_MEMBER_ENABLE', Path)
71		self:UnregisterEvent('UNIT_CONNECTION', Path)
72	end
73end
74
75oUF:AddElement('Portrait', Path, Enable, Disable)
76