project-kyoku/src/gui/mainmenu.cpp

52 lines
1.4 KiB
C++
Raw Normal View History

2021-07-27 14:18:37 -04:00
#include "mainmenu.h"
#include "widgets/pushbutton.h"
2021-07-27 14:18:37 -04:00
#include "widgets/group.h"
2021-08-26 13:41:16 -04:00
MainMenu::MainMenu(sf::RenderWindow& game_window, Callbacks&& callbacks, const FontHolder& font_holder) :
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 13:41:16 -04:00
std::shared_ptr<PushButton> button_start = std::make_shared<PushButton>("Start", font_holder.get(Fonts::Id::GUI), 48);
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 13:41:16 -04:00
std::shared_ptr<PushButton> button_exit = std::make_shared<PushButton>("Exit", font_holder.get(Fonts::Id::GUI), 48);
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(const sf::Time& dt)
2021-07-27 14:18:37 -04:00
{
_buttons->update(dt);
2021-07-27 14:18:37 -04:00
}
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);
}