Compare commits
3 Commits
69848eb9f8
...
b1720dc2b3
| Author | SHA1 | Date | |
|---|---|---|---|
| b1720dc2b3 | |||
| 099f0b55fc | |||
| b133a21914 |
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
|
// Fired when the collected artifact count changes. Carries no payload —
|
||||||
|
// subscribers re-read Simulation::getArtifactCount(), and the win count from
|
||||||
|
// world.artifacts.artifactWinCount.
|
||||||
class ArtifactCountChangedEvent : public Event
|
class ArtifactCountChangedEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
ArtifactCountChangedEvent(int count, int winCount) : count(count), winCount(winCount) {}
|
|
||||||
const int count;
|
|
||||||
const int winCount;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,16 +2,11 @@
|
|||||||
#define BOSS_WAVE_UPDATED_EVENT_H
|
#define BOSS_WAVE_UPDATED_EVENT_H
|
||||||
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "Tick.h"
|
|
||||||
|
|
||||||
|
// Fired when the boss wave counter or its countdown changes. Carries no payload —
|
||||||
|
// subscribers re-read Simulation::getBossWaveCounter() and getBossCountdownTicks().
|
||||||
class BossWaveUpdatedEvent : public Event
|
class BossWaveUpdatedEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
BossWaveUpdatedEvent(int counter, Tick countdownTicks)
|
|
||||||
: counter(counter), countdownTicks(countdownTicks) {}
|
|
||||||
const int counter;
|
|
||||||
const Tick countdownTicks;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BOSS_WAVE_UPDATED_EVENT_H
|
#endif // BOSS_WAVE_UPDATED_EVENT_H
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,10 @@
|
|||||||
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
|
// Fired when the building block stock changes. Carries no payload — subscribers
|
||||||
|
// re-read Simulation::getBuildingBlocksStock().
|
||||||
class BuildingBlocksChangedEvent : public Event
|
class BuildingBlocksChangedEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
explicit BuildingBlocksChangedEvent(int blocks) : blocks(blocks) {}
|
|
||||||
const int blocks;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BUILDING_BLOCKS_CHANGED_EVENT_H
|
#endif // BUILDING_BLOCKS_CHANGED_EVENT_H
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,11 @@
|
|||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
// Fired when the current asteroid-expansion cost changes (REQ-EXP-COST): once at
|
// Fired when the current asteroid-expansion cost changes (REQ-EXP-COST): once at
|
||||||
// startup and again after each expansion is purchased. Carries the cost in
|
// startup and again after each expansion is purchased. Carries no payload — the
|
||||||
// building blocks so the header Expand button can update its caption/enabled
|
// header Expand button re-reads Simulation::getCurrentExpansionCost() to update
|
||||||
// state (REQ-UI-EXPAND-BUTTON).
|
// its caption and enabled state (REQ-UI-EXPAND-BUTTON).
|
||||||
class ExpansionCostChangedEvent : public Event
|
class ExpansionCostChangedEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
explicit ExpansionCostChangedEvent(int cost) : cost(cost) {}
|
|
||||||
const int cost;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXPANSION_COST_CHANGED_EVENT_H
|
#endif // EXPANSION_COST_CHANGED_EVENT_H
|
||||||
|
|||||||
@@ -2,14 +2,11 @@
|
|||||||
#define TICK_ADVANCED_EVENT_H
|
#define TICK_ADVANCED_EVENT_H
|
||||||
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "Tick.h"
|
|
||||||
|
|
||||||
|
// Fired when the simulation tick advances. Carries no payload — subscribers
|
||||||
|
// re-read Simulation::getCurrentTick().
|
||||||
class TickAdvancedEvent : public Event
|
class TickAdvancedEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
explicit TickAdvancedEvent(Tick tick) : tick(tick) {}
|
|
||||||
const Tick tick;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TICK_ADVANCED_EVENT_H
|
#endif // TICK_ADVANCED_EVENT_H
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ BlueprintPanel::BlueprintPanel(Simulation* sim, const GameConfig* config, QWidge
|
|||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_sim(sim)
|
, m_sim(sim)
|
||||||
, m_config(config)
|
, m_config(config)
|
||||||
, m_currentBlocks(0)
|
|
||||||
{
|
{
|
||||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||||
layout->setContentsMargins(4, 4, 4, 4);
|
layout->setContentsMargins(4, 4, 4, 4);
|
||||||
@@ -71,9 +70,8 @@ void BlueprintPanel::onSelectionChanged(const std::vector<BuildingId>& ids)
|
|||||||
refreshButtonStates();
|
refreshButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlueprintPanel::handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event)
|
void BlueprintPanel::handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> /*event*/)
|
||||||
{
|
{
|
||||||
m_currentBlocks = event->blocks;
|
|
||||||
refreshButtonStates();
|
refreshButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,10 +245,12 @@ void BlueprintPanel::refreshButtonStates()
|
|||||||
// A construction site counts the same as an operational building (REQ-UI-BLUEPRINT-CREATE).
|
// A construction site counts the same as an operational building (REQ-UI-BLUEPRINT-CREATE).
|
||||||
m_createBtn->setEnabled(selectionHasPlaceableBuilding(*m_sim, m_selectedBuildingIds));
|
m_createBtn->setEnabled(selectionHasPlaceableBuilding(*m_sim, m_selectedBuildingIds));
|
||||||
|
|
||||||
|
const int blocks = m_sim->getBuildingBlocksStock();
|
||||||
|
|
||||||
for (int i = 0; i < static_cast<int>(m_blueprintButtons.size()); ++i)
|
for (int i = 0; i < static_cast<int>(m_blueprintButtons.size()); ++i)
|
||||||
{
|
{
|
||||||
const int cost = computeBlueprintCost(m_blueprints[static_cast<std::size_t>(i)]);
|
const int cost = computeBlueprintCost(m_blueprints[static_cast<std::size_t>(i)]);
|
||||||
const bool canAfford = m_currentBlocks >= cost;
|
const bool canAfford = blocks >= cost;
|
||||||
m_blueprintButtons[static_cast<std::size_t>(i)]->setEnabled(
|
m_blueprintButtons[static_cast<std::size_t>(i)]->setEnabled(
|
||||||
canAfford || m_activeIndex == i);
|
canAfford || m_activeIndex == i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ private:
|
|||||||
void loadFromDisk();
|
void loadFromDisk();
|
||||||
void saveToDisk() const;
|
void saveToDisk() const;
|
||||||
|
|
||||||
|
// The simulation is the single source of truth for the block stock; the
|
||||||
|
// change event is only a refresh signal.
|
||||||
Simulation* m_sim;
|
Simulation* m_sim;
|
||||||
const GameConfig* m_config;
|
const GameConfig* m_config;
|
||||||
std::vector<BuildingId> m_selectedBuildingIds;
|
std::vector<BuildingId> m_selectedBuildingIds;
|
||||||
int m_currentBlocks;
|
|
||||||
std::optional<int> m_activeIndex; // nullopt = no blueprint selected
|
std::optional<int> m_activeIndex; // nullopt = no blueprint selected
|
||||||
std::vector<Blueprint> m_blueprints;
|
std::vector<Blueprint> m_blueprints;
|
||||||
std::vector<QPushButton*> m_blueprintButtons;
|
std::vector<QPushButton*> m_blueprintButtons;
|
||||||
|
|||||||
@@ -403,26 +403,26 @@ void GameWorldView::onFrame()
|
|||||||
{
|
{
|
||||||
m_lastTick = newTick;
|
m_lastTick = newTick;
|
||||||
EventManager::getInstance()->sendEventImmediately(
|
EventManager::getInstance()->sendEventImmediately(
|
||||||
std::make_shared<TickAdvancedEvent>(newTick));
|
std::make_shared<TickAdvancedEvent>());
|
||||||
}
|
}
|
||||||
if (newBlocks != m_lastBlocks)
|
if (newBlocks != m_lastBlocks)
|
||||||
{
|
{
|
||||||
m_lastBlocks = newBlocks;
|
m_lastBlocks = newBlocks;
|
||||||
EventManager::getInstance()->sendEventImmediately(
|
EventManager::getInstance()->sendEventImmediately(
|
||||||
std::make_shared<BuildingBlocksChangedEvent>(newBlocks));
|
std::make_shared<BuildingBlocksChangedEvent>());
|
||||||
}
|
}
|
||||||
if (newExpCost != m_lastExpansionCost)
|
if (newExpCost != m_lastExpansionCost)
|
||||||
{
|
{
|
||||||
m_lastExpansionCost = newExpCost;
|
m_lastExpansionCost = newExpCost;
|
||||||
EventManager::getInstance()->sendEventImmediately(
|
EventManager::getInstance()->sendEventImmediately(
|
||||||
std::make_shared<ExpansionCostChangedEvent>(newExpCost));
|
std::make_shared<ExpansionCostChangedEvent>());
|
||||||
}
|
}
|
||||||
if (newBoss != m_lastBossCounter || newCountdown != m_lastBossCountdown)
|
if (newBoss != m_lastBossCounter || newCountdown != m_lastBossCountdown)
|
||||||
{
|
{
|
||||||
m_lastBossCounter = newBoss;
|
m_lastBossCounter = newBoss;
|
||||||
m_lastBossCountdown = newCountdown;
|
m_lastBossCountdown = newCountdown;
|
||||||
EventManager::getInstance()->sendEventImmediately(
|
EventManager::getInstance()->sendEventImmediately(
|
||||||
std::make_shared<BossWaveUpdatedEvent>(newBoss, newCountdown));
|
std::make_shared<BossWaveUpdatedEvent>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlocked building set changes only after a drop is applied or on Restart
|
// Unlocked building set changes only after a drop is applied or on Restart
|
||||||
@@ -485,8 +485,7 @@ void GameWorldView::onFrame()
|
|||||||
{
|
{
|
||||||
m_lastArtifactCount = currentArtifactCount;
|
m_lastArtifactCount = currentArtifactCount;
|
||||||
EventManager::getInstance()->sendEventImmediately(
|
EventManager::getInstance()->sendEventImmediately(
|
||||||
std::make_shared<ArtifactCountChangedEvent>(
|
std::make_shared<ArtifactCountChangedEvent>());
|
||||||
currentArtifactCount, m_sim->getConfig().world.artifacts.artifactWinCount));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|||||||
@@ -107,9 +107,9 @@ HeaderBar::~HeaderBar()
|
|||||||
unregisterForEvents();
|
unregisterForEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeaderBar::handleEvent(std::shared_ptr<const TickAdvancedEvent> event)
|
void HeaderBar::handleEvent(std::shared_ptr<const TickAdvancedEvent> /*event*/)
|
||||||
{
|
{
|
||||||
const int totalSeconds = static_cast<int>(ticksToSeconds(event->tick));
|
const int totalSeconds = static_cast<int>(ticksToSeconds(m_sim->getCurrentTick()));
|
||||||
m_timeLabel->setText(
|
m_timeLabel->setText(
|
||||||
QString("%1:%2")
|
QString("%1:%2")
|
||||||
.arg(totalSeconds / 60, 2, 10, QChar('0'))
|
.arg(totalSeconds / 60, 2, 10, QChar('0'))
|
||||||
@@ -195,22 +195,26 @@ void HeaderBar::handleEvent(std::shared_ptr<const GameSpeedChangedEvent> event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeaderBar::handleEvent(std::shared_ptr<const BossWaveUpdatedEvent> event)
|
void HeaderBar::handleEvent(std::shared_ptr<const BossWaveUpdatedEvent> /*event*/)
|
||||||
{
|
{
|
||||||
|
const Tick countdownTicks = m_sim->getBossCountdownTicks();
|
||||||
const int bossSeconds = static_cast<int>(
|
const int bossSeconds = static_cast<int>(
|
||||||
ticksToSeconds(event->countdownTicks > 0 ? event->countdownTicks : 0));
|
ticksToSeconds(countdownTicks > 0 ? countdownTicks : 0));
|
||||||
m_bossWaveLabel->setText(
|
m_bossWaveLabel->setText(
|
||||||
tr("Boss Wave #%1")
|
tr("Boss Wave #%1")
|
||||||
.arg(event->counter));
|
.arg(m_sim->getBossWaveCounter()));
|
||||||
m_nextBossLabel->setText(
|
m_nextBossLabel->setText(
|
||||||
tr("Next boss: %1:%2")
|
tr("Next boss: %1:%2")
|
||||||
.arg(bossSeconds / 60)
|
.arg(bossSeconds / 60)
|
||||||
.arg(bossSeconds % 60, 2, 10, QChar('0')));
|
.arg(bossSeconds % 60, 2, 10, QChar('0')));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeaderBar::handleEvent(std::shared_ptr<const ArtifactCountChangedEvent> event)
|
void HeaderBar::handleEvent(std::shared_ptr<const ArtifactCountChangedEvent> /*event*/)
|
||||||
{
|
{
|
||||||
m_artifactsLabel->setText(tr("Artifacts: %1/%2").arg(event->count).arg(event->winCount));
|
m_artifactsLabel->setText(
|
||||||
|
tr("Artifacts: %1/%2")
|
||||||
|
.arg(m_sim->getArtifactCount())
|
||||||
|
.arg(m_sim->getConfig().world.artifacts.artifactWinCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeaderBar::onSpeedButton(int index)
|
void HeaderBar::onSpeedButton(int index)
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ private:
|
|||||||
|
|
||||||
ItemIconCache* m_itemIcons; // Not owned; lives in MainWindow.
|
ItemIconCache* m_itemIcons; // Not owned; lives in MainWindow.
|
||||||
|
|
||||||
// The simulation is the single source of truth for the block stock and the
|
// The simulation is the single source of truth for everything the header
|
||||||
// expansion cost; the change events are only refresh signals.
|
// displays; the change events are only refresh signals.
|
||||||
const Simulation* m_sim;
|
const Simulation* m_sim;
|
||||||
|
|
||||||
static const double kSpeeds[];
|
static const double kSpeeds[];
|
||||||
|
|||||||
Reference in New Issue
Block a user