implement demolish button
This commit is contained in:
@@ -82,6 +82,12 @@ BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
connect(mapper, SIGNAL(mapped(int)), this, SLOT(onBuildButton(int)));
|
connect(mapper, SIGNAL(mapped(int)), this, SLOT(onBuildButton(int)));
|
||||||
|
|
||||||
|
m_demolishButton = new QPushButton("Demolish", this);
|
||||||
|
m_demolishButton->setCheckable(true);
|
||||||
|
m_demolishButton->setFixedHeight(48);
|
||||||
|
layout->addWidget(m_demolishButton, row, col);
|
||||||
|
connect(m_demolishButton, SIGNAL(clicked()), this, SIGNAL(demolishModeToggleRequested()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildButtonGrid::updateAffordability(int buildingBlocks)
|
void BuildButtonGrid::updateAffordability(int buildingBlocks)
|
||||||
@@ -95,6 +101,11 @@ void BuildButtonGrid::updateAffordability(int buildingBlocks)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BuildButtonGrid::setDemolishModeActive(bool active)
|
||||||
|
{
|
||||||
|
m_demolishButton->setChecked(active);
|
||||||
|
}
|
||||||
|
|
||||||
void BuildButtonGrid::clearActiveButton()
|
void BuildButtonGrid::clearActiveButton()
|
||||||
{
|
{
|
||||||
if (m_activeIndex >= 0 && m_activeIndex < static_cast<int>(m_buttons.size()))
|
if (m_activeIndex >= 0 && m_activeIndex < static_cast<int>(m_buttons.size()))
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void buildingTypeSelected(BuildingType type);
|
void buildingTypeSelected(BuildingType type);
|
||||||
void builderModeExited();
|
void builderModeExited();
|
||||||
|
void demolishModeToggleRequested();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setDemolishModeActive(bool active);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onBuildButton(int index);
|
void onBuildButton(int index);
|
||||||
@@ -33,4 +37,5 @@ private:
|
|||||||
std::vector<QPushButton*> m_buttons;
|
std::vector<QPushButton*> m_buttons;
|
||||||
std::map<BuildingType, int> m_costs;
|
std::map<BuildingType, int> m_costs;
|
||||||
int m_activeIndex;
|
int m_activeIndex;
|
||||||
|
QPushButton* m_demolishButton;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -901,16 +901,7 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
|
|||||||
emit escapeMenuRequested();
|
emit escapeMenuRequested();
|
||||||
break;
|
break;
|
||||||
case Qt::Key_Backspace:
|
case Qt::Key_Backspace:
|
||||||
if (m_demolishMode)
|
toggleDemolishMode();
|
||||||
{
|
|
||||||
m_demolishMode = false;
|
|
||||||
m_demolishHoverId = kInvalidEntityId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (m_builderType.has_value()) { exitBuilderMode(); }
|
|
||||||
m_demolishMode = true;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
QOpenGLWidget::keyPressEvent(event);
|
QOpenGLWidget::keyPressEvent(event);
|
||||||
@@ -1090,12 +1081,28 @@ void GameWorldView::mouseReleaseEvent(QMouseEvent* event)
|
|||||||
// Slots
|
// Slots
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void GameWorldView::toggleDemolishMode()
|
||||||
|
{
|
||||||
|
if (m_demolishMode)
|
||||||
|
{
|
||||||
|
m_demolishMode = false;
|
||||||
|
m_demolishHoverId = kInvalidEntityId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_builderType.has_value()) { exitBuilderMode(); }
|
||||||
|
m_demolishMode = true;
|
||||||
|
}
|
||||||
|
emit demolishModeChanged(m_demolishMode);
|
||||||
|
}
|
||||||
|
|
||||||
void GameWorldView::enterBuilderMode(BuildingType type)
|
void GameWorldView::enterBuilderMode(BuildingType type)
|
||||||
{
|
{
|
||||||
m_builderType = type;
|
m_builderType = type;
|
||||||
m_ghostRotation = Rotation::East;
|
m_ghostRotation = Rotation::East;
|
||||||
m_ghostValid = false;
|
m_ghostValid = false;
|
||||||
m_demolishMode = false;
|
m_demolishMode = false;
|
||||||
|
emit demolishModeChanged(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameWorldView::exitBuilderMode()
|
void GameWorldView::exitBuilderMode()
|
||||||
@@ -1128,6 +1135,7 @@ void GameWorldView::resetForNewGame()
|
|||||||
m_ghostValid = false;
|
m_ghostValid = false;
|
||||||
m_demolishMode = false;
|
m_demolishMode = false;
|
||||||
m_demolishHoverId = kInvalidEntityId;
|
m_demolishHoverId = kInvalidEntityId;
|
||||||
|
emit demolishModeChanged(false);
|
||||||
m_selectedIds.clear();
|
m_selectedIds.clear();
|
||||||
m_boxSelecting = false;
|
m_boxSelecting = false;
|
||||||
m_scrollXTiles = 0.0f;
|
m_scrollXTiles = 0.0f;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ signals:
|
|||||||
void gameOver();
|
void gameOver();
|
||||||
void builderModeExited();
|
void builderModeExited();
|
||||||
void escapeMenuRequested();
|
void escapeMenuRequested();
|
||||||
|
void demolishModeChanged(bool active);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
double gameSpeed() const;
|
double gameSpeed() const;
|
||||||
@@ -54,6 +55,7 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void enterBuilderMode(BuildingType type);
|
void enterBuilderMode(BuildingType type);
|
||||||
void exitBuilderMode();
|
void exitBuilderMode();
|
||||||
|
void toggleDemolishMode();
|
||||||
void setGameSpeed(double multiplier);
|
void setGameSpeed(double multiplier);
|
||||||
void resetForNewGame();
|
void resetForNewGame();
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ MainWindow::MainWindow(Simulation* sim, const GameConfig* config,
|
|||||||
connect(m_gameWorldView, SIGNAL(builderModeExited()),
|
connect(m_gameWorldView, SIGNAL(builderModeExited()),
|
||||||
m_buildButtonGrid, SLOT(clearActiveButton()));
|
m_buildButtonGrid, SLOT(clearActiveButton()));
|
||||||
|
|
||||||
|
connect(m_buildButtonGrid, SIGNAL(demolishModeToggleRequested()),
|
||||||
|
m_gameWorldView, SLOT(toggleDemolishMode()));
|
||||||
|
|
||||||
|
connect(m_gameWorldView, SIGNAL(demolishModeChanged(bool)),
|
||||||
|
m_buildButtonGrid, SLOT(setDemolishModeActive(bool)));
|
||||||
|
|
||||||
// Signals: header bar → game world
|
// Signals: header bar → game world
|
||||||
connect(m_headerBar, SIGNAL(speedChanged(double)),
|
connect(m_headerBar, SIGNAL(speedChanged(double)),
|
||||||
m_gameWorldView, SLOT(setGameSpeed(double)));
|
m_gameWorldView, SLOT(setGameSpeed(double)));
|
||||||
|
|||||||
Reference in New Issue
Block a user