1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-16 18:01:40 +00:00

TouchScreenGUI: Fix only 9 hotbar slots being usable (#13698)

Co-authored-by: Muhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com>
This commit is contained in:
Gregor Parzefall 2023-08-24 17:45:51 +02:00 committed by GitHub
parent 72ef90885d
commit 92b6ff4721
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 45 deletions

View file

@ -2168,6 +2168,14 @@ void Game::processItemSelection(u16 *new_playeritem)
}
}
#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui) {
std::optional<u16> selection = g_touchscreengui->getHotbarSelection();
if (selection)
*new_playeritem = *selection;
}
#endif
// Clamp selection again in case it wasn't changed but max_item was
*new_playeritem = MYMIN(*new_playeritem, max_item);
}

View file

@ -223,16 +223,12 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
client, selected ? IT_ROT_SELECTED : IT_ROT_NONE);
}
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
// NOTE: selectitem = 0 -> no selected; selectitem is 1-based
// mainlist can be NULL, but draw the frame anyway.
void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction)
s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction,
bool is_hotbar)
{
#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui && inv_offset == 0)
g_touchscreengui->resetHud();
#endif
s32 height = m_hotbar_imagesize + m_padding * 2;
s32 width = (itemcount - inv_offset) * (m_hotbar_imagesize + m_padding * 2);
@ -292,11 +288,13 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
break;
}
drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i + 1) == selectitem);
core::rect<s32> item_rect = imgrect + pos + steppos;
drawItem(mainlist->getItem(i), item_rect, (i + 1) == selectitem);
#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui)
g_touchscreengui->registerHudItem(i, (imgrect + pos + steppos));
if (is_hotbar && g_touchscreengui)
g_touchscreengui->registerHotbarRect(i, item_rect);
#endif
}
}
@ -406,7 +404,7 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
if (!inv)
warningstream << "HUD: Unknown inventory list. name=" << e->text << std::endl;
drawItems(pos, v2s32(e->offset.X, e->offset.Y), e->number, 0,
inv, e->item, e->dir);
inv, e->item, e->dir, false);
break; }
case HUD_ELEM_WAYPOINT: {
if (!calculateScreenPos(camera_offset, e, &pos))
@ -739,16 +737,21 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
}
void Hud::drawHotbar(u16 playeritem) {
v2s32 centerlowerpos(m_displaycenter.X, m_screensize.Y);
void Hud::drawHotbar(u16 playeritem)
{
#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui)
g_touchscreengui->resetHotbarRects();
#endif
InventoryList *mainlist = inventory->getList("main");
if (mainlist == NULL) {
//silently ignore this we may not be initialized completely
// Silently ignore this. We may not be initialized completely.
return;
}
v2s32 centerlowerpos(m_displaycenter.X, m_screensize.Y);
s32 hotbar_itemcount = player->hud_hotbar_itemcount;
s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3);
@ -757,7 +760,7 @@ void Hud::drawHotbar(u16 playeritem) {
if ((float) width / (float) window_size.X <=
g_settings->getFloat("hud_hotbar_max_width")) {
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0, true);
}
} else {
pos.X += width/4;
@ -767,9 +770,9 @@ void Hud::drawHotbar(u16 playeritem) {
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
drawItems(pos, v2s32(0, 0), hotbar_itemcount / 2, 0,
mainlist, playeritem + 1, 0);
mainlist, playeritem + 1, 0, true);
drawItems(secondpos, v2s32(0, 0), hotbar_itemcount,
hotbar_itemcount / 2, mainlist, playeritem + 1, 0);
hotbar_itemcount / 2, mainlist, playeritem + 1, 0, true);
}
}
}

View file

@ -101,7 +101,7 @@ private:
void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
s32 inv_offset, InventoryList *mainlist, u16 selectitem,
u16 direction);
u16 direction, bool is_hotbar);
void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);