From 27b5d3288baf06e109b9e8dd780e39274a726fca Mon Sep 17 00:00:00 2001 From: cx384 Date: Thu, 20 Mar 2025 22:03:54 +0100 Subject: [PATCH] Other fixes --- games/devtest/mods/unittests/player.lua | 4 +--- src/client/hud.cpp | 8 ++++---- src/gui/touchcontrols.cpp | 2 +- src/gui/touchcontrols.h | 2 +- src/network/clientpackethandler.cpp | 6 ++++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/games/devtest/mods/unittests/player.lua b/games/devtest/mods/unittests/player.lua index 77fc7fe869..610e1f515f 100644 --- a/games/devtest/mods/unittests/player.lua +++ b/games/devtest/mods/unittests/player.lua @@ -226,9 +226,7 @@ local function run_player_hotbar_source_tests(player) assert(table_equals(player:get_hotbar_source(), {{list = "main", length = 5, offset = 0}})) local hotbar_source = {{list = "test", length = 4, offset = 2}, {list = "myinv", length = 16, offset = 99}} - print(dump(player:get_hotbar_source())) - print(player:set_hotbar_source(hotbar_source)) - print(dump(player:get_hotbar_source())) + player:set_hotbar_source(hotbar_source) assert(table_equals(player:get_hotbar_source(), hotbar_source)) assert(player:hud_get_hotbar_itemcount() == 20) diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 7413889f1b..8ecd9822a0 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -355,7 +355,7 @@ void Hud::drawHotbar(v2s32 screen_pos, v2f offset, u16 direction, direction, pos, width, height); drawInventoryBackground(pos, width, height); - /// Handle offset + // Handle offset std::size_t source_index = 0; u16 length_before = 0; for (s32 i_offset = inv_offset; source_index < sources.size(); source_index++) { @@ -393,9 +393,6 @@ void Hud::drawHotbar(v2s32 screen_pos, v2f offset, u16 direction, void Hud::drawHotbarElement(v2s32 pos, HudElement *e) { - if (g_touchcontrols) // FIXME probably breaks if more then one hotbar element exists - g_touchcontrols->resetHotbarRects(); - // Handle splitting caused by hud_hotbar_max_width u16 hotbar_itemcount = player->hotbar_source.getMaxLength(); float width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2); @@ -478,6 +475,9 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) elems.insert(it, e); } + if (g_touchcontrols) + g_touchcontrols->resetHotbarRects(); + for (HudElement *e : elems) { v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5), diff --git a/src/gui/touchcontrols.cpp b/src/gui/touchcontrols.cpp index 7dd837d9e0..d25ab729bc 100644 --- a/src/gui/touchcontrols.cpp +++ b/src/gui/touchcontrols.cpp @@ -690,7 +690,7 @@ void TouchControls::resetHotbarRects() void TouchControls::registerHotbarRect(u16 index, const recti &rect) { - m_hotbar_rects[index] = rect; + m_hotbar_rects.emplace_back(index, rect); } void TouchControls::setVisible(bool visible) diff --git a/src/gui/touchcontrols.h b/src/gui/touchcontrols.h index 9241e32523..c282f00a72 100644 --- a/src/gui/touchcontrols.h +++ b/src/gui/touchcontrols.h @@ -148,7 +148,7 @@ private: ButtonLayout m_layout; void applyLayout(const ButtonLayout &layout); - std::unordered_map m_hotbar_rects; + std::vector> m_hotbar_rects; std::optional m_hotbar_selection = std::nullopt; // value in degree diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index e81d3e88a0..20db8e67a1 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1272,7 +1272,8 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt) break; s32 hotbar_itemcount = readS32((u8*) value.c_str()); player->hotbar_source.setHotbarItemcountLegacy(hotbar_itemcount); - break; } + break; + } case HUD_PARAM_HOTBAR_IMAGE: player->hotbar_image = value; break; @@ -1282,7 +1283,8 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt) case HUD_PARAM_HOTBAR_SOURCE: { std::istringstream is(value); player->hotbar_source.deSerialize(is); - break; } + break; + } default: break; }