#include "mainmenu.h" #include "widgets/pushbutton.h" #include "widgets/group.h" MainMenu::MainMenu(sf::RenderWindow& game_window, Callbacks&& callbacks, const FontHolder& font_holder) : _buttons(std::make_shared()), _game_window(game_window) { const float window_width = game_window.getSize().x; const float window_height = game_window.getSize().y; auto button_start = std::make_shared("Start", font_holder.get(Fonts::Id::GUI), 48); button_start->setRect(sf::FloatRect(window_width / 3., window_height / 7., window_width / 3., window_height / 7.)); button_start->setCallback(callbacks.onAppendGameState); auto button_editor = std::make_shared("Editor", font_holder.get(Fonts::Id::GUI), 48); button_editor->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 3, window_width / 3., window_height / 7.)); button_editor->setCallback(callbacks.onAppendEditorState); auto button_exit = std::make_shared("Exit", font_holder.get(Fonts::Id::GUI), 48); button_exit->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 5, window_width / 3., window_height / 7.)); button_exit->setCallback([&]() { _game_window.close(); }); _buttons->addChild(button_start); _buttons->addChild(button_editor); _buttons->addChild(button_exit); } void MainMenu::input(const sf::Event& event) { _buttons->input(event); } void MainMenu::update(const sf::Time& dt) { _buttons->update(dt); } void MainMenu::draw() const { _game_window.draw(*_buttons); } void MainMenu::enter() { _buttons->setVisibility(); } void MainMenu::leave() { _buttons->setVisibility(false); }