PageRenderTime 203ms CodeModel.GetById 101ms app.highlight 2ms RepoModel.GetById 98ms app.codeStats 1ms

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

http://github.com/Asphyxia/Tukui
Lua | 46 lines | 37 code | 9 blank | 0 comment | 4 complexity | 669e285501a93e45a5309b234a89cb99 MD5 | raw file
 1local parent, ns = ...
 2local oUF = ns.oUF
 3
 4local Update = function(self, event)
 5	local unit = self.unit
 6	if((UnitInParty(unit) or UnitInRaid(unit)) and UnitIsPartyLeader(unit)) then
 7		self.Leader:Show()
 8	else
 9		self.Leader:Hide()
10	end
11end
12
13local Path = function(self, ...)
14	return (self.Leader.Override or Update) (self, ...)
15end
16
17local ForceUpdate = function(element)
18	return Path(element.__owner, 'ForceUpdate')
19end
20
21local Enable = function(self)
22	local leader = self.Leader
23	if(leader) then
24		leader.__owner = self
25		leader.ForceUpdate = ForceUpdate
26
27		self:RegisterEvent("PARTY_LEADER_CHANGED", Path)
28		self:RegisterEvent("PARTY_MEMBERS_CHANGED", Path)
29
30		if(leader:IsObjectType"Texture" and not leader:GetTexture()) then
31			leader:SetTexture[[Interface\GroupFrame\UI-Group-LeaderIcon]]
32		end
33
34		return true
35	end
36end
37
38local Disable = function(self)
39	local leader = self.Leader
40	if(leader) then
41		self:UnregisterEvent("PARTY_LEADER_CHANGED", Path)
42		self:UnregisterEvent("PARTY_MEMBERS_CHANGED", Path)
43	end
44end
45
46oUF:AddElement('Leader', Path, Enable, Disable)