From 771da80bbb85c9fa4f0dcf0f3d04f46a0a20239f Mon Sep 17 00:00:00 2001 From: grorp <82708541+grorp@users.noreply.github.com> Date: Sat, 25 Nov 2023 17:07:07 +0100 Subject: [PATCH] Make it possible again to see item tooltips on Android (#14029) This change is a quick fix so that item tooltips show again on Android. --- src/gui/guiFormSpecMenu.cpp | 2 +- src/gui/guiInventoryList.cpp | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 1cd9ee85f..8fd287c84 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3643,7 +3643,7 @@ void GUIFormSpecMenu::drawMenu() NULL, m_client, IT_ROT_HOVERED); } -/* TODO find way to show tooltips on touchscreen */ + // On touchscreens, m_pointer is set by GUIModalMenu::preprocessEvent instead. #ifndef HAVE_TOUCHSCREENGUI m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition(); #endif diff --git a/src/gui/guiInventoryList.cpp b/src/gui/guiInventoryList.cpp index b84a13290..6f1d28e0b 100644 --- a/src/gui/guiInventoryList.cpp +++ b/src/gui/guiInventoryList.cpp @@ -99,6 +99,7 @@ void GUIInventoryList::draw() (i / m_geom.X) * m_slot_spacing.Y); core::rect rect = imgrect + base_pos + p; ItemStack item = ilist->getItem(item_i); + ItemStack orig_item = item; bool selected = selected_item && m_invmgr->getInventory(selected_item->inventoryloc) == inv @@ -147,13 +148,19 @@ void GUIInventoryList::draw() // Draw item stack drawItemStack(driver, m_font, item, rect, &AbsoluteClippingRect, client, rotation_kind); - // Add hovering tooltip - if (hovering && !selected_item) { - std::string tooltip = item.getDescription(client->idef()); - if (m_fs_menu->doTooltipAppendItemname()) - tooltip += "\n[" + item.name + "]"; - m_fs_menu->addHoveredItemTooltip(tooltip); - } + } + + // Add hovering tooltip + bool show_tooltip = !item.empty() && hovering && !selected_item; +#ifdef HAVE_TOUCHSCREENGUI + // Make it possible to see item tooltips on touchscreens + show_tooltip |= hovering && selected && m_fs_menu->getSelectedAmount() != 0; +#endif + if (show_tooltip) { + std::string tooltip = orig_item.getDescription(client->idef()); + if (m_fs_menu->doTooltipAppendItemname()) + tooltip += "\n[" + orig_item.name + "]"; + m_fs_menu->addHoveredItemTooltip(tooltip); } }