2022-03-05 10:38:34 -05:00
|
|
|
local mphud = luiglobals.require("LUI.mp_hud.MPHud")
|
2022-03-05 12:47:49 -05:00
|
|
|
local barheight = 16
|
|
|
|
local textheight = 13
|
|
|
|
local textoffsety = barheight / 2 - textheight / 2
|
2022-03-05 10:38:34 -05:00
|
|
|
|
|
|
|
function createinfobar()
|
2022-03-05 12:47:49 -05:00
|
|
|
local infobar = LUI.UIElement.new({
|
|
|
|
left = luiglobals.GameX.IsHardcoreMode() and 160 or 228,
|
|
|
|
top = luiglobals.GameX.IsHardcoreMode() and 5 or 9,
|
|
|
|
height = barheight,
|
|
|
|
width = 70,
|
|
|
|
leftAnchor = true,
|
|
|
|
topAnchor = true
|
|
|
|
})
|
|
|
|
|
|
|
|
infobar:registerAnimationState("hud_on", {
|
|
|
|
alpha = 1
|
|
|
|
})
|
|
|
|
|
|
|
|
infobar:registerAnimationState("hud_off", {
|
|
|
|
alpha = 0
|
|
|
|
})
|
|
|
|
|
|
|
|
return infobar
|
2022-03-05 10:38:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function populateinfobar(infobar)
|
2022-03-05 12:47:49 -05:00
|
|
|
elementoffset = 0
|
|
|
|
|
|
|
|
if (Engine.GetDvarBool("cg_infobar_fps")) then
|
|
|
|
infobar:addElement(infoelement({
|
|
|
|
label = "FPS: ",
|
|
|
|
getvalue = function()
|
|
|
|
return game:getfps()
|
|
|
|
end,
|
|
|
|
width = 70,
|
|
|
|
interval = 100
|
|
|
|
}))
|
|
|
|
end
|
|
|
|
|
|
|
|
if (Engine.GetDvarBool("cg_infobar_ping")) then
|
|
|
|
infobar:addElement(infoelement({
|
|
|
|
label = "Latency: ",
|
|
|
|
getvalue = function()
|
|
|
|
return game:getping() .. " ms"
|
|
|
|
end,
|
|
|
|
width = 115,
|
|
|
|
interval = 100
|
|
|
|
}))
|
|
|
|
end
|
2022-03-05 10:38:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function infoelement(data)
|
2022-03-05 12:47:49 -05:00
|
|
|
local container = LUI.UIElement.new({
|
|
|
|
bottomAnchor = true,
|
|
|
|
leftAnchor = true,
|
|
|
|
topAnchor = true,
|
|
|
|
width = data.width,
|
|
|
|
left = elementoffset
|
|
|
|
})
|
|
|
|
|
|
|
|
elementoffset = elementoffset + data.width + 10
|
|
|
|
|
|
|
|
local background = LUI.UIImage.new({
|
|
|
|
bottomAnchor = true,
|
|
|
|
leftAnchor = true,
|
|
|
|
topAnchor = true,
|
|
|
|
rightAnchor = true,
|
|
|
|
material = luiglobals.RegisterMaterial("white"),
|
|
|
|
color = luiglobals.Colors.black,
|
|
|
|
alpha = 0.5
|
|
|
|
})
|
|
|
|
|
|
|
|
local labelfont = CoD.TextSettings.FontBold110
|
|
|
|
|
|
|
|
local label = LUI.UIText.new({
|
|
|
|
left = 5,
|
|
|
|
top = textoffsety,
|
|
|
|
font = labelfont.Font,
|
|
|
|
height = textheight,
|
|
|
|
leftAnchor = true,
|
|
|
|
topAnchor = true,
|
|
|
|
color = {
|
|
|
|
r = 0.8,
|
|
|
|
g = 0.8,
|
|
|
|
b = 0.8,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
label:setText(data.label)
|
|
|
|
|
|
|
|
local _, _, left = luiglobals.GetTextDimensions(data.label, labelfont.Font, textheight)
|
|
|
|
local value = LUI.UIText.new({
|
|
|
|
left = left + 5,
|
|
|
|
top = textoffsety,
|
|
|
|
height = textheight,
|
|
|
|
leftAnchor = true,
|
|
|
|
topAnchor = true,
|
|
|
|
color = {
|
|
|
|
r = 0.6,
|
|
|
|
g = 0.6,
|
|
|
|
b = 0.6,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
value:addElement(LUI.UITimer.new(data.interval, "update"))
|
|
|
|
value:setText(data.getvalue())
|
|
|
|
value:addEventHandler("update", function()
|
|
|
|
value:setText(data.getvalue())
|
|
|
|
end)
|
|
|
|
|
|
|
|
container:addElement(background)
|
|
|
|
container:addElement(label)
|
|
|
|
container:addElement(value)
|
|
|
|
|
|
|
|
return container
|
2022-03-05 10:38:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local updatehudvisibility = mphud.updateHudVisibility
|
|
|
|
mphud.updateHudVisibility = function(a1, a2)
|
2022-03-05 12:47:49 -05:00
|
|
|
updatehudvisibility(a1, a2)
|
2022-03-05 10:38:34 -05:00
|
|
|
|
2022-03-05 12:47:49 -05:00
|
|
|
local root = Engine.GetLuiRoot()
|
|
|
|
local menus = root:AnyActiveMenusInStack()
|
|
|
|
local infobar = root.infobar
|
2022-03-05 10:38:34 -05:00
|
|
|
|
2022-03-05 12:47:49 -05:00
|
|
|
if (not infobar) then
|
|
|
|
return
|
|
|
|
end
|
2022-03-05 12:36:56 -05:00
|
|
|
|
2022-03-05 12:47:49 -05:00
|
|
|
if (menus) then
|
|
|
|
infobar:animateToState("hud_off")
|
|
|
|
else
|
|
|
|
infobar:animateToState("hud_on")
|
|
|
|
end
|
2022-03-05 10:38:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
LUI.onmenuopen("mp_hud", function(hud)
|
2022-03-05 12:47:49 -05:00
|
|
|
if (Engine.InFrontend()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local infobar = createinfobar()
|
|
|
|
local root = Engine.GetLuiRoot()
|
|
|
|
root.infobar = infobar
|
|
|
|
populateinfobar(infobar)
|
|
|
|
|
|
|
|
root:registerEventHandler("update_hud_infobar_settings", function()
|
|
|
|
infobar:removeAllChildren()
|
|
|
|
populateinfobar(infobar)
|
|
|
|
end)
|
|
|
|
|
|
|
|
root:processEvent({
|
|
|
|
name = "update_hud_infobar_settings"
|
|
|
|
})
|
|
|
|
|
|
|
|
hud.static:addElement(infobar)
|
2022-03-05 10:38:34 -05:00
|
|
|
end)
|