switch to using own event system

This commit is contained in:
2026-06-13 17:42:16 +02:00
parent ed17664ef1
commit 5317f35198
49 changed files with 611 additions and 300 deletions

View File

@@ -7,7 +7,11 @@
#include <QSignalMapper>
#include "BuildingType.h"
#include "BuildingTypeSelectedEvent.h"
#include "DemolishModeToggleRequestedEvent.h"
#include "DisplayName.h"
#include "EventManager.h"
#include "ExitBuilderModeRequestedEvent.h"
BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
@@ -58,7 +62,17 @@ BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
m_demolishButton->setCheckable(true);
m_demolishButton->setFixedHeight(48);
layout->addWidget(m_demolishButton, row, col);
connect(m_demolishButton, SIGNAL(clicked()), this, SIGNAL(demolishModeToggleRequested()));
connect(m_demolishButton, &QPushButton::clicked, this, [this]() {
EventManager::getInstance()->sendEventImmediately(
std::make_shared<DemolishModeToggleRequestedEvent>());
});
registerForEvents();
}
BuildButtonGrid::~BuildButtonGrid()
{
unregisterForEvents();
}
void BuildButtonGrid::updateAffordability(int buildingBlocks)
@@ -72,11 +86,6 @@ void BuildButtonGrid::updateAffordability(int buildingBlocks)
}
}
void BuildButtonGrid::setDemolishModeActive(bool active)
{
m_demolishButton->setChecked(active);
}
void BuildButtonGrid::clearActiveButton()
{
if (m_activeIndex >= 0 && m_activeIndex < static_cast<int>(m_buttons.size()))
@@ -96,7 +105,8 @@ void BuildButtonGrid::onBuildButton(int index)
if (m_activeIndex == index)
{
clearActiveButton();
emit builderModeExited();
EventManager::getInstance()->sendEventImmediately(
std::make_shared<ExitBuilderModeRequestedEvent>());
return;
}
@@ -107,5 +117,16 @@ void BuildButtonGrid::onBuildButton(int index)
m_activeIndex = index;
m_buttons[static_cast<std::size_t>(index)]->setChecked(true);
emit buildingTypeSelected(m_types[static_cast<std::size_t>(index)]);
EventManager::getInstance()->sendEventImmediately(
std::make_shared<BuildingTypeSelectedEvent>(m_types[static_cast<std::size_t>(index)]));
}
void BuildButtonGrid::handleEvent(std::shared_ptr<const BuilderModeExitedEvent> /*event*/)
{
clearActiveButton();
}
void BuildButtonGrid::handleEvent(std::shared_ptr<const DemolishModeChangedEvent> event)
{
m_demolishButton->setChecked(event->active);
}