PageRenderTime 71ms CodeModel.GetById 50ms app.highlight 3ms RepoModel.GetById 17ms app.codeStats 0ms

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

http://github.com/Asphyxia/Tukui
Lua | 51 lines | 40 code | 11 blank | 0 comment | 5 complexity | b8d81f660606aa374c769b6c04e3c06a MD5 | raw file
 1local parent, ns = ...
 2local oUF = ns.oUF
 3
 4local GetRaidTargetIndex = GetRaidTargetIndex
 5local SetRaidTargetIconTexture = SetRaidTargetIconTexture
 6
 7local Update = function(self, event)
 8	local index = GetRaidTargetIndex(self.unit)
 9	local icon = self.RaidIcon
10
11	if(index) then
12		SetRaidTargetIconTexture(icon, index)
13		icon:Show()
14	else
15		icon:Hide()
16	end
17end
18
19local Path = function(self, ...)
20	return (self.RaidIcon.Override or Update) (self, ...)
21end
22
23local ForceUpdate = function(element)
24	if(not element.__owner.unit) then return end
25	return Path(element.__owner, 'ForceUpdate')
26end
27
28local Enable = function(self)
29	local ricon = self.RaidIcon
30	if(ricon) then
31		ricon.__owner = self
32		ricon.ForceUpdate = ForceUpdate
33
34		self:RegisterEvent("RAID_TARGET_UPDATE", Path)
35
36		if(ricon:IsObjectType"Texture" and not ricon:GetTexture()) then
37			ricon:SetTexture[[Interface\TargetingFrame\UI-RaidTargetingIcons]]
38		end
39
40		return true
41	end
42end
43
44local Disable = function(self)
45	local ricon = self.RaidIcon
46	if(ricon) then
47		self:UnregisterEvent("RAID_TARGET_UPDATE", Path)
48	end
49end
50
51oUF:AddElement('RaidIcon', Path, Enable, Disable)