From d86fd06639db61203b74f938555b4465d6f45514 Mon Sep 17 00:00:00 2001 From: cx384 Date: Thu, 1 Feb 2024 18:01:37 +0100 Subject: [PATCH] Fix zindex behavior --- src/client/hud.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 6b94e2774..57c0baba9 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -351,12 +351,21 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) std::vector elems; elems.reserve(player->maxHudId()); - // Add builtin minimap if the server doesn't send it. + // Add builtin elements if the server doesn't send them. + // Declared here such that they have the same lifetime as the elems vector HudElement minimap; - if (client->getProtoVersion() < 44 && (player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE)) { - minimap = {HUD_ELEM_MINIMAP, v2f(1, 0), "", v2f(), "", 0 , 0, 0, v2f(-1, 1), - v2f(-10, 10), v3f(), v2s32(256, 256), 0, "", 0}; - elems.push_back(&minimap); + HudElement hotbar; + if (client->getProtoVersion() < 44) { + if (player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE) { + minimap = {HUD_ELEM_MINIMAP, v2f(1, 0), "", v2f(), "", 0 , 0, 0, v2f(-1, 1), + v2f(-10, 10), v3f(), v2s32(256, 256), 0, "", 0}; + elems.push_back(&minimap); + } + if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) { + hotbar = {HUD_ELEM_HOTBAR, v2f(0.5, 1), "", v2f(), "", 0 , 0, 0, v2f(-0.5, -1), + v2f(0, -4), v3f(), v2s32(), 0, "", 0}; + elems.push_back(&hotbar); + } } for (size_t i = 0; i != player->maxHudId(); i++) { @@ -371,13 +380,6 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) elems.insert(it, e); } - // Add builtin hotbar if the server doesn't send it. - if (client->getProtoVersion() < 44 && (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE)) { - HudElement hotbar{HUD_ELEM_HOTBAR, v2f(0.5, 1), "", v2f(), "", 0 , 0, 0, v2f(-0.5, -1), - v2f(0, -4), v3f(), v2s32(), 0, "", 0}; - elems.push_back(&hotbar); - } - for (HudElement *e : elems) { v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),