/Tukui/modules/databars/latency.lua

http://github.com/Asphyxia/Tukui · Lua · 56 lines · 47 code · 9 blank · 0 comment · 8 complexity · a592f379ecfe47a0ed1cf17ffe8cb0cc MD5 · raw file

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