PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

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

http://github.com/Asphyxia/Tukui
Lua | 53 lines | 42 code | 11 blank | 0 comment | 9 complexity | a93e7baf2acf9b53c01a5bcb10e5ec44 MD5 | raw file
 1local parent, ns = ...
 2local oUF = ns.oUF
 3
 4local Update = function(self, event)
 5	local lfdrole = self.LFDRole
 6
 7	local role = UnitGroupRolesAssigned(self.unit)
 8
 9	if(role == 'TANK' or role == 'HEALER' or role == 'DAMAGER') then
10		lfdrole:SetTexCoord(GetTexCoordsForRoleSmallCircle(role))
11		lfdrole:Show()
12	else
13		lfdrole:Hide()
14	end
15end
16
17local Path = function(self, ...)
18	return (self.LFDRole.Override or Update) (self, ...)
19end
20
21local ForceUpdate = function(element)
22	return Path(element.__owner, 'ForceUpdate')
23end
24
25local Enable = function(self)
26	local lfdrole = self.LFDRole
27	if(lfdrole) then
28		lfdrole.__owner = self
29		lfdrole.ForceUpdate = ForceUpdate
30
31		if(self.unit == "player") then
32			self:RegisterEvent("PLAYER_ROLES_ASSIGNED", Path)
33		else
34			self:RegisterEvent("PARTY_MEMBERS_CHANGED", Path)
35		end
36
37		if(lfdrole:IsObjectType"Texture" and not lfdrole:GetTexture()) then
38			lfdrole:SetTexture[[Interface\LFGFrame\UI-LFG-ICON-PORTRAITROLES]]
39		end
40
41		return true
42	end
43end
44
45local Disable = function(self)
46	local lfdrole = self.LFDRole
47	if(lfdrole) then
48		self:UnregisterEvent("PLAYER_ROLES_ASSIGNED", Path)
49		self:UnregisterEvent("PARTY_MEMBERS_CHANGED", Path)
50	end
51end
52
53oUF:AddElement('LFDRole', Path, Enable, Disable)