diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp index a9faad3..04c758e 100644 --- a/src/gui/editor.cpp +++ b/src/gui/editor.cpp @@ -8,18 +8,39 @@ #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), - _music(std::move(music)), - _bpm_calculator(std::make_shared(_music)), - _bpm_widget(std::make_shared(_bpm_calculator, font_holder.get(Fonts::Id::GUI))) + _callbacks(std::move(callbacks)), + _music(std::move(music)) +{} + +void Editor::input(const sf::Event& event) { - (void)callbacks; - const float window_width = game_window.getSize().x; - //const float window_height = game_window.getSize().y; + _menu_bar->input(event); +} - _menu_bar = std::make_shared(font_holder.get(Fonts::Id::GUI)); +void Editor::update(const sf::Time& dt) +{ + _menu_bar->update(dt); + _bpm_widget->update(dt); +} - auto bpm_button = std::make_shared("Play song :)", font_holder.get(Fonts::Id::GUI)); +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); @@ -34,12 +55,12 @@ Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique 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_holder.get(Fonts::Id::GUI)); + auto test_cascade_button = std::make_shared("Show submenu", _font); - auto test_cascade_button_2 = std::make_shared("Show submenu 2", font_holder.get(Fonts::Id::GUI)); + auto test_cascade_button_2 = std::make_shared("Show submenu 2", _font); - auto quit_button = std::make_shared("Quit", font_holder.get(Fonts::Id::GUI)); - quit_button->setCallback(callbacks.onLeaveEditorState); + 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}); @@ -61,32 +82,14 @@ Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique _music->openFromFile("Uta-test.flac"); _music->setVolume(5); -} -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() -{ - _menu_bar->setVisibility(); + _menu_bar->setVisibility(true); } void Editor::leave() { - _menu_bar->setVisibility(false); + _menu_bar.reset(); + _bpm_calculator.reset(); + _bpm_widget.reset(); } diff --git a/src/gui/editor.h b/src/gui/editor.h index 60d4e9a..d698a41 100644 --- a/src/gui/editor.h +++ b/src/gui/editor.h @@ -27,9 +27,12 @@ public: virtual void leave() override; private: + const std::shared_ptr _font; std::shared_ptr _menu_bar; sf::RenderWindow& _game_window; + Callbacks _callbacks; + std::shared_ptr _music; std::shared_ptr _bpm_calculator; std::shared_ptr _bpm_widget; diff --git a/src/gui/widgets/cascademenubutton.cpp b/src/gui/widgets/cascademenubutton.cpp index bdea938..a32b23f 100644 --- a/src/gui/widgets/cascademenubutton.cpp +++ b/src/gui/widgets/cascademenubutton.cpp @@ -61,6 +61,7 @@ void CascadeMenuButton::resetRect() { _submenu->setPosition({_button_content.getPosition().x + _button_content.getSize().x, _button_content.getPosition().y}); + _submenu->setVisibility(false); } } diff --git a/src/gui/widgets/menubar.cpp b/src/gui/widgets/menubar.cpp index 2378959..c123bd2 100644 --- a/src/gui/widgets/menubar.cpp +++ b/src/gui/widgets/menubar.cpp @@ -3,6 +3,7 @@ MenuBar::MenuBar(const std::shared_ptr& font) : _font(font), + _amount_buttons(0), _button_width(170) { _bar_rect.setFillColor(sf::Color(88, 57, 107)); diff --git a/src/gui/widgets/menudrop.cpp b/src/gui/widgets/menudrop.cpp index 0851299..0c736fb 100644 --- a/src/gui/widgets/menudrop.cpp +++ b/src/gui/widgets/menudrop.cpp @@ -6,7 +6,7 @@ MenuDrop::MenuDrop() : _button_height(27), _button_index(0) { - setVisibility(false); + _is_visible = false; _content_rect.setFillColor(sf::Color(200, 200, 200)); } @@ -87,9 +87,10 @@ void MenuDrop::addPushButton(const std::shared_ptr& button) void MenuDrop::addCascadeButton(const std::shared_ptr& button) { auto& submenu = button->submenu(); - submenu->setParent(_parent); _submenus.emplace_back(submenu); add(button); + + submenu->setParent(_parent); } void MenuDrop::addSeparator() diff --git a/src/gui/widgets/pushbutton.cpp b/src/gui/widgets/pushbutton.cpp index 2954cc0..ec0f40c 100644 --- a/src/gui/widgets/pushbutton.cpp +++ b/src/gui/widgets/pushbutton.cpp @@ -1,4 +1,5 @@ #include "pushbutton.h" +#include PushButton::PushButton(const std::string& text, const std::shared_ptr &font, unsigned int font_size) : Button(text, font, font_size),