add restart button to game over screen

This commit is contained in:
2026-04-21 20:38:18 +02:00
parent 043aaf774a
commit b7f2005504
5 changed files with 76 additions and 1 deletions

View File

@@ -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();
}

View File

@@ -51,6 +51,7 @@ public slots:
void enterBuilderMode(BuildingType type);
void exitBuilderMode();
void setGameSpeed(double multiplier);
void resetForNewGame();
protected:
void initializeGL() override;

View File

@@ -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();
}
}