Skip to content

Instantly share code, notes, and snippets.

@kurapica
Created June 29, 2021 13:44
Show Gist options
  • Save kurapica/ac1ba780b3994ab2b1e623d13d398235 to your computer and use it in GitHub Desktop.
Save kurapica/ac1ba780b3994ab2b1e623d13d398235 to your computer and use it in GitHub Desktop.
Info bar for world of warcraft
Scorpio "InfoBar" ""
_Status = Frame("_Status", UIParent)
_Text = FontString("Text", _Status)
Style[_Status] = {
{
Text = {
drawLayer = "ARTWORK",
fontObject = TextStatusBarTextLarge,
location = { Anchor("CENTER") },
},
location = { Anchor("TOP", 0, - 4) },
size = Size(200, 32),
}
}
-----------------------------------------
-- Script for Info Bar
-----------------------------------------
PERFORMANCEBAR_LOW_LATENCY = 300
PERFORMANCEBAR_MEDIUM_LATENCY = 600
MAX_PLAYER_LEVEL = MAX_PLAYER_LEVEL
XP_TEXT = "|cffffd200XP: +%s|r\n";
EXHAUST_TOOLTIP1 = EXHAUST_TOOLTIP1
EXHAUST_TOOLTIP2 = EXHAUST_TOOLTIP2
EXHAUST_TOOLTIP3 = EXHAUST_TOOLTIP3
EXHAUST_TOOLTIP4 = EXHAUST_TOOLTIP4
MAINMENUBAR_LATENCY_LABEL = MAINMENUBAR_LATENCY_LABEL
MAINMENUBAR_PROTOCOLS_LABEL = MAINMENUBAR_PROTOCOLS_LABEL
UNKNOWN = UNKNOWN
MAINMENUBAR_FPS_LABEL = MAINMENUBAR_FPS_LABEL
MAINMENUBAR_BANDWIDTH_LABEL = MAINMENUBAR_BANDWIDTH_LABEL
MAINMENUBAR_DOWNLOAD_PERCENT_LABEL = MAINMENUBAR_DOWNLOAD_PERCENT_LABEL
CINEMATICS = CINEMATICS
CINEMATIC_DOWNLOAD_FORMAT = CINEMATIC_DOWNLOAD_FORMAT
TOTAL_MEM_MB_ABBR = TOTAL_MEM_MB_ABBR
TOTAL_MEM_KB_ABBR = TOTAL_MEM_KB_ABBR
ADDON_MEM_MB_ABBR = ADDON_MEM_MB_ABBR
ADDON_MEM_KB_ABBR = ADDON_MEM_KB_ABBR
GameTooltip = _G.GameTooltip
NUM_ADDONS_TO_DISPLAY = 20;
topAddOns = {}
for i = 1, NUM_ADDONS_TO_DISPLAY do
topAddOns[i] = { value = 0, name = "" };
end
ipTypes = { "IPv4", "IPv6" }
function UpdateGameTooltip()
local string = "";
local i, j, k = 0, 0, 0;
GameTooltip:SetOwner(_Status, "ANCHOR_NONE")
GameTooltip:ClearAllPoints()
if select(2, _Status:GetCenter()) > GetScreenHeight() / 2 then
GameTooltip:SetPoint("TOP", _Status, "BOTTOM")
else
GameTooltip:SetPoint("BOTTOM", _Status, "TOP")
end
-- Rest xp
local exhaustionThreshold = GetXPExhaustion();
local XPText = format( XP_TEXT, BreakUpLargeNumbers((exhaustionThreshold or 0) / 2));
GameTooltip:SetText(XPText);
-- latency
local bandwidthIn, bandwidthOut, latencyHome, latencyWorld = GetNetStats();
string = format(MAINMENUBAR_LATENCY_LABEL, latencyHome, latencyWorld);
--GameTooltip:AddLine(" ");
GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
GameTooltip:AddLine(" ");
-- protocol types
if GetCVarBool("useIPv6") then
local ipTypeHome, ipTypeWorld = GetNetIpTypes();
string = format(MAINMENUBAR_PROTOCOLS_LABEL, ipTypes[ipTypeHome or 0] or UNKNOWN, ipTypes[ipTypeWorld or 0] or UNKNOWN);
GameTooltip:AddLine(" ");
GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
GameTooltip:AddLine(" ");
end
-- framerate
string = format(MAINMENUBAR_FPS_LABEL, GetFramerate());
GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
GameTooltip:AddLine(" ");
string = format(MAINMENUBAR_BANDWIDTH_LABEL, GetAvailableBandwidth());
GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
GameTooltip:AddLine(" ");
local percent = floor(GetDownloadedPercentage() * 100 + 0.5);
string = format(MAINMENUBAR_DOWNLOAD_PERCENT_LABEL, percent);
GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
-- AddOn mem usage
for i = 1, NUM_ADDONS_TO_DISPLAY, 1 do
topAddOns[i].value = 0;
end
UpdateAddOnMemoryUsage();
UpdateAddOnCPUUsage();
local totalMem = 0;
local totalCpu = 0;
for i = 1, GetNumAddOns(), 1 do
local mem = GetAddOnMemoryUsage(i);
local cpu = GetAddOnCPUUsage(i) or 0;
totalMem = totalMem + mem;
totalCpu = totalCpu + cpu;
for j = 1, NUM_ADDONS_TO_DISPLAY, 1 do
if(mem > topAddOns[j].value) then
for k = NUM_ADDONS_TO_DISPLAY, 1, - 1 do
if(k == j) then
topAddOns[k].cpu = cpu;
topAddOns[k].value = mem;
topAddOns[k].name = GetAddOnInfo(i);
break;
elseif(k ~= 1) then
topAddOns[k].cpu = topAddOns[k - 1].cpu;
topAddOns[k].value = topAddOns[k - 1].value;
topAddOns[k].name = topAddOns[k - 1].name;
end
end
break;
end
end
end
if ( totalMem > 0 ) then
if ( totalMem > 1000 ) then
totalMem = totalMem / 1000;
string = format(TOTAL_MEM_MB_ABBR, totalMem);
else
string = format(TOTAL_MEM_KB_ABBR, totalMem);
end
GameTooltip:AddLine("\n");
GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
local size;
for i = 1, NUM_ADDONS_TO_DISPLAY, 1 do
if ( topAddOns[i].value == 0 ) then
break;
end
size = topAddOns[i].value;
if ( size > 1000 ) then
size = size / 1000;
string = format(ADDON_MEM_MB_ABBR, size, topAddOns[i].name);
else
string = format(ADDON_MEM_KB_ABBR, size, topAddOns[i].name);
end
if totalCpu > 0 then
string = string .. (" [CPU]: %.2f"):format(topAddOns[i].cpu / 1000)
end
GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
end
end
GameTooltip:Show();
end
--------------------
-- Script Handler
--------------------
function _Status:OnEnter()
self.Hover = true
UpdateGameTooltip()
end
function _Status:OnLeave()
self.Hover = false
GameTooltip:Hide()
end
local MapRects = {};
local TempVec2D = CreateVector2D(0, 0);
function GetPlayerMapPos()
local mapid = C_Map.GetBestMapForUnit("player")
if not mapid then return end
local R, P, _ = MapRects[mapid], TempVec2D;
if not R then
R = {};
_, R[1] = C_Map.GetWorldPosFromMapPos(mapid, CreateVector2D(0, 0));
_, R[2] = C_Map.GetWorldPosFromMapPos(mapid, CreateVector2D(1, 1));
R[2]:Subtract(R[1]);
MapRects[mapid] = R;
end
P.x, P.y = UnitPosition('Player');
if not P.x then return nil end
P:Subtract(R[1]);
return (1 / R[2].y) * P.y, (1 / R[2].x) * P.x;
end
Continue(function()
while true do
Delay(2)
-- mail stuff
if HasNewMail() then
mail = "|c00FA58F4new!|r "
else
mail = ""
end
-- date thing
local ticktack = date("%H:%M")
ticktack = "|c00786857" .. ticktack .. "|r"
-- fps crap
local fps = GetFramerate()
fps = "|c00786857" .. floor(fps) .. "|rfps "
-- lag
local _, _, latencyHome, latencyWorld = GetNetStats()
local latency = latencyHome > latencyWorld and latencyHome or latencyWorld
if (latency > PERFORMANCEBAR_MEDIUM_LATENCY) then
latency = "|c00ff0000" .. latency .. "|rms "
elseif (latency > PERFORMANCEBAR_LOW_LATENCY) then
latency = "|c00ffff00" .. latency .. "|rms "
else
latency = "|c0000ff00" .. latency .. "|rms "
end
-- xp stuff
local xp_cur = UnitXP("player")
local xp_max = UnitXPMax("player")
if UnitLevel("player") < MAX_PLAYER_LEVEL then
ep = "|c00786857" .. floor(xp_max - xp_cur) .. "|rxp "
else
ep = ""
end
-- get player x,y
local x, y = GetPlayerMapPos()
x = x or 0
y = y or 0
-- if x and y 0 then boo
if(x == 0 and y == 0) then
coords = "";
else
coords = "(" .. "|c00786857" .. format("%.2d,%.2d" .. "|r) ", x * 100, y * 100)
end
-- Refresh
_Text:SetText(fps .. latency .. ep .. mail .. coords .. ticktack)
if _Status.Hover then
UpdateGameTooltip()
end
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment