PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 37ms app.codeStats 0ms

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

http://github.com/Asphyxia/Tukui
Lua | 84 lines | 67 code | 17 blank | 0 comment | 12 complexity | 5365934c049d6be6765fa28d8726ea13 MD5 | raw file
 1local _, ns = ...
 2local oUF = ns.oUF
 3
 4local function Update(self, event, unit)
 5	if(self.unit ~= unit) then return end
 6
 7	local hp = self.HealPrediction
 8	if(hp.PreUpdate) then hp:PreUpdate(unit) end
 9
10	local myIncomingHeal = UnitGetIncomingHeals(unit, 'player') or 0
11	local allIncomingHeal = UnitGetIncomingHeals(unit) or 0
12	local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
13
14	if(health + allIncomingHeal > maxHealth * hp.maxOverflow) then
15		allIncomingHeal = maxHealth * hp.maxOverflow - health
16	end
17
18	if(allIncomingHeal < myIncomingHeal) then
19		myIncomingHeal = allIncomingHeal
20		allIncomingHeal = 0
21	else
22		allIncomingHeal = allIncomingHeal - myIncomingHeal
23	end
24
25	if(hp.myBar) then
26		hp.myBar:SetMinMaxValues(0, maxHealth)
27		hp.myBar:SetValue(myIncomingHeal)
28		hp.myBar:Show()
29	end
30
31	if(hp.otherBar) then
32		hp.otherBar:SetMinMaxValues(0, maxHealth)
33		hp.otherBar:SetValue(allIncomingHeal)
34		hp.otherBar:Show()
35	end
36
37	if(hp.PostUpdate) then
38		return hp:PostUpdate(unit)
39	end
40end
41
42local function Path(self, ...)
43	return (self.HealPrediction.Override or Update) (self, ...)
44end
45
46local ForceUpdate = function(element)
47	return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
48end
49
50local function Enable(self)
51	local hp = self.HealPrediction
52	if(hp) then
53		hp.__owner = self
54		hp.ForceUpdate = ForceUpdate
55
56		self:RegisterEvent('UNIT_HEAL_PREDICTION', Path)
57		self:RegisterEvent('UNIT_MAXHEALTH', Path)
58		self:RegisterEvent('UNIT_HEALTH', Path)
59
60		if(not hp.maxOverflow) then
61			hp.maxOverflow = 1.05
62		end
63
64		if(hp.myBar and not hp.myBar:GetStatusBarTexture()) then
65			hp.myBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
66		end
67		if(hp.otherBar and not hp.otherBar:GetStatusBarTexture()) then
68			hp.otherBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
69		end
70
71		return true
72	end
73end
74
75local function Disable(self)
76	local hp = self.HealPrediction
77	if(hp) then
78		self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path)
79		self:UnregisterEvent('UNIT_MAXHEALTH', Path)
80		self:UnregisterEvent('UNIT_HEALTH', Path)
81	end
82end
83
84oUF:AddElement('HealPrediction', Path, Enable, Disable)