1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Other fixes

This commit is contained in:
cx384 2025-03-20 22:03:54 +01:00
parent 69a2d0a511
commit 27b5d3288b
5 changed files with 11 additions and 11 deletions

View file

@ -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}})) 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}} local hotbar_source = {{list = "test", length = 4, offset = 2}, {list = "myinv", length = 16, offset = 99}}
print(dump(player:get_hotbar_source())) player:set_hotbar_source(hotbar_source)
print(player:set_hotbar_source(hotbar_source))
print(dump(player:get_hotbar_source()))
assert(table_equals(player:get_hotbar_source(), hotbar_source)) assert(table_equals(player:get_hotbar_source(), hotbar_source))
assert(player:hud_get_hotbar_itemcount() == 20) assert(player:hud_get_hotbar_itemcount() == 20)

View file

@ -355,7 +355,7 @@ void Hud::drawHotbar(v2s32 screen_pos, v2f offset, u16 direction,
direction, pos, width, height); direction, pos, width, height);
drawInventoryBackground(pos, width, height); drawInventoryBackground(pos, width, height);
/// Handle offset // Handle offset
std::size_t source_index = 0; std::size_t source_index = 0;
u16 length_before = 0; u16 length_before = 0;
for (s32 i_offset = inv_offset; source_index < sources.size(); source_index++) { 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) 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 // Handle splitting caused by hud_hotbar_max_width
u16 hotbar_itemcount = player->hotbar_source.getMaxLength(); u16 hotbar_itemcount = player->hotbar_source.getMaxLength();
float width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2); 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); elems.insert(it, e);
} }
if (g_touchcontrols)
g_touchcontrols->resetHotbarRects();
for (HudElement *e : elems) { for (HudElement *e : elems) {
v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5), v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),

View file

@ -690,7 +690,7 @@ void TouchControls::resetHotbarRects()
void TouchControls::registerHotbarRect(u16 index, const recti &rect) 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) void TouchControls::setVisible(bool visible)

View file

@ -148,7 +148,7 @@ private:
ButtonLayout m_layout; ButtonLayout m_layout;
void applyLayout(const ButtonLayout &layout); void applyLayout(const ButtonLayout &layout);
std::unordered_map<u16, recti> m_hotbar_rects; std::vector<std::pair<u16, recti>> m_hotbar_rects;
std::optional<u16> m_hotbar_selection = std::nullopt; std::optional<u16> m_hotbar_selection = std::nullopt;
// value in degree // value in degree

View file

@ -1272,7 +1272,8 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
break; break;
s32 hotbar_itemcount = readS32((u8*) value.c_str()); s32 hotbar_itemcount = readS32((u8*) value.c_str());
player->hotbar_source.setHotbarItemcountLegacy(hotbar_itemcount); player->hotbar_source.setHotbarItemcountLegacy(hotbar_itemcount);
break; } break;
}
case HUD_PARAM_HOTBAR_IMAGE: case HUD_PARAM_HOTBAR_IMAGE:
player->hotbar_image = value; player->hotbar_image = value;
break; break;
@ -1282,7 +1283,8 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
case HUD_PARAM_HOTBAR_SOURCE: { case HUD_PARAM_HOTBAR_SOURCE: {
std::istringstream is(value); std::istringstream is(value);
player->hotbar_source.deSerialize(is); player->hotbar_source.deSerialize(is);
break; } break;
}
default: default:
break; break;
} }