diff --git a/include/application.h b/include/application.h index fe72d4c..52dc57f 100644 --- a/include/application.h +++ b/include/application.h @@ -27,7 +27,8 @@ private: std::shared_ptr _game; void exec(); - void emplaceState(GUIState::Tag new_state); + void pushState(GUIState::Tag new_state); + void popState(); }; #endif // APPLICATION_H diff --git a/src/application.cpp b/src/application.cpp index 1a1e75f..c53d90b 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -23,11 +23,12 @@ Application::Application() : _game_window.setMouseCursorGrabbed(false); _game_window.setVerticalSyncEnabled(true); - MainMenu::Callbacks callbacks = {[&](){ emplaceState(GUIState::Tag::EDITOR); }}; + MainMenu::Callbacks callbacks = {[&](){ pushState(GUIState::Tag::EDITOR); }}; + Editor::Callbacks editor_callbacks = {[&](){ popState(); }}; const auto main_menu = std::make_shared(_game_window, std::move(callbacks)); const auto game_state = std::make_shared(_game_window, _game, GameState::Callbacks()); - const auto editor = std::make_shared(_game_window, Editor::Callbacks(), std::make_unique()); + const auto editor = std::make_shared(_game_window, std::move(editor_callbacks), std::make_unique()); _states[GUIState::Tag::MAIN_MENU] = main_menu; _states[GUIState::Tag::GAME] = game_state; _states[GUIState::Tag::EDITOR] = editor; @@ -95,9 +96,16 @@ void Application::draw() _game_window.display(); } -void Application::emplaceState(GUIState::Tag new_state) +void Application::pushState(GUIState::Tag new_state) { _state_stack.back()->leave(); _state_stack.emplace_back(_states.at(new_state)); _state_stack.back()->enter(); } + +void Application::popState() +{ + _state_stack.back()->leave(); + _state_stack.pop_back(); + _state_stack.back()->enter(); +} diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp index 2941975..64e85c0 100644 --- a/src/gui/editor.cpp +++ b/src/gui/editor.cpp @@ -16,7 +16,26 @@ Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique const float window_width = game_window.getSize().x; //const float window_height = game_window.getSize().y; + auto bpm_button = std::make_shared("Calculate BPM"); + bpm_button->setCallback([&]() + { + _bpm_calculator->startListening(0); + }); + + auto quit_button = std::make_shared("Quit"); + quit_button->setCallback(callbacks.onLeaveEditorState); + + auto test_menu = std::make_shared(); + test_menu->setRect(sf::FloatRect{0, 0, 200, 27}); + _menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27)); + _menu_bar->addSubMenu("test", test_menu); + + test_menu->addPushButton(bpm_button); + test_menu->addPushButton(quit_button); + + _music->openFromFile("Uta-test.flac"); + _music->setVolume(5); } void Editor::input(const sf::Event& event) diff --git a/src/gui/editor.h b/src/gui/editor.h index 8f1e17d..e99c4e2 100644 --- a/src/gui/editor.h +++ b/src/gui/editor.h @@ -14,7 +14,7 @@ public: struct Callbacks { - std::function onAppendGameState; + std::function onLeaveEditorState; }; explicit Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr&& music); diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index 78226db..21e3616 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -1,5 +1,5 @@ #include "mainmenu.h" -#include "widgets/button.h" +#include "widgets/pushbutton.h" #include "widgets/group.h" MainMenu::MainMenu(sf::RenderWindow& game_window, Callbacks&& callbacks) : @@ -9,11 +9,11 @@ MainMenu::MainMenu(sf::RenderWindow& game_window, Callbacks&& callbacks) : const float window_width = game_window.getSize().x; const float window_height = game_window.getSize().y; - std::shared_ptr