add restart button to game over screen
This commit is contained in:
@@ -1121,3 +1121,24 @@ void GameWorldView::setGameSpeed(double multiplier)
|
||||
m_sim->buildingBlocksStock(),
|
||||
m_gameSpeedMultiplier);
|
||||
}
|
||||
|
||||
void GameWorldView::resetForNewGame()
|
||||
{
|
||||
exitBuilderMode();
|
||||
m_activeBeams.clear();
|
||||
m_toasts.clear();
|
||||
m_ghostRotation = Rotation::East;
|
||||
m_ghostValid = false;
|
||||
m_demolishMode = false;
|
||||
m_demolishHoverId = kInvalidEntityId;
|
||||
m_selectedIds.clear();
|
||||
m_boxSelecting = false;
|
||||
m_scrollXTiles = 0.0f;
|
||||
m_scrollLeft = false;
|
||||
m_scrollRight = false;
|
||||
m_gameOverShown = false;
|
||||
m_gameSpeedMultiplier = 1.0;
|
||||
m_prevNonZeroSpeed = 1.0;
|
||||
emit selectionChanged({});
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public slots:
|
||||
void enterBuilderMode(BuildingType type);
|
||||
void exitBuilderMode();
|
||||
void setGameSpeed(double multiplier);
|
||||
void resetForNewGame();
|
||||
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QResizeEvent>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
@@ -106,7 +107,17 @@ void MainWindow::onGameOver()
|
||||
box.setText(QString("HQ destroyed!\nSurvival time: %1:%2")
|
||||
.arg(minutes, 2, 10, QChar('0'))
|
||||
.arg(seconds, 2, 10, QChar('0')));
|
||||
QPushButton* restartBtn = box.addButton("Restart", QMessageBox::AcceptRole);
|
||||
box.addButton("Quit", QMessageBox::RejectRole);
|
||||
box.exec();
|
||||
close();
|
||||
|
||||
if (box.clickedButton() == restartBtn)
|
||||
{
|
||||
m_sim->reset();
|
||||
m_gameWorldView->resetForNewGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user