1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add ItemStack:get_description() to get tooltip (#8847)

This commit is contained in:
Paul Ouellette 2019-08-24 12:38:02 -04:00 committed by sfan5
parent efbac7e446
commit 008b80fe1c
6 changed files with 33 additions and 22 deletions

View file

@ -2844,37 +2844,23 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int layer,
}
if (layer == 1) {
// Draw item stack
if (selected)
item.takeItem(m_selected_amount);
if (!item.empty()) {
// Draw item stack
drawItemStack(driver, m_font, item,
rect, &AbsoluteClippingRect, m_client,
rotation_kind);
}
// Draw tooltip
std::wstring tooltip_text;
if (hovering && !m_selected_item) {
const std::string &desc = item.metadata.getString("description");
if (desc.empty())
tooltip_text =
utf8_to_wide(item.getDefinition(m_client->idef()).description);
else
tooltip_text = utf8_to_wide(desc);
if (!item.name.empty()) {
if (tooltip_text.empty())
tooltip_text = utf8_to_wide(item.name);
else if (m_tooltip_append_itemname)
tooltip_text += utf8_to_wide("\n[" + item.name + "]");
// Draw tooltip
if (hovering && !m_selected_item) {
std::string tooltip = item.getDescription(m_client->idef());
if (m_tooltip_append_itemname)
tooltip += "\n[" + item.name + "]";
showTooltip(utf8_to_wide(tooltip), m_default_tooltip_color,
m_default_tooltip_bgcolor);
}
}
if (!tooltip_text.empty()) {
showTooltip(tooltip_text, m_default_tooltip_color,
m_default_tooltip_bgcolor);
}
}
}
}