From cf7fda00831372d981415f9a830513b2b28fdf25 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Mon, 4 Nov 2019 09:30:02 +0100 Subject: Add z-index management to HUD --- src/client/clientevent.h | 1 + src/client/game.cpp | 5 +++++ src/client/hud.cpp | 14 ++++++++++++++ 3 files changed, 20 insertions(+) (limited to 'src/client') diff --git a/src/client/clientevent.h b/src/client/clientevent.h index 2a44717ce..69e8838b4 100644 --- a/src/client/clientevent.h +++ b/src/client/clientevent.h @@ -131,6 +131,7 @@ struct ClientEvent v2f *offset; v3f *world_pos; v2s32 *size; + s16 z_index; } hudadd; struct { diff --git a/src/client/game.cpp b/src/client/game.cpp index 59654e892..e3e0e1150 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2650,6 +2650,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam) e->offset = *event->hudadd.offset; e->world_pos = *event->hudadd.world_pos; e->size = *event->hudadd.size; + e->z_index = event->hudadd.z_index; hud_server_to_client[server_id] = player->addHud(e); delete event->hudadd.pos; @@ -2728,6 +2729,10 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca case HUD_STAT_SIZE: e->size = *event->hudchange.v2s32data; break; + + case HUD_STAT_Z_INDEX: + e->z_index = event->hudchange.data; + break; } delete event->hudchange.v3fdata; diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 304a3ab16..e78130dd4 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -283,11 +283,25 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) { u32 text_height = g_fontengine->getTextHeight(); irr::gui::IGUIFont* font = g_fontengine->getFont(); + + // Reorder elements by z_index + std::vector ids; + for (size_t i = 0; i != player->maxHudId(); i++) { HudElement *e = player->getHud(i); if (!e) continue; + auto it = ids.begin(); + while (it != ids.end() && player->getHud(*it)->z_index <= e->z_index) + ++it; + + ids.insert(it, i); + } + + for (size_t i : ids) { + HudElement *e = player->getHud(i); + v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5), floor(e->pos.Y * (float) m_screensize.Y + 0.5)); switch (e->type) { -- cgit v1.2.3