PageRenderTime 125ms CodeModel.GetById 63ms app.highlight 3ms RepoModel.GetById 57ms app.codeStats 1ms

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

http://github.com/Asphyxia/Tukui
Lua | 56 lines | 43 code | 13 blank | 0 comment | 8 complexity | e14a791d726dd752d06754a697bc356a MD5 | raw file
 1if(select(2, UnitClass('player')) ~= 'PALADIN') then return end
 2
 3local parent, ns = ...
 4local oUF = ns.oUF
 5
 6local SPELL_POWER_HOLY_POWER = SPELL_POWER_HOLY_POWER
 7local MAX_HOLY_POWER = MAX_HOLY_POWER
 8
 9local Update = function(self, event, unit, powerType)
10	if(self.unit ~= unit or (powerType and powerType ~= 'HOLY_POWER')) then return end
11
12	local hp = self.HolyPower
13	if(hp.PreUpdate) then hp:PreUpdate(unit) end
14
15	local num = UnitPower('player', SPELL_POWER_HOLY_POWER)
16	for i = 1, MAX_HOLY_POWER do
17		if(i <= num) then
18			hp[i]:SetAlpha(1)
19		else
20			hp[i]:SetAlpha(0)
21		end
22	end
23
24	if(hp.PostUpdate) then
25		return hp:PostUpdate(unit)
26	end
27end
28
29local Path = function(self, ...)
30	return (self.HolyPower.Override or Update) (self, ...)
31end
32
33local ForceUpdate = function(element)
34	return Path(element.__owner, 'ForceUpdate', element.__owner.unit, 'HOLY_POWER')
35end
36
37local function Enable(self)
38	local hp = self.HolyPower
39	if(hp) then
40		hp.__owner = self
41		hp.ForceUpdate = ForceUpdate
42
43		self:RegisterEvent('UNIT_POWER', Path)
44
45		return true
46	end
47end
48
49local function Disable(self)
50	local hp = self.HolyPower
51	if(hp) then
52		self:UnregisterEvent('UNIT_POWER', Path)
53	end
54end
55
56oUF:AddElement('HolyPower', Path, Enable, Disable)