PageRenderTime 92ms CodeModel.GetById 50ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

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

http://github.com/Asphyxia/Tukui
Lua | 59 lines | 46 code | 13 blank | 0 comment | 7 complexity | cc056007a84a335711c08ac954f2a19a MD5 | raw file
 1local parent, ns = ...
 2local oUF = ns.oUF
 3
 4local Update = function(self, event, unit)
 5	if(unit ~= self.unit) then return end
 6
 7	local threat = self.Threat
 8	if(threat.PreUpdate) then threat:PreUpdate(unit) end
 9
10	unit = unit or self.unit
11	local status = UnitThreatSituation(unit)
12
13	if(status and status > 0) then
14		local r, g, b = GetThreatStatusColor(status)
15		threat:SetVertexColor(r, g, b)
16		threat:Show()
17	else
18		threat:Hide()
19	end
20
21	if(threat.PostUpdate) then
22		return threat:PostUpdate(unit, status)
23	end
24end
25
26local Path = function(self, ...)
27	return (self.Threat.Override or Update) (self, ...)
28end
29
30local ForceUpdate = function(element)
31	return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
32end
33
34local Enable = function(self)
35	local threat = self.Threat
36	if(threat) then
37		threat.__owner = self
38		threat.ForceUpdate = ForceUpdate
39
40		self:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", Path)
41		threat:Hide()
42
43		if(threat:IsObjectType"Texture" and not threat:GetTexture()) then
44			threat:SetTexture[[Interface\Minimap\ObjectIcons]]
45			threat:SetTexCoord(1/4, 3/8, 0, 1/4)
46		end
47
48		return true
49	end
50end
51
52local Disable = function(self)
53	local threat = self.Threat
54	if(threat) then
55		self:UnregisterEvent("UNIT_THREAT_SITUATION_UPDATE", Path)
56	end
57end
58
59oUF:AddElement('Threat', Path, Enable, Disable)