diff options
author | Pierre-Yves Rollo <dev@pyrollo.com> | 2019-11-04 09:30:02 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2019-12-06 20:31:26 +0000 |
commit | cf7fda00831372d981415f9a830513b2b28fdf25 (patch) | |
tree | ad8d856fe0c85f3cb35e205a5df4b286e04bf9aa /src/client | |
parent | f6de86ce4b9da21f16d3bcdbc0c55ce4cbe23067 (diff) | |
download | minetest-cf7fda00831372d981415f9a830513b2b28fdf25.tar.gz minetest-cf7fda00831372d981415f9a830513b2b28fdf25.tar.bz2 minetest-cf7fda00831372d981415f9a830513b2b28fdf25.zip |
Add z-index management to HUD
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/clientevent.h | 1 | ||||
-rw-r--r-- | src/client/game.cpp | 5 | ||||
-rw-r--r-- | src/client/hud.cpp | 14 |
3 files changed, 20 insertions, 0 deletions
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<size_t> 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) { |