explain an item wherever the UI names one

Every display naming an item now shows that item's production tooltip, not
only the selection panel's chips: the header block stock, the total cost of
a building multi-selection, the remaining scrap of a debris selection, the
icons of every recipe summary, and a blueprint card's cost.

ItemTooltip moves out of the selection panel and takes an
ItemTooltipContext of its own -- an item is named all over the UI, and the
panel's context carries visuals and a debug flag no tooltip reads. A
recipe line wraps each icon with its amount so the pair can be pointed at
as one statement, and attaches tooltips only where asked: a module button
and the item tooltip itself draw the same line and stay silent.

Hover only wherever the display sits on something the player clicks, whose
click is not free to explain. Note that a recipe line on an option button
can no longer be transparent to the mouse -- Qt never looks inside a
transparent widget for the cursor -- so it relies on press propagation to
keep picking the option.

The header block stock loses world.building_blocks_tooltip, showing what
every other block icon shows instead. The Expand button keeps no tooltip:
its cost is painted into its face with nowhere to hang one, and the button
is due to be removed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ne3mejABZoLWKLh8fgpM3x
This commit is contained in:
2026-08-18 21:41:34 +02:00
parent dcc801f017
commit 44ec3c51f1
34 changed files with 336 additions and 157 deletions

View File

@@ -10,6 +10,7 @@
#include "BuildingIconCache.h"
#include "ItemIconCache.h"
#include "ItemTooltip.h"
namespace
{
@@ -105,6 +106,13 @@ void RecipeLineRow::setCardChrome(bool enabled)
: QMargins(0, 0, 0, 0));
}
void RecipeLineRow::setItemTooltips(const ItemTooltipContext& context,
TooltipTrigger::Trigger trigger)
{
m_tooltipContext = context;
m_tooltipTrigger = trigger;
}
void RecipeLineRow::setLine(const Spec& spec)
{
if (spec.isEmpty())
@@ -199,25 +207,45 @@ void RecipeLineRow::addAmounts(const std::vector<Amount>& amounts)
{
addAndShow(m_amountsLayout, new QLabel(QStringLiteral("+"), m_amountsRow));
}
// The item's icon on its colored square (REQ-UI-ITEM-ICON). A missing icon file
// is not an error: the square stands alone then, and only an item with no square
// either falls back to its id in text.
const QPixmap icon = (m_itemIcons != nullptr)
? m_itemIcons->getSquarePixmap(entry.itemId, kIconSizePx)
: QPixmap();
if (!icon.isNull())
{
QLabel* iconLabel = new QLabel(m_amountsRow);
iconLabel->setPixmap(icon);
addAndShow(m_amountsLayout, iconLabel);
}
else
{
addAndShow(m_amountsLayout,
new QLabel(QString::fromStdString(entry.itemId), m_amountsRow));
}
addAndShow(m_amountsLayout,
new QLabel(QString::number(entry.amount), m_amountsRow));
addAmount(entry);
}
}
void RecipeLineRow::addAmount(const Amount& entry)
{
// A widget of its own around the pair, so what the player points at is the whole
// statement -- this many of that item -- rather than an icon the height of a line of
// text (REQ-UI-ITEM-VALUE-TOOLTIP). Its spacing is the row's own, so the line reads
// exactly as it did when the two labels sat in the row directly.
QWidget* pair = new QWidget(m_amountsRow);
QHBoxLayout* pairLayout = new QHBoxLayout(pair);
pairLayout->setContentsMargins(0, 0, 0, 0);
pairLayout->setSpacing(m_amountsLayout->spacing());
// The item's icon on its colored square (REQ-UI-ITEM-ICON). A missing icon file
// is not an error: the square stands alone then, and only an item with no square
// either falls back to its id in text.
const QPixmap icon = (m_itemIcons != nullptr)
? m_itemIcons->getSquarePixmap(entry.itemId, kIconSizePx)
: QPixmap();
if (!icon.isNull())
{
QLabel* iconLabel = new QLabel(pair);
iconLabel->setPixmap(icon);
addAndShow(pairLayout, iconLabel);
}
else
{
addAndShow(pairLayout,
new QLabel(QString::fromStdString(entry.itemId), pair));
}
addAndShow(pairLayout, new QLabel(QString::number(entry.amount), pair));
if (m_tooltipContext.has_value())
{
ItemTooltip::attachTo(*pair, *m_tooltipContext, entry.itemId, m_tooltipTrigger);
}
m_amountsLayout->addWidget(pair);
pair->show();
}