switch to using own event system
This commit is contained in:
@@ -53,52 +53,6 @@ MainWindow::MainWindow(Simulation* sim, const std::string& configDir, QWidget* p
|
||||
bottomLayout->addWidget(m_buildButtonGrid, 1);
|
||||
bottomLayout->addWidget(m_blueprintPanel, 1);
|
||||
|
||||
// Signals: game world → other panels
|
||||
connect(m_gameWorldView, &GameWorldView::selectionChanged,
|
||||
m_selectedBuildingPanel, &SelectedBuildingPanel::onSelectionChanged);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::gameOver,
|
||||
this, &MainWindow::onGameOver);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::escapeMenuRequested,
|
||||
this, &MainWindow::onEscapeMenuRequested);
|
||||
|
||||
connect(m_selectedBuildingPanel, &SelectedBuildingPanel::layoutDialogRequested,
|
||||
this, &MainWindow::onLayoutDialogRequested);
|
||||
|
||||
// Signals: build grid → game world
|
||||
connect(m_buildButtonGrid, &BuildButtonGrid::buildingTypeSelected,
|
||||
m_gameWorldView, &GameWorldView::enterBuilderMode);
|
||||
|
||||
connect(m_buildButtonGrid, &BuildButtonGrid::builderModeExited,
|
||||
m_gameWorldView, &GameWorldView::exitBuilderMode);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::builderModeExited,
|
||||
m_buildButtonGrid, &BuildButtonGrid::clearActiveButton);
|
||||
|
||||
connect(m_buildButtonGrid, &BuildButtonGrid::demolishModeToggleRequested,
|
||||
m_gameWorldView, &GameWorldView::toggleDemolishMode);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::demolishModeChanged,
|
||||
m_buildButtonGrid, &BuildButtonGrid::setDemolishModeActive);
|
||||
|
||||
// Signals: blueprint panel ↔ game world
|
||||
connect(m_gameWorldView, &GameWorldView::selectionChanged,
|
||||
m_blueprintPanel, &BlueprintPanel::onSelectionChanged);
|
||||
|
||||
connect(m_blueprintPanel, &BlueprintPanel::blueprintPlacementRequested,
|
||||
m_gameWorldView, &GameWorldView::enterBlueprintMode);
|
||||
|
||||
connect(m_blueprintPanel, &BlueprintPanel::exitBlueprintModeRequested,
|
||||
m_gameWorldView, &GameWorldView::exitBlueprintMode);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::blueprintModeExited,
|
||||
m_blueprintPanel, &BlueprintPanel::clearActiveBlueprintButton);
|
||||
|
||||
// Signals: header bar → game world
|
||||
connect(m_headerBar, &HeaderBar::speedChanged,
|
||||
m_gameWorldView, &GameWorldView::setGameSpeed);
|
||||
|
||||
m_gameWorldView->setFocus();
|
||||
|
||||
connect(qApp, &QApplication::focusChanged, this, [this](QWidget*, QWidget* newWidget) {
|
||||
@@ -191,7 +145,7 @@ void MainWindow::handleEvent(std::shared_ptr<const SchematicChoicesAvailableEven
|
||||
m_gameWorldView->resetFrameTimer();
|
||||
}
|
||||
|
||||
void MainWindow::onEscapeMenuRequested()
|
||||
void MainWindow::handleEvent(std::shared_ptr<const EscapeMenuRequestedEvent> /*event*/)
|
||||
{
|
||||
const double prevSpeed = m_gameWorldView->gameSpeed();
|
||||
m_gameWorldView->setGameSpeed(0.0);
|
||||
@@ -235,12 +189,12 @@ void MainWindow::onEscapeMenuRequested()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onLayoutDialogRequested(BuildingId shipyardId)
|
||||
void MainWindow::handleEvent(std::shared_ptr<const LayoutDialogRequestedEvent> event)
|
||||
{
|
||||
const double prevSpeed = m_gameWorldView->gameSpeed();
|
||||
m_gameWorldView->setGameSpeed(0.0);
|
||||
|
||||
const Building* b = m_sim->buildings().findBuilding(shipyardId);
|
||||
const Building* b = m_sim->buildings().findBuilding(event->shipyardId);
|
||||
if (!b)
|
||||
{
|
||||
m_gameWorldView->setGameSpeed(prevSpeed);
|
||||
@@ -272,14 +226,14 @@ void MainWindow::onLayoutDialogRequested(BuildingId shipyardId)
|
||||
this);
|
||||
if (dialog.exec() == QDialog::Accepted && dialog.result().has_value())
|
||||
{
|
||||
m_sim->buildings().setShipLayout(shipyardId, *dialog.result());
|
||||
m_sim->buildings().setShipLayout(event->shipyardId, *dialog.result());
|
||||
}
|
||||
|
||||
m_gameWorldView->setGameSpeed(prevSpeed);
|
||||
m_gameWorldView->resetFrameTimer();
|
||||
}
|
||||
|
||||
void MainWindow::onGameOver()
|
||||
void MainWindow::handleEvent(std::shared_ptr<const GameOverEvent> /*event*/)
|
||||
{
|
||||
const Tick tick = m_sim->currentTick();
|
||||
const int totalSeconds = static_cast<int>(ticksToSeconds(tick));
|
||||
|
||||
Reference in New Issue
Block a user