Files
dota_factory/src/ui/ExpandButton.h
Malte Langkabel abe8c8f448 stand the expansion button on the ground it buys
The button leaves the header bar for the world, centered on the columns
the next purchase unlocks and panning with them until it leaves the view.
Those columns now take a lighter tint than the locked ground behind them,
so the boundary between the two says how far one purchase reaches.

Nothing in the code reported a scroll: the camera knew it had moved and
told only the hover. A ViewScrolledEvent says it now, which is what a
widget keeping a place in the world rather than on the screen needs. The
panels want none of it -- they are placed against the screen and stay put
as the world moves under them -- so the button is placed after their pass
and never joins the rectangles they step around.

Its face is two lines, "Expand" over the cost. That makes the cost a
display of its own, so it carries the building-block tooltip the way every
other item value does, on hover alone since the click buys the expansion.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ne3mejABZoLWKLh8fgpM3x
2026-08-18 22:55:06 +02:00

45 lines
1.7 KiB
C++

#pragma once
#include <memory>
#include "BuildingBlocksChangedEvent.h"
#include "EventHandler.h"
#include "ExpansionCostChangedEvent.h"
#include "ItemTooltipContext.h"
#include "OptionButton.h"
class QLabel;
// The asteroid expansion button (REQ-UI-EXPAND-BUTTON): a button that stands in the game
// world on the columns the next purchase would unlock, rather than in the header bar.
//
// It knows what it says and what it costs; where it stands is MainWindow's to decide, the
// position being a place in the world and this button knowing nothing of the view's scroll
// (MainWindow::placeExpandButton).
//
// Its face is two lines, `Expand` over the cost, so that the cost is a display naming an
// item and can explain it the way every other item value does -- on hover only, the click
// belonging to the button (REQ-UI-ITEM-VALUE-TOOLTIP).
class ExpandButton : public OptionButton,
public CombinedEventHandler<ExpansionCostChangedEvent,
BuildingBlocksChangedEvent>
{
Q_OBJECT
public:
// Nothing in the context is owned; all of it must outlive this widget.
explicit ExpandButton(const ItemTooltipContext& context, QWidget* parent = nullptr);
~ExpandButton() override;
private:
void handleEvent(std::shared_ptr<const ExpansionCostChangedEvent> event) override;
void handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event) override;
// Re-states the cost and whether the player can pay it. Asks for a fresh placement
// pass afterwards, because a wider cost re-centers the button.
void refresh();
ItemTooltipContext m_context;
QLabel* m_costLabel;
};