Update hud.lua

This commit is contained in:
Federico Cecchetto 2022-06-02 17:07:43 +02:00
parent 7ed826d244
commit a8a63efbee

View File

@ -5,8 +5,26 @@ local textoffsety = barheight / 2 - textheight / 2
function createinfobar()
local infobar = LUI.UIElement.new({
left = GameX.IsHardcoreMode() and 0 or 213,
top = GameX.IsHardcoreMode() and 0 or -6,
left = 213,
top = -6,
height = barheight,
width = 70,
leftAnchor = true,
topAnchor = true
})
infobar:registerAnimationState("minimap_on", {
left = 213,
top = -6,
height = barheight,
width = 70,
leftAnchor = true,
topAnchor = true
})
infobar:registerAnimationState("minimap_off", {
left = 0,
top = 0,
height = barheight,
width = 70,
leftAnchor = true,
@ -24,6 +42,37 @@ function createinfobar()
return infobar
end
function updateinfobarvisibility()
local root = Engine.GetLuiRoot()
local menus = root:AnyActiveMenusInStack()
local infobar = root.infobar
if (not infobar) then
return
end
if (menus or Game.InKillCam()) then
infobar:animateToState("hud_off")
else
infobar:animateToState("hud_on")
end
local validstates = {
"hud_on",
"active",
"nosignal",
"scrambled"
}
infobar:animateToState("minimap_off")
for i = 1, #validstates do
if (validstates[i] == root.hud.minimap.current_state) then
infobar:animateToState("minimap_on")
break
end
end
end
function populateinfobar(infobar)
elementoffset = 0
@ -48,6 +97,8 @@ function populateinfobar(infobar)
interval = 100
}))
end
updateinfobarvisibility()
end
function infoelement(data)
@ -120,20 +171,7 @@ end
local updatehudvisibility = mphud.updateHudVisibility
mphud.updateHudVisibility = function(a1, a2)
updatehudvisibility(a1, a2)
local root = Engine.GetLuiRoot()
local menus = root:AnyActiveMenusInStack()
local infobar = root.infobar
if (not infobar) then
return
end
if (menus) then
infobar:animateToState("hud_off")
else
infobar:animateToState("hud_on")
end
updateinfobarvisibility()
end
LUI.onmenuopen("mp_hud", function(hud)
@ -144,6 +182,7 @@ LUI.onmenuopen("mp_hud", function(hud)
local infobar = createinfobar()
local root = Engine.GetLuiRoot()
root.infobar = infobar
root.hud = hud
populateinfobar(infobar)
root:registerEventHandler("update_hud_infobar_settings", function()
@ -157,4 +196,3 @@ LUI.onmenuopen("mp_hud", function(hud)
hud.static.scalable:addElement(infobar)
end)