forked from NaiJi/project-kyoku
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#include "mainmenu.h"
|
|
#include "widgets/pushbutton.h"
|
|
#include "widgets/group.h"
|
|
|
|
MainMenu::MainMenu(sf::RenderWindow& game_window, Callbacks&& callbacks) :
|
|
_buttons(std::make_shared<Group>()),
|
|
_game_window(game_window)
|
|
{
|
|
const float window_width = game_window.getSize().x;
|
|
const float window_height = game_window.getSize().y;
|
|
|
|
std::shared_ptr<PushButton> button_start = std::make_shared<PushButton>("Start");
|
|
button_start->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 2, window_width / 3., window_height / 7.));
|
|
button_start->setCallback(callbacks.onAppendGameState);
|
|
|
|
std::shared_ptr<PushButton> button_exit = std::make_shared<PushButton>("Exit");
|
|
button_exit->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 4, window_width / 3., window_height / 7.));
|
|
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();
|
|
}
|
|
|
|
void MainMenu::draw() const
|
|
{
|
|
_game_window.draw(*_buttons);
|
|
}
|
|
|
|
void MainMenu::enter()
|
|
{
|
|
_buttons->setVisibility();
|
|
}
|
|
|
|
void MainMenu::leave()
|
|
{
|
|
_buttons->setVisibility(false);
|
|
}
|
|
|