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

@@ -16,6 +16,7 @@
#include "EventManager.h"
#include "IconCaption.h"
#include "ItemIconCache.h"
#include "ItemTooltip.h"
#include "Simulation.h"
#include "SpeedChangeRequestedEvent.h"
#include "Tick.h"
@@ -24,11 +25,9 @@
const double HeaderBar::kSpeeds[] = { 0.0, 0.5, 1.0, 2.0, 10.0 };
const int HeaderBar::kSpeedCount = 5;
HeaderBar::HeaderBar(const Simulation* sim, const GameConfig* config,
ItemIconCache* itemIcons, QWidget* parent)
HeaderBar::HeaderBar(const ItemTooltipContext& context, QWidget* parent)
: QWidget(parent)
, m_itemIcons(itemIcons)
, m_sim(sim)
, m_context(context)
{
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(8, 4, 8, 4);
@@ -37,21 +36,21 @@ HeaderBar::HeaderBar(const Simulation* sim, const GameConfig* config,
m_timeLabel = new QLabel("00:00", this);
// Both displays state a value and do nothing when clicked, so a click brings the
// tooltip up at once rather than waiting the hover out (REQ-UI-TOOLTIP-TRIGGER).
// The stock states an amount of an item, so what it shows is that item's production
// tooltip, as every other display naming an item does
// (REQ-UI-BLOCKS-ICON, REQ-UI-ITEM-VALUE-TOOLTIP).
m_blocksLabel = new QLabel(this);
if (config->world.buildingBlocksTooltip)
{
TooltipTrigger::attachText(
*m_blocksLabel,
QString::fromStdString(*config->world.buildingBlocksTooltip),
TooltipTrigger::Trigger::HoverAndClick);
}
ItemTooltip::attachTo(*m_blocksLabel, m_context, kBlockItemId,
TooltipTrigger::Trigger::HoverAndClick);
updateBlocksLabel();
// An artifact count is no item amount, so it has no production path to show and
// states configured text instead (REQ-UI-ARTIFACTS-TOOLTIP).
m_artifactsLabel = new QLabel(tr("Artifacts: 0/?"), this);
if (config->world.artifactTooltip)
if (m_context.config->world.artifactTooltip)
{
TooltipTrigger::attachText(
*m_artifactsLabel,
QString::fromStdString(*config->world.artifactTooltip),
QString::fromStdString(*m_context.config->world.artifactTooltip),
TooltipTrigger::Trigger::HoverAndClick);
}
m_bossWaveLabel = new QLabel(tr("Boss Wave #1"), this);
@@ -108,7 +107,7 @@ HeaderBar::~HeaderBar()
void HeaderBar::handleEvent(std::shared_ptr<const TickAdvancedEvent> /*event*/)
{
const int totalSeconds = static_cast<int>(ticksToSeconds(m_sim->getCurrentTick()));
const int totalSeconds = static_cast<int>(ticksToSeconds(m_context.sim->getCurrentTick()));
m_timeLabel->setText(
QString("%1:%2")
.arg(totalSeconds / 60, 2, 10, QChar('0'))
@@ -128,9 +127,9 @@ void HeaderBar::handleEvent(std::shared_ptr<const ExpansionCostChangedEvent> /*e
void HeaderBar::updateBlocksLabel()
{
const int blocks = m_sim->getBuildingBlocksStock();
const int blocks = m_context.sim->getBuildingBlocksStock();
const QPixmap icon = m_itemIcons->getInlineIcon(kBlockItemId, font());
const QPixmap icon = m_context.itemIcons->getInlineIcon(kBlockItemId, font());
if (icon.isNull())
{
// Fallback text form when no building_block icon exists (REQ-UI-BLOCKS-ICON).
@@ -144,12 +143,12 @@ void HeaderBar::updateBlocksLabel()
void HeaderBar::updateExpandButton()
{
const int blocks = m_sim->getBuildingBlocksStock();
const int expansionCost = m_sim->getCurrentExpansionCost();
const int blocks = m_context.sim->getBuildingBlocksStock();
const int expansionCost = m_context.sim->getCurrentExpansionCost();
m_expandButton->setEnabled(blocks >= expansionCost);
const QPixmap icon = m_itemIcons->getInlineIcon(kBlockItemId, font());
const QPixmap icon = m_context.itemIcons->getInlineIcon(kBlockItemId, font());
if (icon.isNull())
{
// Fallback text form when no building_block icon exists (REQ-UI-EXPAND-BUTTON).
@@ -188,12 +187,12 @@ void HeaderBar::handleEvent(std::shared_ptr<const GameSpeedChangedEvent> event)
void HeaderBar::handleEvent(std::shared_ptr<const BossWaveUpdatedEvent> /*event*/)
{
const Tick countdownTicks = m_sim->getBossCountdownTicks();
const Tick countdownTicks = m_context.sim->getBossCountdownTicks();
const int bossSeconds = static_cast<int>(
ticksToSeconds(countdownTicks > 0 ? countdownTicks : 0));
m_bossWaveLabel->setText(
tr("Boss Wave #%1")
.arg(m_sim->getBossWaveCounter()));
.arg(m_context.sim->getBossWaveCounter()));
m_nextBossLabel->setText(
tr("Next boss: %1:%2")
.arg(bossSeconds / 60)
@@ -204,8 +203,8 @@ void HeaderBar::handleEvent(std::shared_ptr<const ArtifactCountChangedEvent> /*e
{
m_artifactsLabel->setText(
tr("Artifacts: %1/%2")
.arg(m_sim->getArtifactCount())
.arg(m_sim->getConfig().world.artifacts.artifactWinCount));
.arg(m_context.sim->getArtifactCount())
.arg(m_context.sim->getConfig().world.artifacts.artifactWinCount));
}
void HeaderBar::onSpeedButton(int index)