PageRenderTime 172ms CodeModel.GetById 80ms app.highlight 3ms RepoModel.GetById 88ms app.codeStats 0ms

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

http://github.com/Asphyxia/Tukui
Lua | 48 lines | 39 code | 9 blank | 0 comment | 5 complexity | 4dfaf523bd86a3d45595b0ec7e29b286 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	if(self.PvP) then
 8		local factionGroup = UnitFactionGroup(unit)
 9		if(UnitIsPVPFreeForAll(unit)) then
10			self.PvP:SetTexture[[Interface\TargetingFrame\UI-PVP-FFA]]
11			self.PvP:Show()
12		elseif(factionGroup and UnitIsPVP(unit)) then
13			self.PvP:SetTexture([[Interface\TargetingFrame\UI-PVP-]]..factionGroup)
14			self.PvP:Show()
15		else
16			self.PvP:Hide()
17		end
18	end
19end
20
21local Path = function(self, ...)
22	return (self.PvP.Override or Update) (self, ...)
23end
24
25local ForceUpdate = function(element)
26	return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
27end
28
29local Enable = function(self)
30	local pvp = self.PvP
31	if(pvp) then
32		pvp.__owner = self
33		pvp.ForceUpdate = ForceUpdate
34
35		self:RegisterEvent("UNIT_FACTION", Path)
36
37		return true
38	end
39end
40
41local Disable = function(self)
42	local pvp = self.PvP
43	if(pvp) then
44		self:UnregisterEvent("UNIT_FACTION", Path)
45	end
46end
47
48oUF:AddElement('PvP', Path, Enable, Disable)