replace combined stateUpdated signal with individual events
This commit is contained in:
@@ -41,41 +41,51 @@ HeaderBar::HeaderBar(QWidget* parent)
|
||||
connect(btn, &QPushButton::clicked, mapper, qOverload<>(&QSignalMapper::map));
|
||||
}
|
||||
connect(mapper, qOverload<int>(&QSignalMapper::mapped), this, &HeaderBar::onSpeedButton);
|
||||
|
||||
|
||||
setFixedHeight(sizeHint().height());
|
||||
|
||||
registerForEvents();
|
||||
}
|
||||
|
||||
void HeaderBar::onStateUpdated(Tick tick, int buildingBlocks, double gameSpeed,
|
||||
int bossCounter, Tick bossCountdownTicks)
|
||||
HeaderBar::~HeaderBar()
|
||||
{
|
||||
const int totalSeconds = static_cast<int>(ticksToSeconds(tick));
|
||||
const int minutes = totalSeconds / 60;
|
||||
const int seconds = totalSeconds % 60;
|
||||
unregisterForEvents();
|
||||
}
|
||||
|
||||
void HeaderBar::handleEvent(std::shared_ptr<const TickAdvancedEvent> event)
|
||||
{
|
||||
const int totalSeconds = static_cast<int>(ticksToSeconds(event->tick));
|
||||
m_timeLabel->setText(
|
||||
QString("%1:%2")
|
||||
.arg(minutes, 2, 10, QChar('0'))
|
||||
.arg(seconds, 2, 10, QChar('0')));
|
||||
.arg(totalSeconds / 60, 2, 10, QChar('0'))
|
||||
.arg(totalSeconds % 60, 2, 10, QChar('0')));
|
||||
}
|
||||
|
||||
m_blocksLabel->setText(tr("Blocks: %1").arg(buildingBlocks));
|
||||
|
||||
const int bossSeconds = static_cast<int>(ticksToSeconds(
|
||||
bossCountdownTicks > 0 ? bossCountdownTicks : 0));
|
||||
const int bossMin = bossSeconds / 60;
|
||||
const int bossSec = bossSeconds % 60;
|
||||
m_bossLabel->setText(
|
||||
tr("Boss Wave #%1 Next boss: %2:%3")
|
||||
.arg(bossCounter)
|
||||
.arg(bossMin)
|
||||
.arg(bossSec, 2, 10, QChar('0')));
|
||||
void HeaderBar::handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event)
|
||||
{
|
||||
m_blocksLabel->setText(tr("Blocks: %1").arg(event->blocks));
|
||||
}
|
||||
|
||||
void HeaderBar::handleEvent(std::shared_ptr<const GameSpeedChangedEvent> event)
|
||||
{
|
||||
for (int i = 0; i < kSpeedCount; ++i)
|
||||
{
|
||||
const bool active = (std::abs(kSpeeds[i] - gameSpeed) < 0.001);
|
||||
m_speedButtons[static_cast<std::size_t>(i)]->setChecked(active);
|
||||
m_speedButtons[static_cast<std::size_t>(i)]->setChecked(
|
||||
std::abs(kSpeeds[i] - event->speed) < 0.001);
|
||||
}
|
||||
}
|
||||
|
||||
void HeaderBar::handleEvent(std::shared_ptr<const BossWaveUpdatedEvent> event)
|
||||
{
|
||||
const int bossSeconds = static_cast<int>(
|
||||
ticksToSeconds(event->countdownTicks > 0 ? event->countdownTicks : 0));
|
||||
m_bossLabel->setText(
|
||||
tr("Boss Wave #%1 Next boss: %2:%3")
|
||||
.arg(event->counter)
|
||||
.arg(bossSeconds / 60)
|
||||
.arg(bossSeconds % 60, 2, 10, QChar('0')));
|
||||
}
|
||||
|
||||
void HeaderBar::onSpeedButton(int index)
|
||||
{
|
||||
if (index >= 0 && index < kSpeedCount)
|
||||
@@ -83,4 +93,3 @@ void HeaderBar::onSpeedButton(int index)
|
||||
emit speedChanged(kSpeeds[index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user