PageRenderTime 22ms CodeModel.GetById 18ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://github.com/Asphyxia/Tukui
Lua | 62 lines | 50 code | 11 blank | 1 comment | 14 complexity | 3a20fc79cda20a71662be59494dc6f6e MD5 | raw file
 1local parent, ns = ...
 2local oUF = ns.oUF
 3
 4local _FRAMES = {}
 5local OnRangeFrame
 6
 7local UnitInRange, UnitIsConnected = UnitInRange, UnitIsConnected
 8
 9-- updating of range.
10local timer = 0
11local OnRangeUpdate = function(self, elapsed)
12	timer = timer + elapsed
13
14	if(timer >= .20) then
15		for _, object in next, _FRAMES do
16			if(object:IsShown()) then
17				local range = object.Range
18				if(UnitIsConnected(object.unit) and not UnitInRange(object.unit)) then
19					if(object:GetAlpha() == range.insideAlpha) then
20						object:SetAlpha(range.outsideAlpha)
21					end
22				elseif(object:GetAlpha() ~= range.insideAlpha) then
23					object:SetAlpha(range.insideAlpha)
24				end
25			end
26		end
27
28		timer = 0
29	end
30end
31
32local Enable = function(self)
33	local range = self.Range
34	if(range and range.insideAlpha and range.outsideAlpha) then
35		table.insert(_FRAMES, self)
36
37		if(not OnRangeFrame) then
38			OnRangeFrame = CreateFrame"Frame"
39			OnRangeFrame:SetScript("OnUpdate", OnRangeUpdate)
40		end
41
42		OnRangeFrame:Show()
43	end
44end
45
46local Disable = function(self)
47	local range = self.Range
48	if(range) then
49		for k, frame in next, _FRAMES do
50			if(frame == self) then
51				table.remove(_FRAMES, k)
52				break
53			end
54		end
55
56		if(#_FRAMES == 0) then
57			OnRangeFrame:Hide()
58		end
59	end
60end
61
62oUF:AddElement('Range', nil, Enable, Disable)