switch to using own event system
This commit is contained in:
@@ -12,8 +12,11 @@
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "BlueprintPlacementRequestedEvent.h"
|
||||
#include "BlueprintSerializer.h"
|
||||
#include "BuildingBlocksChangedEvent.h"
|
||||
#include "EventManager.h"
|
||||
#include "ExitBlueprintModeRequestedEvent.h"
|
||||
|
||||
#include "Building.h"
|
||||
#include "BuildingSystem.h"
|
||||
@@ -62,12 +65,12 @@ BlueprintPanel::BlueprintPanel(Simulation* sim, const GameConfig* config, QWidge
|
||||
connect(m_saveBtn, &QPushButton::clicked, this, &BlueprintPanel::onSaveClicked);
|
||||
connect(m_loadBtn, &QPushButton::clicked, this, &BlueprintPanel::onLoadClicked);
|
||||
|
||||
registerForEvent();
|
||||
registerForEvents();
|
||||
}
|
||||
|
||||
BlueprintPanel::~BlueprintPanel()
|
||||
{
|
||||
unregisterForEvent();
|
||||
unregisterForEvents();
|
||||
}
|
||||
|
||||
void BlueprintPanel::onSelectionChanged(const std::vector<BuildingId>& ids)
|
||||
@@ -114,7 +117,8 @@ void BlueprintPanel::onDeleteBlueprintClicked(int index)
|
||||
if (m_activeIndex == index)
|
||||
{
|
||||
m_activeIndex = -1;
|
||||
emit exitBlueprintModeRequested();
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<ExitBlueprintModeRequestedEvent>());
|
||||
}
|
||||
else if (m_activeIndex > index)
|
||||
{
|
||||
@@ -131,7 +135,8 @@ void BlueprintPanel::onBlueprintButtonClicked(int index)
|
||||
if (m_activeIndex == index)
|
||||
{
|
||||
clearActiveBlueprintButton();
|
||||
emit exitBlueprintModeRequested();
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<ExitBlueprintModeRequestedEvent>());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,7 +147,8 @@ void BlueprintPanel::onBlueprintButtonClicked(int index)
|
||||
|
||||
m_activeIndex = index;
|
||||
m_blueprintButtons[static_cast<std::size_t>(index)]->setChecked(true);
|
||||
emit blueprintPlacementRequested(m_blueprints[static_cast<std::size_t>(index)]);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<BlueprintPlacementRequestedEvent>(m_blueprints[static_cast<std::size_t>(index)]));
|
||||
}
|
||||
|
||||
Blueprint BlueprintPanel::createBlueprintFromSelection() const
|
||||
@@ -312,7 +318,8 @@ void BlueprintPanel::onLoadClicked()
|
||||
|
||||
if (m_activeIndex >= 0)
|
||||
{
|
||||
emit exitBlueprintModeRequested();
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<ExitBlueprintModeRequestedEvent>());
|
||||
m_activeIndex = -1;
|
||||
}
|
||||
|
||||
@@ -350,3 +357,13 @@ void BlueprintPanel::refreshButtonStates()
|
||||
canAfford || m_activeIndex == i);
|
||||
}
|
||||
}
|
||||
|
||||
void BlueprintPanel::handleEvent(std::shared_ptr<const SelectionChangedEvent> event)
|
||||
{
|
||||
onSelectionChanged(event->ids);
|
||||
}
|
||||
|
||||
void BlueprintPanel::handleEvent(std::shared_ptr<const BlueprintModeExitedEvent> /*event*/)
|
||||
{
|
||||
clearActiveBlueprintButton();
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
#include <QWidget>
|
||||
|
||||
#include "Blueprint.h"
|
||||
#include "BlueprintModeExitedEvent.h"
|
||||
#include "BuildingBlocksChangedEvent.h"
|
||||
#include "BuildingId.h"
|
||||
#include "EventHandler.h"
|
||||
#include "GameConfig.h"
|
||||
#include "SelectionChangedEvent.h"
|
||||
#include "Tick.h"
|
||||
|
||||
class Simulation;
|
||||
@@ -17,7 +19,9 @@ class QScrollArea;
|
||||
class QVBoxLayout;
|
||||
|
||||
class BlueprintPanel : public QWidget,
|
||||
public EventHandler<BuildingBlocksChangedEvent>
|
||||
public CombinedEventHandler<BuildingBlocksChangedEvent,
|
||||
SelectionChangedEvent,
|
||||
BlueprintModeExitedEvent>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -25,16 +29,10 @@ public:
|
||||
BlueprintPanel(Simulation* sim, const GameConfig* config, QWidget* parent = nullptr);
|
||||
~BlueprintPanel() override;
|
||||
|
||||
public slots:
|
||||
void onSelectionChanged(const std::vector<BuildingId>& ids);
|
||||
void clearActiveBlueprintButton();
|
||||
|
||||
signals:
|
||||
void blueprintPlacementRequested(Blueprint blueprint);
|
||||
void exitBlueprintModeRequested();
|
||||
|
||||
private:
|
||||
void handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const SelectionChangedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const BlueprintModeExitedEvent> event) override;
|
||||
|
||||
private slots:
|
||||
void onCreateClicked();
|
||||
@@ -44,6 +42,8 @@ private slots:
|
||||
void onLoadClicked();
|
||||
|
||||
private:
|
||||
void onSelectionChanged(const std::vector<BuildingId>& ids);
|
||||
void clearActiveBlueprintButton();
|
||||
Blueprint createBlueprintFromSelection() const;
|
||||
int computeBlueprintCost(const Blueprint& bp) const;
|
||||
void rebuildButtons();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -5,28 +5,30 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "BuilderModeExitedEvent.h"
|
||||
#include "BuildingType.h"
|
||||
#include "DemolishModeChangedEvent.h"
|
||||
#include "EventHandler.h"
|
||||
#include "GameConfig.h"
|
||||
|
||||
class QPushButton;
|
||||
|
||||
class BuildButtonGrid : public QWidget
|
||||
class BuildButtonGrid : public QWidget,
|
||||
public CombinedEventHandler<BuilderModeExitedEvent,
|
||||
DemolishModeChangedEvent>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BuildButtonGrid(const GameConfig* config, QWidget* parent = nullptr);
|
||||
~BuildButtonGrid() override;
|
||||
|
||||
void updateAffordability(int buildingBlocks);
|
||||
void clearActiveButton();
|
||||
|
||||
signals:
|
||||
void buildingTypeSelected(BuildingType type);
|
||||
void builderModeExited();
|
||||
void demolishModeToggleRequested();
|
||||
|
||||
public slots:
|
||||
void setDemolishModeActive(bool active);
|
||||
private:
|
||||
void handleEvent(std::shared_ptr<const BuilderModeExitedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const DemolishModeChangedEvent> event) override;
|
||||
|
||||
private slots:
|
||||
void onBuildButton(int index);
|
||||
|
||||
@@ -20,14 +20,17 @@
|
||||
#include "BeltSystem.h"
|
||||
#include "Building.h"
|
||||
#include "BuildingSystem.h"
|
||||
#include "DemolishModeChangedEvent.h"
|
||||
#include "EntityHitTest.h"
|
||||
#include "EntitySelectedEvent.h"
|
||||
#include "EventManager.h"
|
||||
#include "FacingComponent.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "GameOverEvent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "ScrapSystem.h"
|
||||
#include "SelectionChangedEvent.h"
|
||||
#include "SensorRangeComponent.h"
|
||||
#include "ShipIdentityComponent.h"
|
||||
#include "ShipSystem.h"
|
||||
@@ -35,8 +38,11 @@
|
||||
#include "StationBodyComponent.h"
|
||||
#include "SurfaceMask.h"
|
||||
#include "Tick.h"
|
||||
#include "EscapeMenuRequestedEvent.h"
|
||||
#include "TracePrintRequestedEvent.h"
|
||||
#include "BossWaveUpdatedEvent.h"
|
||||
#include "BuilderModeExitedEvent.h"
|
||||
#include "BlueprintModeExitedEvent.h"
|
||||
#include "BuildingBlocksChangedEvent.h"
|
||||
#include "GameSpeedChangedEvent.h"
|
||||
#include "SchematicChoicesAvailableEvent.h"
|
||||
@@ -115,6 +121,13 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config,
|
||||
connect(m_renderTimer, &QTimer::timeout, this, &GameWorldView::onFrame);
|
||||
m_renderTimer->start();
|
||||
m_frameTimer.start();
|
||||
|
||||
registerForEvents();
|
||||
}
|
||||
|
||||
GameWorldView::~GameWorldView()
|
||||
{
|
||||
unregisterForEvents();
|
||||
}
|
||||
|
||||
void GameWorldView::initializeGL()
|
||||
@@ -137,31 +150,13 @@ void GameWorldView::onFrame()
|
||||
}
|
||||
}
|
||||
|
||||
// Drain fire events → active beams
|
||||
// Emit fire events via EventManager
|
||||
{
|
||||
const std::vector<FireEvent> fires = m_sim->drainFireEvents();
|
||||
for (const FireEvent& fe : fires)
|
||||
const std::vector<WeaponFiredEvent> fires = m_sim->drainWeaponFiredEvents();
|
||||
for (const WeaponFiredEvent& fe : fires)
|
||||
{
|
||||
float maxRadius = 0.125f;
|
||||
if (m_sim->admin().isValid(fe.target)
|
||||
&& m_sim->admin().hasAll<StationBodyComponent>(fe.target))
|
||||
{
|
||||
const StationBodyComponent& sb = m_sim->admin().get<StationBodyComponent>(fe.target);
|
||||
const int shorter = std::min(sb.footprint.width(), sb.footprint.height());
|
||||
maxRadius = shorter / 2.0f;
|
||||
}
|
||||
|
||||
std::uniform_real_distribution<float> angleDist(0.0f, 6.28318530f);
|
||||
std::uniform_real_distribution<float> radiusDist(0.0f, maxRadius);
|
||||
const float angle = angleDist(m_rng);
|
||||
const float radius = radiusDist(m_rng);
|
||||
|
||||
ActiveBeam beam;
|
||||
beam.event = fe;
|
||||
beam.emittedWallMs = m_wallMs;
|
||||
beam.targetOffset = QVector2D(radius * std::cos(angle),
|
||||
radius * std::sin(angle));
|
||||
m_activeBeams.push_back(beam);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<WeaponFiredEvent>(fe));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +227,8 @@ void GameWorldView::onFrame()
|
||||
{
|
||||
m_gameOverShown = true;
|
||||
m_gameSpeedMultiplier = 0.0;
|
||||
emit gameOver();
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<GameOverEvent>());
|
||||
}
|
||||
|
||||
update();
|
||||
@@ -1140,7 +1136,8 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
|
||||
}
|
||||
break;
|
||||
case Qt::Key_Escape:
|
||||
emit escapeMenuRequested();
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<EscapeMenuRequestedEvent>());
|
||||
break;
|
||||
case Qt::Key_Backspace:
|
||||
toggleDemolishMode();
|
||||
@@ -1227,7 +1224,8 @@ void GameWorldView::mousePressEvent(QMouseEvent* event)
|
||||
if (hitEntity != entt::null)
|
||||
{
|
||||
m_selectedBuildingIds.clear();
|
||||
emit selectionChanged(m_selectedBuildingIds);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<SelectionChangedEvent>(m_selectedBuildingIds));
|
||||
m_selectedEntity = hitEntity;
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<EntitySelectedEvent>(hitEntity));
|
||||
@@ -1264,14 +1262,16 @@ void GameWorldView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
m_selectedBuildingIds = { id };
|
||||
}
|
||||
emit selectionChanged(m_selectedBuildingIds);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<SelectionChangedEvent>(m_selectedBuildingIds));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(event->modifiers() & Qt::ControlModifier))
|
||||
{
|
||||
m_selectedBuildingIds.clear();
|
||||
emit selectionChanged(m_selectedBuildingIds);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<SelectionChangedEvent>(m_selectedBuildingIds));
|
||||
}
|
||||
m_boxSelecting = true;
|
||||
m_boxStartTile = tile;
|
||||
@@ -1370,12 +1370,13 @@ void GameWorldView::mouseReleaseEvent(QMouseEvent* event)
|
||||
if (!found) { m_selectedBuildingIds.push_back(id); }
|
||||
}
|
||||
}
|
||||
emit selectionChanged(m_selectedBuildingIds);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<SelectionChangedEvent>(m_selectedBuildingIds));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Slots
|
||||
// Methods (formerly slots)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void GameWorldView::toggleDemolishMode()
|
||||
@@ -1391,7 +1392,8 @@ void GameWorldView::toggleDemolishMode()
|
||||
if (m_blueprintMode.has_value()) { exitBlueprintMode(); }
|
||||
m_demolishMode = true;
|
||||
}
|
||||
emit demolishModeChanged(m_demolishMode);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<DemolishModeChangedEvent>(m_demolishMode));
|
||||
}
|
||||
|
||||
void GameWorldView::enterBuilderMode(BuildingType type)
|
||||
@@ -1401,14 +1403,16 @@ void GameWorldView::enterBuilderMode(BuildingType type)
|
||||
m_ghostValid = false;
|
||||
m_demolishMode = false;
|
||||
m_blueprintMode.reset();
|
||||
emit demolishModeChanged(false);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<DemolishModeChangedEvent>(false));
|
||||
}
|
||||
|
||||
void GameWorldView::enterBlueprintMode(Blueprint blueprint)
|
||||
{
|
||||
if (m_builderType.has_value()) { exitBuilderMode(); }
|
||||
m_demolishMode = false;
|
||||
emit demolishModeChanged(false);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<DemolishModeChangedEvent>(false));
|
||||
m_blueprintGhostTile = m_ghostTile;
|
||||
m_blueprintMode = std::move(blueprint);
|
||||
}
|
||||
@@ -1416,7 +1420,8 @@ void GameWorldView::enterBlueprintMode(Blueprint blueprint)
|
||||
void GameWorldView::exitBlueprintMode()
|
||||
{
|
||||
m_blueprintMode.reset();
|
||||
emit blueprintModeExited();
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<BlueprintModeExitedEvent>());
|
||||
}
|
||||
|
||||
void GameWorldView::exitBuilderMode()
|
||||
@@ -1424,7 +1429,8 @@ void GameWorldView::exitBuilderMode()
|
||||
m_builderType.reset();
|
||||
m_beltDragTiles.clear();
|
||||
m_dragging = false;
|
||||
emit builderModeExited();
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<BuilderModeExitedEvent>());
|
||||
}
|
||||
|
||||
double GameWorldView::gameSpeed() const
|
||||
@@ -1454,7 +1460,8 @@ void GameWorldView::resetForNewGame()
|
||||
m_ghostValid = false;
|
||||
m_demolishMode = false;
|
||||
m_demolishHoverBuildingId = kInvalidBuildingId;
|
||||
emit demolishModeChanged(false);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<DemolishModeChangedEvent>(false));
|
||||
m_selectedBuildingIds.clear();
|
||||
m_boxSelecting = false;
|
||||
m_scrollXTiles = 0.0f;
|
||||
@@ -1466,7 +1473,66 @@ void GameWorldView::resetForNewGame()
|
||||
m_lastBlocks = -1;
|
||||
m_lastBossCounter = -1;
|
||||
m_lastBossCountdown = Tick(-1);
|
||||
emit selectionChanged({});
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<SelectionChangedEvent>(std::vector<BuildingId>{}));
|
||||
setGameSpeed(1.0);
|
||||
update();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Event handlers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const WeaponFiredEvent> event)
|
||||
{
|
||||
float maxRadius = 0.125f;
|
||||
if (m_sim->admin().isValid(event->target)
|
||||
&& m_sim->admin().hasAll<StationBodyComponent>(event->target))
|
||||
{
|
||||
const StationBodyComponent& sb = m_sim->admin().get<StationBodyComponent>(event->target);
|
||||
const int shorter = std::min(sb.footprint.width(), sb.footprint.height());
|
||||
maxRadius = shorter / 2.0f;
|
||||
}
|
||||
|
||||
std::uniform_real_distribution<float> angleDist(0.0f, 6.28318530f);
|
||||
std::uniform_real_distribution<float> radiusDist(0.0f, maxRadius);
|
||||
const float angle = angleDist(m_rng);
|
||||
const float radius = radiusDist(m_rng);
|
||||
|
||||
ActiveBeam beam;
|
||||
beam.event = *event;
|
||||
beam.emittedWallMs = m_wallMs;
|
||||
beam.targetOffset = QVector2D(radius * std::cos(angle),
|
||||
radius * std::sin(angle));
|
||||
m_activeBeams.push_back(beam);
|
||||
}
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const BuildingTypeSelectedEvent> event)
|
||||
{
|
||||
enterBuilderMode(event->type);
|
||||
}
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const ExitBuilderModeRequestedEvent> /*event*/)
|
||||
{
|
||||
exitBuilderMode();
|
||||
}
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const DemolishModeToggleRequestedEvent> /*event*/)
|
||||
{
|
||||
toggleDemolishMode();
|
||||
}
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const BlueprintPlacementRequestedEvent> event)
|
||||
{
|
||||
enterBlueprintMode(event->blueprint);
|
||||
}
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const ExitBlueprintModeRequestedEvent> /*event*/)
|
||||
{
|
||||
exitBlueprintMode();
|
||||
}
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const SpeedChangeRequestedEvent> event)
|
||||
{
|
||||
setGameSpeed(event->multiplier);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,20 @@
|
||||
#include <QVector2D>
|
||||
|
||||
#include "Blueprint.h"
|
||||
#include "SchematicChoiceOption.h"
|
||||
#include "BlueprintModeExitedEvent.h"
|
||||
#include "BlueprintPlacementRequestedEvent.h"
|
||||
#include "BuilderModeExitedEvent.h"
|
||||
#include "BuildingType.h"
|
||||
#include "BuildingTypeSelectedEvent.h"
|
||||
#include "BuildingId.h"
|
||||
#include "FireEvent.h"
|
||||
#include "DemolishModeChangedEvent.h"
|
||||
#include "DemolishModeToggleRequestedEvent.h"
|
||||
#include "EventHandler.h"
|
||||
#include "ExitBlueprintModeRequestedEvent.h"
|
||||
#include "ExitBuilderModeRequestedEvent.h"
|
||||
#include "WeaponFiredEvent.h"
|
||||
#include "SchematicChoiceOption.h"
|
||||
#include "SpeedChangeRequestedEvent.h"
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
#include "EntitySelectedEvent.h"
|
||||
@@ -38,32 +48,24 @@ struct QPointCompare
|
||||
}
|
||||
};
|
||||
|
||||
class GameWorldView : public QOpenGLWidget
|
||||
class GameWorldView : public QOpenGLWidget,
|
||||
public CombinedEventHandler<WeaponFiredEvent,
|
||||
BuildingTypeSelectedEvent,
|
||||
ExitBuilderModeRequestedEvent,
|
||||
DemolishModeToggleRequestedEvent,
|
||||
BlueprintPlacementRequestedEvent,
|
||||
ExitBlueprintModeRequestedEvent,
|
||||
SpeedChangeRequestedEvent>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GameWorldView(Simulation* sim, const GameConfig* config,
|
||||
const VisualsConfig* visuals, QWidget* parent = nullptr);
|
||||
~GameWorldView() override;
|
||||
|
||||
signals:
|
||||
void selectionChanged(const std::vector<BuildingId>& ids);
|
||||
void gameOver();
|
||||
void builderModeExited();
|
||||
void blueprintModeExited();
|
||||
void escapeMenuRequested();
|
||||
void demolishModeChanged(bool active);
|
||||
|
||||
public:
|
||||
double gameSpeed() const;
|
||||
void resetFrameTimer();
|
||||
|
||||
public slots:
|
||||
void enterBuilderMode(BuildingType type);
|
||||
void exitBuilderMode();
|
||||
void enterBlueprintMode(Blueprint blueprint);
|
||||
void exitBlueprintMode();
|
||||
void toggleDemolishMode();
|
||||
void setGameSpeed(double multiplier);
|
||||
void resetForNewGame();
|
||||
|
||||
@@ -80,6 +82,14 @@ private slots:
|
||||
void onFrame();
|
||||
|
||||
private:
|
||||
void handleEvent(std::shared_ptr<const WeaponFiredEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const BuildingTypeSelectedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const ExitBuilderModeRequestedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const DemolishModeToggleRequestedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const BlueprintPlacementRequestedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const ExitBlueprintModeRequestedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const SpeedChangeRequestedEvent> event) override;
|
||||
|
||||
void drawTiles(QPainter& painter);
|
||||
void drawBuildings(QPainter& painter);
|
||||
void drawStations(QPainter& painter);
|
||||
@@ -119,9 +129,15 @@ private:
|
||||
void stepSpeed(int delta);
|
||||
void placeAtTile(QPoint tile);
|
||||
|
||||
void enterBuilderMode(BuildingType type);
|
||||
void exitBuilderMode();
|
||||
void enterBlueprintMode(Blueprint blueprint);
|
||||
void exitBlueprintMode();
|
||||
void toggleDemolishMode();
|
||||
|
||||
struct ActiveBeam
|
||||
{
|
||||
FireEvent event;
|
||||
WeaponFiredEvent event;
|
||||
qint64 emittedWallMs;
|
||||
QVector2D targetOffset;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <QPushButton>
|
||||
#include <QSignalMapper>
|
||||
|
||||
#include "EventManager.h"
|
||||
#include "SpeedChangeRequestedEvent.h"
|
||||
#include "Tick.h"
|
||||
|
||||
const double HeaderBar::kSpeeds[] = { 0.0, 0.5, 1.0, 2.0, 10.0 };
|
||||
@@ -90,6 +92,7 @@ void HeaderBar::onSpeedButton(int index)
|
||||
{
|
||||
if (index >= 0 && index < kSpeedCount)
|
||||
{
|
||||
emit speedChanged(kSpeeds[index]);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<SpeedChangeRequestedEvent>(kSpeeds[index]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,6 @@ public:
|
||||
explicit HeaderBar(QWidget* parent = nullptr);
|
||||
~HeaderBar() override;
|
||||
|
||||
signals:
|
||||
void speedChanged(double multiplier);
|
||||
|
||||
private slots:
|
||||
void onSpeedButton(int index);
|
||||
|
||||
|
||||
@@ -53,52 +53,6 @@ MainWindow::MainWindow(Simulation* sim, const std::string& configDir, QWidget* p
|
||||
bottomLayout->addWidget(m_buildButtonGrid, 1);
|
||||
bottomLayout->addWidget(m_blueprintPanel, 1);
|
||||
|
||||
// Signals: game world → other panels
|
||||
connect(m_gameWorldView, &GameWorldView::selectionChanged,
|
||||
m_selectedBuildingPanel, &SelectedBuildingPanel::onSelectionChanged);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::gameOver,
|
||||
this, &MainWindow::onGameOver);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::escapeMenuRequested,
|
||||
this, &MainWindow::onEscapeMenuRequested);
|
||||
|
||||
connect(m_selectedBuildingPanel, &SelectedBuildingPanel::layoutDialogRequested,
|
||||
this, &MainWindow::onLayoutDialogRequested);
|
||||
|
||||
// Signals: build grid → game world
|
||||
connect(m_buildButtonGrid, &BuildButtonGrid::buildingTypeSelected,
|
||||
m_gameWorldView, &GameWorldView::enterBuilderMode);
|
||||
|
||||
connect(m_buildButtonGrid, &BuildButtonGrid::builderModeExited,
|
||||
m_gameWorldView, &GameWorldView::exitBuilderMode);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::builderModeExited,
|
||||
m_buildButtonGrid, &BuildButtonGrid::clearActiveButton);
|
||||
|
||||
connect(m_buildButtonGrid, &BuildButtonGrid::demolishModeToggleRequested,
|
||||
m_gameWorldView, &GameWorldView::toggleDemolishMode);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::demolishModeChanged,
|
||||
m_buildButtonGrid, &BuildButtonGrid::setDemolishModeActive);
|
||||
|
||||
// Signals: blueprint panel ↔ game world
|
||||
connect(m_gameWorldView, &GameWorldView::selectionChanged,
|
||||
m_blueprintPanel, &BlueprintPanel::onSelectionChanged);
|
||||
|
||||
connect(m_blueprintPanel, &BlueprintPanel::blueprintPlacementRequested,
|
||||
m_gameWorldView, &GameWorldView::enterBlueprintMode);
|
||||
|
||||
connect(m_blueprintPanel, &BlueprintPanel::exitBlueprintModeRequested,
|
||||
m_gameWorldView, &GameWorldView::exitBlueprintMode);
|
||||
|
||||
connect(m_gameWorldView, &GameWorldView::blueprintModeExited,
|
||||
m_blueprintPanel, &BlueprintPanel::clearActiveBlueprintButton);
|
||||
|
||||
// Signals: header bar → game world
|
||||
connect(m_headerBar, &HeaderBar::speedChanged,
|
||||
m_gameWorldView, &GameWorldView::setGameSpeed);
|
||||
|
||||
m_gameWorldView->setFocus();
|
||||
|
||||
connect(qApp, &QApplication::focusChanged, this, [this](QWidget*, QWidget* newWidget) {
|
||||
@@ -191,7 +145,7 @@ void MainWindow::handleEvent(std::shared_ptr<const SchematicChoicesAvailableEven
|
||||
m_gameWorldView->resetFrameTimer();
|
||||
}
|
||||
|
||||
void MainWindow::onEscapeMenuRequested()
|
||||
void MainWindow::handleEvent(std::shared_ptr<const EscapeMenuRequestedEvent> /*event*/)
|
||||
{
|
||||
const double prevSpeed = m_gameWorldView->gameSpeed();
|
||||
m_gameWorldView->setGameSpeed(0.0);
|
||||
@@ -235,12 +189,12 @@ void MainWindow::onEscapeMenuRequested()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onLayoutDialogRequested(BuildingId shipyardId)
|
||||
void MainWindow::handleEvent(std::shared_ptr<const LayoutDialogRequestedEvent> event)
|
||||
{
|
||||
const double prevSpeed = m_gameWorldView->gameSpeed();
|
||||
m_gameWorldView->setGameSpeed(0.0);
|
||||
|
||||
const Building* b = m_sim->buildings().findBuilding(shipyardId);
|
||||
const Building* b = m_sim->buildings().findBuilding(event->shipyardId);
|
||||
if (!b)
|
||||
{
|
||||
m_gameWorldView->setGameSpeed(prevSpeed);
|
||||
@@ -272,14 +226,14 @@ void MainWindow::onLayoutDialogRequested(BuildingId shipyardId)
|
||||
this);
|
||||
if (dialog.exec() == QDialog::Accepted && dialog.result().has_value())
|
||||
{
|
||||
m_sim->buildings().setShipLayout(shipyardId, *dialog.result());
|
||||
m_sim->buildings().setShipLayout(event->shipyardId, *dialog.result());
|
||||
}
|
||||
|
||||
m_gameWorldView->setGameSpeed(prevSpeed);
|
||||
m_gameWorldView->resetFrameTimer();
|
||||
}
|
||||
|
||||
void MainWindow::onGameOver()
|
||||
void MainWindow::handleEvent(std::shared_ptr<const GameOverEvent> /*event*/)
|
||||
{
|
||||
const Tick tick = m_sim->currentTick();
|
||||
const int totalSeconds = static_cast<int>(ticksToSeconds(tick));
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
|
||||
#include "BuildingBlocksChangedEvent.h"
|
||||
#include "BuildingId.h"
|
||||
#include "EscapeMenuRequestedEvent.h"
|
||||
#include "EventHandler.h"
|
||||
#include "GameOverEvent.h"
|
||||
#include "LayoutDialogRequestedEvent.h"
|
||||
#include "SchematicChoicesAvailableEvent.h"
|
||||
#include "ShipLayoutBlueprint.h"
|
||||
#include "Tick.h"
|
||||
@@ -24,7 +27,10 @@ class QResizeEvent;
|
||||
|
||||
class MainWindow : public QWidget,
|
||||
public CombinedEventHandler<BuildingBlocksChangedEvent,
|
||||
SchematicChoicesAvailableEvent>
|
||||
SchematicChoicesAvailableEvent,
|
||||
GameOverEvent,
|
||||
EscapeMenuRequestedEvent,
|
||||
LayoutDialogRequestedEvent>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -39,13 +45,11 @@ protected:
|
||||
private:
|
||||
void handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const SchematicChoicesAvailableEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const GameOverEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const EscapeMenuRequestedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const LayoutDialogRequestedEvent> event) override;
|
||||
void layoutPanels();
|
||||
|
||||
private slots:
|
||||
void onGameOver();
|
||||
void onEscapeMenuRequested();
|
||||
void onLayoutDialogRequested(BuildingId shipyardId);
|
||||
|
||||
private:
|
||||
std::string m_configDir;
|
||||
VisualsConfig m_visuals;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "DynamicBodyComponent.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "EntitySelectedEvent.h"
|
||||
#include "EventManager.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "ModuleOwnerComponent.h"
|
||||
@@ -28,6 +29,7 @@
|
||||
#include "BuildingSystem.h"
|
||||
#include "BuildingType.h"
|
||||
#include "ItemType.h"
|
||||
#include "LayoutDialogRequestedEvent.h"
|
||||
#include "ModulesConfig.h"
|
||||
#include "Rotation.h"
|
||||
#include "ShipLayoutPreview.h"
|
||||
@@ -139,7 +141,8 @@ SelectedBuildingPanel::SelectedBuildingPanel(Simulation* sim,
|
||||
connect(m_configureLayoutBtn, &QPushButton::clicked, this, [this]() {
|
||||
if (m_singleBuildingId != kInvalidBuildingId)
|
||||
{
|
||||
emit layoutDialogRequested(m_singleBuildingId);
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<LayoutDialogRequestedEvent>(m_singleBuildingId));
|
||||
}
|
||||
});
|
||||
connect(m_filterAList, &QListWidget::itemChanged,
|
||||
@@ -861,3 +864,8 @@ void SelectedBuildingPanel::clearEntityDisplay()
|
||||
m_entityStatsPanel->hide();
|
||||
m_stationStatsLabel->hide();
|
||||
}
|
||||
|
||||
void SelectedBuildingPanel::handleEvent(std::shared_ptr<const SelectionChangedEvent> event)
|
||||
{
|
||||
onSelectionChanged(event->ids);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "EventHandler.h"
|
||||
#include "GameConfig.h"
|
||||
#include "RecipesConfig.h"
|
||||
#include "SelectionChangedEvent.h"
|
||||
#include "ShipLayout.h"
|
||||
#include "ShipsConfig.h"
|
||||
#include "Tick.h"
|
||||
@@ -30,7 +31,9 @@ class QPushButton;
|
||||
class QVBoxLayout;
|
||||
|
||||
class SelectedBuildingPanel : public QWidget,
|
||||
public CombinedEventHandler<TickAdvancedEvent, EntitySelectedEvent>
|
||||
public CombinedEventHandler<TickAdvancedEvent,
|
||||
EntitySelectedEvent,
|
||||
SelectionChangedEvent>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -39,15 +42,10 @@ public:
|
||||
QWidget* parent = nullptr);
|
||||
~SelectedBuildingPanel() override;
|
||||
|
||||
signals:
|
||||
void layoutDialogRequested(BuildingId shipyardId);
|
||||
|
||||
public slots:
|
||||
void onSelectionChanged(const std::vector<BuildingId>& ids);
|
||||
|
||||
private:
|
||||
void handleEvent(std::shared_ptr<const TickAdvancedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const EntitySelectedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const SelectionChangedEvent> event) override;
|
||||
|
||||
private slots:
|
||||
void onRecipeChanged(int comboIndex);
|
||||
@@ -55,6 +53,7 @@ private slots:
|
||||
void onSplitterFilterChanged();
|
||||
|
||||
private:
|
||||
void onSelectionChanged(const std::vector<BuildingId>& ids);
|
||||
void rebuild();
|
||||
void clearContent();
|
||||
void buildEmpty();
|
||||
|
||||
Reference in New Issue
Block a user