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

@@ -30,6 +30,7 @@
#include "BlueprintLibrary.h"
#include "IconCaption.h"
#include "ItemIconCache.h"
#include "ItemTooltip.h"
#include "TooltipTrigger.h"
namespace
@@ -113,9 +114,10 @@ namespace
return face;
}
// A composed card face and the size to show it at; the button needs both, and only
// the composer knows the size it arrived at.
struct CardFace { QIcon icon; QSize size; };
// A composed card face, the size to show it at, and where in it the cost ended up:
// the button needs the first two, and only the composer knows the third, which is
// what the cost's tooltip is hung on (REQ-UI-ITEM-VALUE-TOOLTIP).
struct CardFace { QIcon icon; QSize size; QRect costRect; };
// The two-mode face of one card. The modes differ only in the text color, so an
// unaffordable card greys itself when Qt swaps the pixmap on the disabled button
@@ -142,17 +144,23 @@ namespace
textColor, dimColor, faceSize);
result.icon.addPixmap(face, mode);
result.size = result.size.expandedTo(getLogicalSize(face));
// Where composeCardFace put it: bottom left, its own width. Both modes
// compose the same text, so both arrive at the same rect.
const QSize costSize = getLogicalSize(costPixmap);
result.costRect = QRect(0, faceSize.height() - costSize.height(),
costSize.width(), costSize.height());
}
return result;
}
}
BlueprintSelectionDialog::BlueprintSelectionDialog(BlueprintLibrary* library,
ItemIconCache* itemIcons,
const ItemTooltipContext& context,
QWidget* parent)
: ModalDialog(parent)
, m_library(library)
, m_itemIcons(itemIcons)
, m_context(context)
, m_itemIcons(context.itemIcons)
{
QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(kSpacingPx, kSpacingPx, kSpacingPx, kSpacingPx);
@@ -264,6 +272,20 @@ void BlueprintSelectionDialog::rebuildGrid()
body->setEnabled(m_library->getCanAfford(i));
cardLayout->addWidget(body);
// The cost is painted into the face, so what explains the item it names is a
// child of its own laid over that band -- placed by hand like the delete icon
// below (REQ-UI-ITEM-VALUE-TOOLTIP). The face is centered in the button, which
// is what the offset accounts for. A child of the body rather than a sibling, so
// that the press it does not handle still reaches the button and picks the
// blueprint; hover only, for the same reason (REQ-UI-TOOLTIP-TRIGGER).
QWidget* costArea = new QWidget(body);
const QPoint faceOrigin((cardSize.width() - face.size.width()) / 2,
(cardSize.height() - face.size.height()) / 2);
costArea->setGeometry(QRect(faceOrigin + face.costRect.topLeft(),
face.costRect.size()));
ItemTooltip::attachTo(*costArea, m_context, kBlockItemId,
TooltipTrigger::Trigger::HoverOnly);
// A sibling of the body rather than one of its children, and outside the
// layout: Qt disables a widget's children along with it, and the delete icon
// must stay enabled on an unaffordable card (REQ-UI-BLUEPRINT-DELETE).