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-12-27 13:41:25 -05:00
|
|
|
MainMenu::MainMenu(Callbacks&& callbacks, const FontHolder& font_holder) :
|
|
|
|
_font(font_holder.get(Fonts::Id::GUI)),
|
|
|
|
_callbacks(std::move(callbacks)),
|
|
|
|
_buttons(std::make_shared<Group>())
|
2021-07-27 14:18:37 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::input(const sf::Event& event)
|
|
|
|
{
|
|
|
|
_buttons->input(event);
|
|
|
|
}
|
|
|
|
|
2021-08-27 13:40:48 -04:00
|
|
|
void MainMenu::update(const sf::Time& dt)
|
2021-07-27 14:18:37 -04:00
|
|
|
{
|
2021-08-27 13:40:48 -04:00
|
|
|
_buttons->update(dt);
|
2021-07-27 14:18:37 -04:00
|
|
|
}
|
|
|
|
|
2021-12-27 13:41:25 -05:00
|
|
|
void MainMenu::draw(sf::RenderTarget &target, sf::RenderStates states) const
|
2021-08-03 14:42:58 -04:00
|
|
|
{
|
2021-12-27 13:41:25 -05:00
|
|
|
target.draw(*_buttons, states);
|
2021-08-03 14:42:58 -04:00
|
|
|
}
|
|
|
|
|
2021-12-27 13:41:25 -05:00
|
|
|
void MainMenu::enter(sf::Vector2u&& render_size)
|
2021-07-27 14:18:37 -04:00
|
|
|
{
|
2021-12-27 13:41:25 -05:00
|
|
|
const float window_width = render_size.x;
|
|
|
|
const float window_height = render_size.y;
|
|
|
|
|
|
|
|
auto button_start = std::make_shared<PushButton>("Start", _font, 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<PushButton>("Editor", _font, 48);
|
|
|
|
button_editor->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 3, window_width / 3., window_height / 7.));
|
|
|
|
button_editor->setCallback(_callbacks.onAppendEditorState);
|
|
|
|
|
|
|
|
_buttons->addChild(button_start);
|
|
|
|
_buttons->addChild(button_editor);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|