diff --git a/LagBar.lua b/LagBar.lua
index 7044e86..9cbae50 100644
--- a/LagBar.lua
+++ b/LagBar.lua
@@ -1,68 +1,121 @@
--LagBar by Xruptor
-local LagBar = CreateFrame("frame", "LagBar", UIParent)
-LagBar:SetScript('OnEvent', function(self, event, ...)
- if self[event] then
- self[event](self, event, ...)
- end
-end)
+local f = CreateFrame("frame","LagBar",UIParent)
+f:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
local debugf = tekDebug and tekDebug:GetFrame("LagBar")
local function Debug(...)
if debugf then debugf:AddMessage(string.join(", ", tostringall(...))) end
end
-if IsLoggedIn() then LagBar:PLAYER_LOGIN() else LagBar:RegisterEvent('PLAYER_LOGIN') end
+local MAX_INTERVAL = 1
+local UPDATE_INTERVAL = 0
-function LagBar:PLAYER_LOGIN()
- LagBar:Enable()
- self:UnregisterEvent("PLAYER_LOGIN")
- self.PLAYER_LOGIN = nil
-end
+----------------------
+-- Color Functions --
+----------------------
-LagBar.version = GetAddOnMetadata("LagBar", "Version")
-LagBar.PL_Lock = false
-
-LagBar.LOW_LATENCY = 300
-LagBar.MEDIUM_LATENCY = 600
-LagBar.MAX_INTERVAL = 1
-LagBar.UPDATE_INTERVAL = 0
+local function LagBar_GetThresholdPercentage(quality, ...)
+ local n = select('#', ...)
+ if n <= 1 then
+ return LagBar_GetThresholdPercentage(quality, 0, ... or 1)
+ end
-function LagBar:Enable()
+ local worst = ...
+ local best = select(n, ...)
- if not LagBar_DB then
- LagBar_DB = {}
- LagBar_DB.x = 0
- LagBar_DB.y = 0
- LagBar_DB.locked = false
- LagBar_DB.bgShown = true
- LagBar_DB.scale = 1
+ if worst == best and quality == worst then
+ return 0.5
end
- --lets do a toggle for world ping
- if LagBar_DB and LagBar_DB.worldping == nil then
- LagBar_DB.worldping = true
+
+ if worst <= best then
+ if quality <= worst then
+ return 0
+ elseif quality >= best then
+ return 1
+ end
+ local last = worst
+ for i = 2, n-1 do
+ local value = select(i, ...)
+ if quality <= value then
+ return ((i-2) + (quality - last) / (value - last)) / (n-1)
+ end
+ last = value
+ end
+
+ local value = select(n, ...)
+ return ((n-2) + (quality - last) / (value - last)) / (n-1)
+ else
+ if quality >= worst then
+ return 0
+ elseif quality <= best then
+ return 1
+ end
+ local last = worst
+ for i = 2, n-1 do
+ local value = select(i, ...)
+ if quality >= value then
+ return ((i-2) + (quality - last) / (value - last)) / (n-1)
+ end
+ last = value
+ end
+
+ local value = select(n, ...)
+ return ((n-2) + (quality - last) / (value - last)) / (n-1)
end
- --lets do a toggle for improved display
- if LagBar_DB and LagBar_DB.impdisplay == nil then
- LagBar_DB.impdisplay = true
+end
+
+local function LagBar_GetThresholdColor(quality, ...)
+
+ local inf = 1/0
+
+ if quality ~= quality or quality == inf or quality == -inf then
+ return 1, 1, 1
end
- --lets check for scale
- if LagBar_DB.scale == nil then
- LagBar_DB.scale = 1
+
+ local percent = LagBar_GetThresholdPercentage(quality, ...)
+
+ if percent <= 0 then
+ return 1, 0, 0
+ elseif percent <= 0.5 then
+ return 1, percent*2, 0
+ elseif percent >= 1 then
+ return 0, 1, 0
+ else
+ return 2 - percent*2, 1, 0
end
+end
+
+local function LagBar_GetThresholdHexColor(quality, ...)
+ local r, g, b = LagBar_GetThresholdColor(quality, ...)
+ return string.format("%02x%02x%02x", r*255, g*255, b*255)
+end
+
- LagBar:DrawGUI()
- LagBar:MoveFrame()
+----------------------
+-- Enable --
+----------------------
+
+function f:PLAYER_LOGIN()
+
+ if not LagBar_DB then LagBar_DB = {} end
+
+ if LagBar_DB.bgShown == nil then LagBar_DB.bgShown = 1 end
+ if LagBar_DB.worldping == nil then LagBar_DB.worldping = true end
+ if LagBar_DB.impdisplay == nil then LagBar_DB.impdisplay = true end
+ if LagBar_DB.scale == nil then LagBar_DB.scale = 1 end
+
+ self:DrawGUI()
+ self:RestoreLayout("LagBar")
SLASH_LAGBAR1 = "/lagbar";
SlashCmdList["LAGBAR"] = LagBar_SlashCommand;
+
+ local ver = GetAddOnMetadata("LagBar","Version") or '1.0'
+ DEFAULT_CHAT_FRAME:AddMessage(string.format("|cFF99CC33%s|r [v|cFFDF2B2B%s|r] Loaded", "LagBar", ver or "1.0"))
-end
-
-function LagBar:OnEvent(event, arg1, arg2, arg3, arg4, ...)
- if event == "ADDON_LOADED" and arg1 == "LagBar" then
- LagBar:Enable();
- end
+ self:UnregisterEvent("PLAYER_LOGIN")
+ self.PLAYER_LOGIN = nil
end
function LagBar_SlashCommand(cmd)
@@ -72,8 +125,7 @@ function LagBar_SlashCommand(cmd)
if a and a ~= "" then
if c and c:lower() == "reset" then
DEFAULT_CHAT_FRAME:AddMessage("LagBar: Frame position has been reset!");
- LagBarFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
-
+ f:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
return nil;
elseif c and c:lower() == "bg" then
LagBar:BackgroundToggle();
@@ -91,7 +143,7 @@ function LagBar_SlashCommand(cmd)
local scalenum = strsub(cmd, b+2)
if scalenum and scalenum ~= "" and tonumber(scalenum) then
LagBar_DB.scale = tonumber(scalenum)
- LagBarFrame:SetScale(tonumber(scalenum))
+ f:SetScale(tonumber(scalenum))
DEFAULT_CHAT_FRAME:AddMessage("LagBar: scale has been set to ["..tonumber(scalenum).."]")
return true
end
@@ -99,6 +151,7 @@ function LagBar_SlashCommand(cmd)
end
end
DEFAULT_CHAT_FRAME:AddMessage("LagBar");
+ DEFAULT_CHAT_FRAME:AddMessage("To move the LagBar window, hold down SHIFT then drag to a new position.");
DEFAULT_CHAT_FRAME:AddMessage("/lagbar reset - resets the frame position");
DEFAULT_CHAT_FRAME:AddMessage("/lagbar bg - toggles the background on/off");
DEFAULT_CHAT_FRAME:AddMessage("/lagbar worldping - toggles world ping display on/off");
@@ -106,91 +159,58 @@ function LagBar_SlashCommand(cmd)
DEFAULT_CHAT_FRAME:AddMessage("/lagbar scale # - Set the scale of the LagBar frame. Use small numbers like 0.5, 0.2, 1, 1.1, 1.5, etc..")
end
-function LagBar:MoveFrame()
-
- if LagBar.PL_Lock then return end
+function f:DrawGUI()
- LagBar.PL_Lock = true
+ f:SetWidth(30)
+ f:SetHeight(25)
+ f:SetMovable(true)
+ f:SetClampedToScreen(true)
- LagBarFrame:ClearAllPoints();
- LagBarFrame:SetPoint("CENTER", UIParent, LagBar_DB.x and "BOTTOMLEFT" or "BOTTOM", LagBar_DB.x or 0, LagBar_DB.y or 221);
- LagBarFrame:Show();
-
- LagBar.PL_Lock = false
+ f:SetScale(LagBar_DB.scale)
-end
-
-function LagBar:DrawGUI()
-
- --don't repeat
- if LagBarFrame then
- return
+ if LagBar_DB.bgShown == 1 then
+ f:SetBackdrop( {
+ bgFile = "Interface\\TutorialFrame\\TutorialFrameBackground";
+ edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border";
+ tile = true; tileSize = 32; edgeSize = 16;
+ insets = { left = 5; right = 5; top = 5; bottom = 5; };
+ } );
+ f:SetBackdropBorderColor(0.5, 0.5, 0.5);
+ f:SetBackdropColor(0.5, 0.5, 0.5, 0.6)
+ else
+ f:SetBackdrop(nil)
end
- --frames cannot have onclick handlers
-
- lbFrame = CreateFrame("Frame", "LagBarFrame", UIParent, "GameTooltipTemplate");
- lbFrame:SetPoint("CENTER", UIParent, LagBar_DB.x and "BOTTOMLEFT" or "BOTTOM", LagBar_DB.x or 0, LagBar_DB.y or 221);
- lbFrame:EnableMouse(true);
- lbFrame:SetToplevel(true);
- lbFrame:SetMovable(true);
- lbFrame:SetFrameStrata("LOW");
- lbFrame:SetHeight(25);
-
- --set to a small size to update size automaticall on first FPS grab
- LagBarFrame:SetWidth(30)
-
- --set the saved scale
- LagBarFrame:SetScale(LagBar_DB.scale)
+ f:EnableMouse(true)
- if LagBar_DB.bgShown then
- local backdrop_header = {bgFile = "Interface\\TutorialFrame\\TutorialFrameBackground",
- edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile=1, tileSize=16, edgeSize = 16,
- insets = {left = 5, right = 5, top = 5, bottom = 5}};
-
- lbFrame:SetBackdrop(backdrop_header);
- lbFrame:SetBackdropBorderColor(0.5, 0.5, 0.5);
- lbFrame:SetBackdropColor(0.5, 0.5, 0.5, 0.6)
- else
- lbFrame:SetBackdrop(nil);
- end
-
- lbFrame:RegisterForDrag("LeftButton")
- lbFrame.text = lbFrame:CreateFontString("$parentText", "ARTWORK", "GameFontNormalSmall");
- lbFrame.text:SetPoint("CENTER", lbFrame, "CENTER", 0, 0);
- lbFrame.text:Show();
+ local g = f:CreateFontString("$parentText", "ARTWORK", "GameFontNormalSmall")
+ g:SetJustifyH("LEFT")
+ g:SetPoint("CENTER",0,0)
+ g:SetText("")
+
+ f:SetScript("OnMouseDown",function()
+ if (IsShiftKeyDown()) then
+ self.isMoving = true
+ self:StartMoving();
+ end
+ end)
+ f:SetScript("OnMouseUp",function()
+ if( self.isMoving ) then
+ self.isMoving = nil
+ self:StopMovingOrSizing()
+
+ f:SaveLayout(self:GetName());
+
+ end
+ end)
+
+ f:SetScript("OnUpdate", function(self, arg1)
- lbFrame:SetScript("OnUpdate", function(self, arg1)
-
- if (LagBar.UPDATE_INTERVAL > 0) then
- LagBar.UPDATE_INTERVAL = LagBar.UPDATE_INTERVAL - arg1;
+ if (UPDATE_INTERVAL > 0) then
+ UPDATE_INTERVAL = UPDATE_INTERVAL - arg1
else
- LagBar.UPDATE_INTERVAL = LagBar.MAX_INTERVAL;
-
- --local bandwidthIn, bandwidthOut, latency = GetNetStats();
- --if (latency > LagBar_MEDIUM_LATENCY) then
- -- LagBar_Text:SetTextColor(1, 0, 0);
- --elseif (latency > LagBar_LOW_LATENCY) then
- -- LagBar_Text:SetTextColor(1, 1, 0);
- --else
- -- LagBar_Text:SetTextColor(0, 1, 0);
- --end
- --if (latency > 9999) then
- -- LagBar_Text:SetText("Ping: HIGH");
- --else
- -- LagBar_Text:SetText("Ping: "..latency.." ms");
- --end
-
- --ORIGINAL CODE
- -- local framerate = floor(GetFramerate() + 0.5)
- -- local framerate_text = format("|cff%s%d|r fps", LagBar_GetThresholdHexColor(framerate / 60), framerate)
-
- -- local latency = select(3, GetNetStats())
- -- local latency_text = format("|cff%s%d|r ms", LagBar_GetThresholdHexColor(latency, 1000, 500, 250, 100, 0), latency)
-
- -- LagBarFrameText:SetText(framerate_text.." | "..latency_text);
-
+ UPDATE_INTERVAL = MAX_INTERVAL;
--thanks to comix1234 on wowinterface.com for the update.
local framerate = floor(GetFramerate() + 0.5)
@@ -205,92 +225,108 @@ function LagBar:DrawGUI()
--change text according to worldping
if LagBar_DB.worldping then
if LagBar_DB.impdisplay then
- LagBarFrameText:SetText(framerate_text.." | |cFF99CC33H:|r"..latency_text.." | |cFF99CC33W:|r"..latency_text_server)
+ g:SetText(framerate_text.." | |cFF99CC33H:|r"..latency_text.." | |cFF99CC33W:|r"..latency_text_server)
else
- LagBarFrameText:SetText(framerate_text.." | "..latency_text.." | "..latency_text_server)
+ g:SetText(framerate_text.." | "..latency_text.." | "..latency_text_server)
end
else
- LagBarFrameText:SetText(framerate_text.." | "..latency_text)
+ g:SetText(framerate_text.." | "..latency_text)
end
--check for overlapping text (JUST IN CASE)
- if LagBarFrameText:GetStringWidth() > LagBarFrame:GetWidth() then
- LagBarFrame:SetWidth(LagBarFrameText:GetStringWidth() + 20)
- elseif (LagBarFrame:GetWidth() - LagBarFrameText:GetStringWidth()) > 41 then
- LagBarFrame:SetWidth(LagBarFrameText:GetStringWidth() + 41)
+ if g:GetStringWidth() > f:GetWidth() then
+ f:SetWidth(g:GetStringWidth() + 20)
+ elseif (f:GetWidth() - g:GetStringWidth()) > 41 then
+ f:SetWidth(g:GetStringWidth() + 41)
end
end
end)
+
+ f:Show()
+end
- lbFrame:SetScript("OnMouseDown", function(frame, button)
-
- if not LagBar_DB.locked and button ~= "RightButton" then
- frame.isMoving = true
- frame:StartMoving();
- end
-
- end)
-
- lbFrame:SetScript("OnMouseUp", function(frame, button)
-
- if not LagBar_DB.locked and button ~= "RightButton" then
- if( frame.isMoving ) then
+function f:SaveLayout(frame)
+ if type(frame) ~= "string" then return end
+ if not _G[frame] then return end
+ if not LagBar_DB then LagBar_DB = {} end
+
+ local opt = LagBar_DB[frame] or nil
+
+ if not opt then
+ LagBar_DB[frame] = {
+ ["point"] = "CENTER",
+ ["relativePoint"] = "CENTER",
+ ["xOfs"] = 0,
+ ["yOfs"] = 0,
+ }
+ opt = LagBar_DB[frame]
+ return
+ end
- frame.isMoving = nil
- frame:StopMovingOrSizing()
+ local point, relativeTo, relativePoint, xOfs, yOfs = _G[frame]:GetPoint()
+ opt.point = point
+ opt.relativePoint = relativePoint
+ opt.xOfs = xOfs
+ opt.yOfs = yOfs
+end
- LagBar_DB.x, LagBar_DB.y = frame:GetCenter()
- end
-
- elseif button == "RightButton" then
-
- if LagBar_DB.locked then
- LagBar_DB.locked = false
- DEFAULT_CHAT_FRAME:AddMessage("LagBar: Unlocked");
- else
- LagBar_DB.locked = true
- DEFAULT_CHAT_FRAME:AddMessage("LagBar: Locked");
- end
- end
+function f:RestoreLayout(frame)
+ if type(frame) ~= "string" then return end
+ if not _G[frame] then return end
+ if not LagBar_DB then LagBar_DB = {} end
+
+ local opt = LagBar_DB[frame] or nil
+
+ if not opt then
+ LagBar_DB[frame] = {
+ ["point"] = "CENTER",
+ ["relativePoint"] = "CENTER",
+ ["xOfs"] = 0,
+ ["yOfs"] = 0,
+ }
+ opt = LagBar_DB[frame]
+ end
- end)
-
+ _G[frame]:ClearAllPoints()
+ _G[frame]:SetPoint(opt.point, UIParent, opt.relativePoint, opt.xOfs, opt.yOfs)
end
-function LagBar:BackgroundToggle()
-
- if not LagBar_DB.bgShown then
- LagBar_DB.bgShown = true;
+function f:BackgroundToggle()
+ if not LagBar_DB then LagBar_DB = {} end
+ if LagBar_DB.bgShown == nil then LagBar_DB.bgShown = 1 end
+
+ if LagBar_DB.bgShown == 0 then
+ LagBar_DB.bgShown = 1;
DEFAULT_CHAT_FRAME:AddMessage("LagBar: Background Shown");
- elseif LagBar_DB.bgShown then
- LagBar_DB.bgShown = false;
+ elseif LagBar_DB.bgShown == 1 then
+ LagBar_DB.bgShown = 0;
DEFAULT_CHAT_FRAME:AddMessage("LagBar: Background Hidden");
else
- LagBar_DB.bgShown = true;
+ LagBar_DB.bgShown = 1
DEFAULT_CHAT_FRAME:AddMessage("LagBar: Background Shown");
end
--now change background
- if LagBar_DB.bgShown and LagBarFrame then
- local backdrop_header = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
- edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile=1, tileSize=16, edgeSize = 16,
- insets = {left = 5, right = 5, top = 5, bottom = 5}};
-
-
- LagBarFrame:SetBackdrop(backdrop_header);
- LagBarFrame:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
- LagBarFrame:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
-
- elseif LagBarFrame then
- LagBarFrame:SetBackdrop(nil)
+ if LagBar_DB.bgShown == 1 then
+ f:SetBackdrop( {
+ bgFile = "Interface\\TutorialFrame\\TutorialFrameBackground";
+ edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border";
+ tile = true; tileSize = 32; edgeSize = 16;
+ insets = { left = 5; right = 5; top = 5; bottom = 5; };
+ } );
+ f:SetBackdropBorderColor(0.5, 0.5, 0.5);
+ f:SetBackdropColor(0.5, 0.5, 0.5, 0.6)
+ else
+ f:SetBackdrop(nil)
end
end
-function LagBar:WorldPingToggle()
-
+function f:WorldPingToggle()
+ if not LagBar_DB then LagBar_DB = {} end
+
if not LagBar_DB.worldping then
LagBar_DB.worldping = true
DEFAULT_CHAT_FRAME:AddMessage("LagBar: World ping is now displayed")
@@ -304,8 +340,9 @@ function LagBar:WorldPingToggle()
end
-function LagBar:ImpDisplayToggle()
-
+function f:ImpDisplayToggle()
+ if not LagBar_DB then LagBar_DB = {} end
+
if not LagBar_DB.impdisplay then
LagBar_DB.impdisplay = true
DEFAULT_CHAT_FRAME:AddMessage("LagBar: Improved World Ping Display On")
@@ -319,79 +356,4 @@ function LagBar:ImpDisplayToggle()
end
-function LagBar_GetThresholdHexColor(quality, ...)
- local r, g, b = LagBar_GetThresholdColor(quality, ...)
- return string.format("%02x%02x%02x", r*255, g*255, b*255)
-end
-
-function LagBar_GetThresholdColor(quality, ...)
-
- local inf = 1/0
-
- if quality ~= quality or quality == inf or quality == -inf then
- return 1, 1, 1
- end
-
- local percent = LagBar_GetThresholdPercentage(quality, ...)
-
- if percent <= 0 then
- return 1, 0, 0
- elseif percent <= 0.5 then
- return 1, percent*2, 0
- elseif percent >= 1 then
- return 0, 1, 0
- else
- return 2 - percent*2, 1, 0
- end
-end
-
-function LagBar_GetThresholdPercentage(quality, ...)
- local n = select('#', ...)
- if n <= 1 then
- return LagBar_GetThresholdPercentage(quality, 0, ... or 1)
- end
-
- local worst = ...
- local best = select(n, ...)
-
- if worst == best and quality == worst then
- return 0.5
- end
-
- if worst <= best then
- if quality <= worst then
- return 0
- elseif quality >= best then
- return 1
- end
- local last = worst
- for i = 2, n-1 do
- local value = select(i, ...)
- if quality <= value then
- return ((i-2) + (quality - last) / (value - last)) / (n-1)
- end
- last = value
- end
-
- local value = select(n, ...)
- return ((n-2) + (quality - last) / (value - last)) / (n-1)
- else
- if quality >= worst then
- return 0
- elseif quality <= best then
- return 1
- end
- local last = worst
- for i = 2, n-1 do
- local value = select(i, ...)
- if quality >= value then
- return ((i-2) + (quality - last) / (value - last)) / (n-1)
- end
- last = value
- end
-
- local value = select(n, ...)
- return ((n-2) + (quality - last) / (value - last)) / (n-1)
- end
-end
-
+if IsLoggedIn() then f:PLAYER_LOGIN() else f:RegisterEvent("PLAYER_LOGIN") end
diff --git a/LagBar.toc b/LagBar.toc
index 38754ae..c05ab0c 100644
--- a/LagBar.toc
+++ b/LagBar.toc
@@ -1,7 +1,7 @@
-## Interface: 70100
+## Interface: 80000
## Title: LagBar
## Author: Xruptor
-## Version: 3.6
+## Version: 4.0
## Notes: Displays a simple bar with some Latency Information.
## OptionalDeps: tekDebug
## SavedVariables: LagBar_DB