2021-07-27 14:18:37 -04:00
|
|
|
#include "mainmenu.h"
|
2021-08-26 12:54:30 -04:00
|
|
|
#include "widgets/pushbutton.h"
|
2021-07-27 14:18:37 -04:00
|
|
|
#include "widgets/group.h"
|
|
|
|
|
2021-08-03 14:42:58 -04:00
|
|
|
MainMenu::MainMenu(sf::RenderWindow& game_window, Callbacks&& callbacks) :
|
2021-07-27 14:18:37 -04:00
|
|
|
_buttons(std::make_shared<Group>()),
|
|
|
|
_game_window(game_window)
|
|
|
|
{
|
2021-08-04 15:06:01 -04:00
|
|
|
const float window_width = game_window.getSize().x;
|
|
|
|
const float window_height = game_window.getSize().y;
|
|
|
|
|
2021-08-26 12:54:30 -04:00
|
|
|
std::shared_ptr<PushButton> button_start = std::make_shared<PushButton>("Start");
|
2021-08-04 15:06:01 -04:00
|
|
|
button_start->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 2, window_width / 3., window_height / 7.));
|
2021-08-03 14:42:58 -04:00
|
|
|
button_start->setCallback(callbacks.onAppendGameState);
|
2021-07-27 14:18:37 -04:00
|
|
|
|
2021-08-26 12:54:30 -04:00
|
|
|
std::shared_ptr<PushButton> button_exit = std::make_shared<PushButton>("Exit");
|
2021-08-04 15:06:01 -04:00
|
|
|
button_exit->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 4, window_width / 3., window_height / 7.));
|
2021-07-27 14:18:37 -04:00
|
|
|
button_exit->setCallback([&]()
|
|
|
|
{
|
|
|
|
_game_window.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
_buttons->addChild(button_start);
|
|
|
|
_buttons->addChild(button_exit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::input(const sf::Event& event)
|
|
|
|
{
|
|
|
|
_buttons->input(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::update()
|
|
|
|
{
|
|
|
|
_buttons->update();
|
|
|
|
}
|
|
|
|
|
2021-08-03 14:42:58 -04:00
|
|
|
void MainMenu::draw() const
|
|
|
|
{
|
|
|
|
_game_window.draw(*_buttons);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::enter()
|
2021-07-27 14:18:37 -04:00
|
|
|
{
|
2021-08-03 14:42:58 -04:00
|
|
|
_buttons->setVisibility();
|
2021-07-27 14:18:37 -04:00
|
|
|
}
|
2021-08-03 14:42:58 -04:00
|
|
|
|
|
|
|
void MainMenu::leave()
|
|
|
|
{
|
|
|
|
_buttons->setVisibility(false);
|
|
|
|
}
|
|
|
|
|