PageRenderTime 121ms CodeModel.GetById 61ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

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

http://github.com/Asphyxia/Tukui
Lua | 54 lines | 44 code | 10 blank | 0 comment | 17 complexity | 33197eb3870b24c5bf18d20ccb1ed972 MD5 | raw file
 1local parent, ns = ...
 2local oUF = ns.oUF
 3
 4local GetComboPoints = GetComboPoints
 5local MAX_COMBO_POINTS = MAX_COMBO_POINTS
 6
 7local Update = function(self, event, unit)
 8	if(unit == 'pet') then return end
 9
10	local cp
11	if(UnitHasVehicleUI'player') then
12		cp = GetComboPoints('vehicle', 'target')
13	else
14		cp = GetComboPoints('player', 'target')
15	end
16	self.CPoints:SetText(cp)
17	if cp == 0 then self.CPoints:SetText("") end
18	if cp == 1 then self.CPoints:SetTextColor(.9,0,.2) end
19	if cp == 2 then self.CPoints:SetTextColor(217/255, 65/255, .2) end
20	if cp == 3 then self.CPoints:SetTextColor(159/255, 130/255, .2) end
21	if cp == 4 then self.CPoints:SetTextColor(39/255, 200/255, .2) end
22	if cp == 5 then self.CPoints:SetTextColor(0,1,0) end
23end
24
25local Path = function(self, ...)
26	return (self.CPoints.Override or Update) (self, ...)
27end
28
29local ForceUpdate = function(element)
30	return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
31end
32
33local Enable = function(self)
34	local cpoints = self.CPoints
35	if(cpoints) then
36		cpoints.__owner = self
37		cpoints.ForceUpdate = ForceUpdate
38
39		self:RegisterEvent('UNIT_COMBO_POINTS', Path)
40		self:RegisterEvent('PLAYER_TARGET_CHANGED', Path)
41
42		return true
43	end
44end
45
46local Disable = function(self)
47	local cpoints = self.CPoints
48	if(cpoints) then
49		self:UnregisterEvent('UNIT_COMBO_POINTS', Path)
50		self:UnregisterEvent('PLAYER_TARGET_CHANGED', Path)
51	end
52end
53
54oUF:AddElement('CPoints', Path, Enable, Disable)