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

/Tukui/modules/databars/latency.lua

http://github.com/Asphyxia/Tukui
Lua | 56 lines | 47 code | 9 blank | 0 comment | 5 complexity | a592f379ecfe47a0ed1cf17ffe8cb0cc MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2
 3local ADDON_NAME, ns = ...
 4local oUF = ns.oUF or oUF
 5
 6ns._Objects = {}
 7ns._Headers = {}
 8
 9if not C["databars"].latency or C["databars"].latency == 0 then return end
10local barNum = C["databars"].latency
11
12T.databars[barNum]:Show()
13
14local Stat = CreateFrame("Frame", nil, T.databars[barNum])
15Stat:EnableMouse(true)
16Stat:SetFrameStrata("BACKGROUND")
17Stat:SetFrameLevel(4)
18
19local StatusBar = T.databars[barNum].statusbar
20local Text = T.databars[barNum].text
21
22local int = 1
23local function Update(self, t)
24	int = int - t
25	if int < 0 then
26		local ms = select(3, GetNetStats())
27		Text:SetText(ms..T.datacolor.." MS")
28		StatusBar:SetMinMaxValues(0, 400)
29		StatusBar:SetValue(ms)
30		self:SetAllPoints(T.databars[barNum])	
31		if ms > 75 then
32			StatusBar:SetStatusBarColor( 30 / 255, 1, 30 / 255 , .8 )
33		elseif ms > 35 then
34			StatusBar:SetStatusBarColor( 1, 180 / 255, 0, .8 )
35		else
36			StatusBar:SetStatusBarColor( 1, 75 / 255, 75 / 255, 0.5, .8 )
37		end
38		int = 1
39	end	
40end
41Stat:SetScript("OnUpdate", Update)
42Update(Stat, 10)
43
44Stat:SetScript("OnEnter", function(self)
45	if not InCombatLockdown() then
46		local xoff, yoff = T.DataBarTooltipAnchor(barNum)
47		GameTooltip:SetOwner(T.databars[barNum], "ANCHOR_BOTTOMRIGHT", xoff, yoff)
48	
49		local _, _, latencyHome, latencyWorld = GetNetStats()
50		local latency = format(MAINMENUBAR_LATENCY_LABEL, latencyHome, latencyWorld)
51		GameTooltip:ClearLines()
52		GameTooltip:AddLine(latency)
53		GameTooltip:Show()
54	end
55end)	
56Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)