#include "editor.h" #include "widgets/button.h" #include "widgets/group.h" #include "widgets/menubar.h" #include "widgets/bpmcalculatorwidget.h" #include "tools/bpmcalculator.h" #include Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr&& music, const FontHolder& font_holder) : _font(font_holder.get(Fonts::Id::GUI)), _game_window(game_window), _callbacks(std::move(callbacks)), _music(std::move(music)) {} void Editor::input(const sf::Event& event) { _menu_bar->input(event); } void Editor::update(const sf::Time& dt) { _menu_bar->update(dt); _bpm_widget->update(dt); } void Editor::draw() const { _game_window.draw(*_menu_bar); _game_window.draw(*_bpm_widget); } void Editor::enter() { _bpm_calculator = std::make_shared(_music); _bpm_widget = std::make_shared(_bpm_calculator, _font); const float window_width = _game_window.getSize().x; _menu_bar = std::make_shared(_font); auto bpm_button = std::make_shared("Calculate BPM", _font); bpm_button->setCallback([&]() { _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->setVisibility(false); auto test_menu_2 = std::make_shared(); test_menu_2->setRect(sf::FloatRect{0, 0, 200, 27 * 5}); auto test_menu_3 = std::make_shared(); test_menu_3->setRect(sf::FloatRect{0, 0, 200, 27 * 5}); auto test_cascade_button = std::make_shared("Show submenu", _font); auto test_cascade_button_2 = std::make_shared("Show submenu 2", _font); auto quit_button = std::make_shared("Quit", _font); quit_button->setCallback(_callbacks.onLeaveEditorState); auto test_menu = std::make_shared(); test_menu->setRect(sf::FloatRect{0, 0, 200, 27 * 3}); _menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27)); _menu_bar->addSubMenu("test", test_menu); test_cascade_button->setSubmenu(test_menu_2); test_menu->addPushButton(bpm_button); test_menu->addCascadeButton(test_cascade_button); test_menu->addPushButton(quit_button); test_cascade_button->resetRect(); test_cascade_button_2->setSubmenu(test_menu_3); test_menu_2->addCascadeButton(test_cascade_button_2); test_cascade_button_2->resetRect(); _music->openFromFile("Uta-test.flac"); _music->setVolume(5); _menu_bar->setVisibility(true); } void Editor::leave() { _menu_bar.reset(); _bpm_calculator.reset(); _bpm_widget.reset(); }