implement escape menu
This commit is contained in:
@@ -898,15 +898,7 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::Key_Escape:
|
case Qt::Key_Escape:
|
||||||
if (m_builderType.has_value())
|
emit escapeMenuRequested();
|
||||||
{
|
|
||||||
exitBuilderMode();
|
|
||||||
}
|
|
||||||
else if (m_demolishMode)
|
|
||||||
{
|
|
||||||
m_demolishMode = false;
|
|
||||||
m_demolishHoverId = kInvalidEntityId;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Qt::Key_Backspace:
|
case Qt::Key_Backspace:
|
||||||
if (m_demolishMode)
|
if (m_demolishMode)
|
||||||
@@ -1114,6 +1106,11 @@ void GameWorldView::exitBuilderMode()
|
|||||||
emit builderModeExited();
|
emit builderModeExited();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double GameWorldView::gameSpeed() const
|
||||||
|
{
|
||||||
|
return m_gameSpeedMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
void GameWorldView::setGameSpeed(double multiplier)
|
void GameWorldView::setGameSpeed(double multiplier)
|
||||||
{
|
{
|
||||||
m_gameSpeedMultiplier = multiplier;
|
m_gameSpeedMultiplier = multiplier;
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ signals:
|
|||||||
void stateUpdated(Tick tick, int blocks, double speed);
|
void stateUpdated(Tick tick, int blocks, double speed);
|
||||||
void gameOver();
|
void gameOver();
|
||||||
void builderModeExited();
|
void builderModeExited();
|
||||||
|
void escapeMenuRequested();
|
||||||
|
|
||||||
|
public:
|
||||||
|
double gameSpeed() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void enterBuilderMode(BuildingType type);
|
void enterBuilderMode(BuildingType type);
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ MainWindow::MainWindow(Simulation* sim, const GameConfig* config,
|
|||||||
connect(m_gameWorldView, SIGNAL(gameOver()),
|
connect(m_gameWorldView, SIGNAL(gameOver()),
|
||||||
this, SLOT(onGameOver()));
|
this, SLOT(onGameOver()));
|
||||||
|
|
||||||
|
connect(m_gameWorldView, SIGNAL(escapeMenuRequested()),
|
||||||
|
this, SLOT(onEscapeMenuRequested()));
|
||||||
|
|
||||||
// Signals: build grid → game world
|
// Signals: build grid → game world
|
||||||
connect(m_buildButtonGrid, SIGNAL(buildingTypeSelected(BuildingType)),
|
connect(m_buildButtonGrid, SIGNAL(buildingTypeSelected(BuildingType)),
|
||||||
m_gameWorldView, SLOT(enterBuilderMode(BuildingType)));
|
m_gameWorldView, SLOT(enterBuilderMode(BuildingType)));
|
||||||
@@ -95,6 +98,35 @@ void MainWindow::onStateUpdated(Tick /*tick*/, int blocks, double /*speed*/)
|
|||||||
m_buildButtonGrid->updateAffordability(blocks);
|
m_buildButtonGrid->updateAffordability(blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onEscapeMenuRequested()
|
||||||
|
{
|
||||||
|
const double prevSpeed = m_gameWorldView->gameSpeed();
|
||||||
|
m_gameWorldView->setGameSpeed(0.0);
|
||||||
|
|
||||||
|
QMessageBox box(this);
|
||||||
|
box.setWindowTitle("Paused");
|
||||||
|
QPushButton* continueBtn = box.addButton("Continue", QMessageBox::AcceptRole);
|
||||||
|
QPushButton* restartBtn = box.addButton("Restart", QMessageBox::ResetRole);
|
||||||
|
QPushButton* quitBtn = box.addButton("Quit", QMessageBox::DestructiveRole);
|
||||||
|
box.setEscapeButton(continueBtn);
|
||||||
|
box.exec();
|
||||||
|
|
||||||
|
QAbstractButton* clicked = box.clickedButton();
|
||||||
|
if (clicked == restartBtn)
|
||||||
|
{
|
||||||
|
m_sim->reset();
|
||||||
|
m_gameWorldView->resetForNewGame();
|
||||||
|
}
|
||||||
|
else if (clicked == quitBtn)
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_gameWorldView->setGameSpeed(prevSpeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onGameOver()
|
void MainWindow::onGameOver()
|
||||||
{
|
{
|
||||||
const Tick tick = m_sim->currentTick();
|
const Tick tick = m_sim->currentTick();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ protected:
|
|||||||
private slots:
|
private slots:
|
||||||
void onGameOver();
|
void onGameOver();
|
||||||
void onStateUpdated(Tick tick, int blocks, double speed);
|
void onStateUpdated(Tick tick, int blocks, double speed);
|
||||||
|
void onEscapeMenuRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void layoutPanels();
|
void layoutPanels();
|
||||||
|
|||||||
Reference in New Issue
Block a user