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.

60 lines
1.9 KiB
C++

#include "application/mainmenu.h"
#include "widgets/pushbutton.h"
#include "widgets/group.h"
MainMenu::MainMenu(const std::shared_ptr<kku::CoreFactory>& factory, MainMenu::Callbacks&& callbacks) :
_callbacks(std::move(callbacks)),
_core_factory(factory),
_buttons(std::make_shared<Group>())
{
}
void MainMenu::input(const kku::SystemEvent& event)
{
_buttons->input(event);
}
void MainMenu::update(const kku::microsec& dt)
{
_buttons->update(dt);
}
void MainMenu::display() const
{
_buttons->display();
}
void MainMenu::enter()
{
const auto render_size = _core_factory->getRenderSize();
const float window_width = render_size.first;
const float window_height = render_size.second;
auto button_start = std::make_shared<PushButton>("Start", _core_factory, 48);
button_start->setRect(kku::Area<float>{window_width / 3.f, window_height / 7.f,
window_width / 3.f, window_height / 7.f});
button_start->setCallback(_callbacks.onAppendGameState);
auto button_editor = std::make_shared<PushButton>("Editor", _core_factory, 48);
button_editor->setRect(kku::Area<float>{window_width / 3.f, window_height / 7.f * 3,
window_width / 3.f, window_height / 7.f});
button_editor->setCallback(_callbacks.onAppendEditorState);
auto button_about = std::make_shared<PushButton>("About", _core_factory, 48);
button_about->setRect(kku::Area<float>{window_width / 3.f, window_height / 7.f * 5,
window_width / 3.f, window_height / 7.f});
button_about->setCallback(_callbacks.onAppendAboutState);
_buttons->addChild(button_start);
_buttons->addChild(button_editor);
_buttons->addChild(button_about);
_buttons->setVisibility();
}
void MainMenu::leave()
{
_buttons->setVisibility(false);
}