PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 1ms

/Tukui/modules/unitframes/plugins/oUF_ClassIcons/oUF_ClassIcons.lua

http://github.com/Asphyxia/Tukui
Lua | 47 lines | 36 code | 10 blank | 1 comment | 3 complexity | b93beb8f4eb5c6ebb1b2a00076080e29 MD5 | raw file
 1local _, ns = ...
 2local oUF = ns.oUF or oUF
 3
 4local Update = function(self, event)
 5	local _, class = UnitClass(self.unit)
 6	local icon = self.ClassIcon
 7  
 8	if(class) then
 9		local left, right, top, bottom = unpack(CLASS_BUTTONS[class])
10		-- zoom class icon
11		left = left + (right - left) * 0.09
12		right = right - (right - left) * 0.09
13
14		top = top + (bottom - top) * 0.09
15		bottom = bottom - (bottom - top) * 0.09
16	
17		icon:SetTexCoord(left, right, top, bottom)
18		icon:Show()
19	else
20		icon:Hide()
21	end
22end
23
24local Enable = function(self)
25	local cicon = self.ClassIcon
26
27	if(cicon) then
28		self:RegisterEvent("PARTY_MEMBERS_CHANGED", Update)
29		self:RegisterEvent("PLAYER_TARGET_CHANGED", Update)
30		self:RegisterEvent("ARENA_OPPONENT_UPDATE", Update)
31
32		cicon:SetTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes")
33		
34		return true
35	end
36end
37
38local Disable = function(self)
39	local ricon = self.ClassIcon
40	if(ricon) then
41		self:UnregisterEvent("ARENA_OPPONENT_UPDATE", Update)
42		self:UnregisterEvent("PARTY_MEMBERS_CHANGED", Update)
43		self:UnregisterEvent("PLAYER_TARGET_CHANGED", Update)
44	end
45end
46
47oUF:AddElement('ClassIcon', Update, Enable, Disable)