#pragma once #include #include #include #include #include "BuilderModeExitedEvent.h" #include "BuildHotkeyPressedEvent.h" #include "BuildingBlocksChangedEvent.h" #include "BuildingType.h" #include "DemolishModeChangedEvent.h" #include "EventHandler.h" #include "GameConfig.h" class QPushButton; class Simulation; class BuildButtonGrid : public QWidget, public CombinedEventHandler { Q_OBJECT public: BuildButtonGrid(Simulation* sim, const GameConfig* config, QWidget* parent = nullptr); ~BuildButtonGrid() override; void clearActiveButton(); private: // Re-evaluates which build buttons are enabled from the current building block // stock (read from the simulation). If the currently selected tool can no longer // be afforded, it exits builder mode so the button does not stay selected. void updateAffordability(); void handleEvent(std::shared_ptr event) override; void handleEvent(std::shared_ptr event) override; void handleEvent(std::shared_ptr event) override; void handleEvent(std::shared_ptr event) override; private slots: void onBuildButton(int index); private: Simulation* m_sim; const GameConfig* m_config; std::vector m_types; std::vector m_buttons; std::map m_costs; std::optional m_activeIndex; QPushButton* m_demolishButton; };