project-kyoku/src/application/editorstate.cpp

115 lines
3.5 KiB
C++
Raw Normal View History

2021-10-05 20:48:28 +02:00
#include "editorstate.h"
2021-08-12 21:10:52 +02:00
#include "widgets/button.h"
#include "widgets/group.h"
2021-08-16 20:54:03 +02:00
#include "widgets/menubar.h"
#include "widgets/window.h"
#include "widgets/editorwidget.h"
#include "widgets/bpmcalculatorwidget.h"
2021-08-12 21:10:52 +02:00
#include "tools/bpmcalculator.h"
#include <iostream>
2021-10-05 20:48:28 +02:00
EditorState::EditorState(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music, const FontHolder& font_holder) :
_font(font_holder.get(Fonts::Id::GUI)),
2021-08-12 21:10:52 +02:00
_game_window(game_window),
_callbacks(std::move(callbacks)),
_music(std::move(music))
{}
2021-10-05 20:48:28 +02:00
void EditorState::input(const sf::Event& event)
{
_group->input(event);
}
2021-10-05 20:48:28 +02:00
void EditorState::update(const sf::Time& dt)
{
_group->update(dt);
}
2021-10-05 20:48:28 +02:00
void EditorState::draw() const
{
_game_window.draw(*_group);
}
2021-10-05 20:48:28 +02:00
void EditorState::enter()
2021-08-12 21:10:52 +02:00
{
auto& group = _group;
auto& music = _music;
_music->openFromFile("Uta-test.flac");
_music->setVolume(5);
_bpm_calculator = std::make_shared<BPMCalculator>(_music);
std::shared_ptr<BPMCalculatorWidget> bpm_widget = std::make_shared<BPMCalculatorWidget>(_bpm_calculator, _font);
bpm_widget->init();
const auto bpm_widget_callback = [&group, bpm_widget=bpm_widget, &music]()
{
music->stop();
bpm_widget->setVisibility(false);
group->unblock();
};
const float window_width = _game_window.getSize().x;
2021-08-12 21:10:52 +02:00
auto menu_bar = std::make_shared<MenuBar>(_font);
2021-08-26 19:41:16 +02:00
auto bpm_button = std::make_shared<PushButton>("Calculate BPM", _font);
bpm_button->setCallback([&group, bpm_widget=bpm_widget]()
{
group->blockBy(bpm_widget);
bpm_widget->setVisibility(true);
});
bpm_widget->setRect(sf::FloatRect(_game_window.getSize().x / 3, _game_window.getSize().y / 3, _game_window.getSize().x / 3, _game_window.getSize().y / 3));
bpm_widget->addBarButton("X", bpm_widget_callback);
bpm_widget->setVisibility(false);
2021-08-26 20:22:19 +02:00
auto test_menu_2 = std::make_shared<MenuDrop>();
test_menu_2->setRect(sf::FloatRect{0, 0, 200, 27 * 5});
auto test_menu_3 = std::make_shared<MenuDrop>();
test_menu_3->setRect(sf::FloatRect{0, 0, 200, 27 * 5});
auto test_cascade_button = std::make_shared<CascadeMenuButton>("Show submenu", _font);
2021-08-26 20:22:19 +02:00
auto test_cascade_button_2 = std::make_shared<CascadeMenuButton>("Show submenu 2", _font);
auto quit_button = std::make_shared<PushButton>("Quit", _font);
quit_button->setCallback(_callbacks.onLeaveEditorState);
auto test_menu = std::make_shared<MenuDrop>();
2021-08-26 20:22:19 +02:00
test_menu->setRect(sf::FloatRect{0, 0, 200, 27 * 3});
menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27));
menu_bar->addRootSubMenu("test", test_menu);
menu_bar->addDependentSubmenu(test_menu_2);
menu_bar->addDependentSubmenu(test_menu_3);
2021-08-26 20:22:19 +02:00
test_cascade_button->setSubmenu(test_menu_2);
test_menu->addPushButton(bpm_button);
2021-08-26 20:22:19 +02:00
test_menu->addCascadeButton(test_cascade_button);
test_menu->addPushButton(quit_button);
test_cascade_button->resetRect();
2021-08-26 20:22:19 +02:00
test_cascade_button_2->setSubmenu(test_menu_3);
test_menu_2->addCascadeButton(test_cascade_button_2);
test_cascade_button_2->resetRect();
menu_bar->setVisibility(true);
//auto editor_widget = std::make_unique<EditorWidget>(_edito)
_group = std::make_shared<Group>();
_group->addChild(menu_bar);
_group->addChild(bpm_widget);
2021-08-12 21:10:52 +02:00
}
2021-10-05 20:48:28 +02:00
void EditorState::leave()
2021-08-12 21:10:52 +02:00
{
_group.reset();
_bpm_calculator.reset();
2021-08-12 21:10:52 +02:00
}