82 lines
2.9 KiB
C++
82 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <QPixmap>
|
|
#include <QWidget>
|
|
|
|
#include "ArtifactCountChangedEvent.h"
|
|
#include "BossWaveUpdatedEvent.h"
|
|
#include "BuildingBlocksChangedEvent.h"
|
|
#include "EventHandler.h"
|
|
#include "ExpansionCostChangedEvent.h"
|
|
#include "GameConfig.h"
|
|
#include "GameSpeedChangedEvent.h"
|
|
#include "Tick.h"
|
|
#include "TickAdvancedEvent.h"
|
|
|
|
class QLabel;
|
|
class QPushButton;
|
|
class ItemIconCache;
|
|
|
|
class HeaderBar : public QWidget,
|
|
public CombinedEventHandler<TickAdvancedEvent,
|
|
BuildingBlocksChangedEvent,
|
|
ExpansionCostChangedEvent,
|
|
GameSpeedChangedEvent,
|
|
BossWaveUpdatedEvent,
|
|
ArtifactCountChangedEvent>
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
// itemsIconDir holds the per-item icon SVGs (REQ-UI-ITEM-ICON); used to show the
|
|
// building_block icon in the stock display and expand button (REQ-UI-BLOCKS-ICON,
|
|
// REQ-UI-EXPAND-BUTTON).
|
|
HeaderBar(const GameConfig* config, const std::string& itemsIconDir,
|
|
QWidget* parent = nullptr);
|
|
~HeaderBar() override;
|
|
|
|
private slots:
|
|
void onSpeedButton(int index);
|
|
|
|
private:
|
|
void handleEvent(std::shared_ptr<const TickAdvancedEvent> event) override;
|
|
void handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event) override;
|
|
void handleEvent(std::shared_ptr<const ExpansionCostChangedEvent> event) override;
|
|
void handleEvent(std::shared_ptr<const GameSpeedChangedEvent> event) override;
|
|
void handleEvent(std::shared_ptr<const BossWaveUpdatedEvent> event) override;
|
|
void handleEvent(std::shared_ptr<const ArtifactCountChangedEvent> event) override;
|
|
|
|
// Refreshes the Expand button caption and enabled state from the current
|
|
// expansion cost and building block stock (REQ-UI-EXPAND-BUTTON).
|
|
void updateExpandButton();
|
|
|
|
// Refreshes the building blocks stock display from m_blocks: `Stock: <n>` with
|
|
// the building_block icon after it, or the `Stock: <n> Blocks` text fallback when
|
|
// no icon file exists (REQ-UI-BLOCKS-ICON).
|
|
void updateBlocksLabel();
|
|
|
|
// The building_block icon at the header's text height, or a null pixmap when no
|
|
// icon file exists. Loaded once via m_itemIcons on first use.
|
|
QPixmap blockIcon() const;
|
|
|
|
QLabel* m_timeLabel;
|
|
QLabel* m_blocksLabel;
|
|
QLabel* m_artifactsLabel;
|
|
QLabel* m_bossWaveLabel;
|
|
QLabel* m_nextBossLabel;
|
|
QPushButton* m_expandButton;
|
|
std::vector<QPushButton*> m_speedButtons;
|
|
|
|
std::unique_ptr<ItemIconCache> m_itemIcons;
|
|
|
|
int m_blocks = 0;
|
|
int m_expansionCost = 0;
|
|
|
|
static const double kSpeeds[];
|
|
static const int kSpeedCount;
|
|
};
|