1
0
mirror of synced 2025-02-13 00:44:28 +01:00

Allow exiting MusicSelect::Screen without a chart selected

This commit is contained in:
Stepland 2020-04-30 11:11:23 +02:00
parent 9f9669e1aa
commit ebf5c08b05
3 changed files with 13 additions and 5 deletions

View File

@ -38,7 +38,11 @@ int main(int, char const **) {
settings settings
}; };
auto chart = music_select.select_chart(window); auto chart = music_select.select_chart(window);
std::cout << "Selected Chart : " << chart.song.title << " [" << chart.difficulty << "]" << std::endl; if (chart) {
std::cout << "Selected Chart : " << chart->song.title << " [" << chart->difficulty << "]" << std::endl;
} else {
std::cout << "Exited MusicSelect::Screen without selecting a chart" << std::endl;
}
/* /*
while (true) { while (true) {

View File

@ -27,7 +27,7 @@ MusicSelect::Screen::Screen(const Data::SongList& t_song_list, SharedResources&
std::cout << "loaded MusicSelect::Screen" << std::endl; std::cout << "loaded MusicSelect::Screen" << std::endl;
} }
Data::SongDifficulty MusicSelect::Screen::select_chart(sf::RenderWindow& window) { std::optional<Data::SongDifficulty> MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
window.setFramerateLimit(60); window.setFramerateLimit(60);
ImGui::SFML::Init(window); ImGui::SFML::Init(window);
sf::Clock imguiClock; sf::Clock imguiClock;
@ -94,8 +94,11 @@ Data::SongDifficulty MusicSelect::Screen::select_chart(sf::RenderWindow& window)
resources.music_preview.update(); resources.music_preview.update();
} }
ImGui::SFML::Shutdown(); ImGui::SFML::Shutdown();
assert((resources.selected_panel.has_value())); if (resources.selected_panel) {
return *resources.selected_panel->obj.get_selected_difficulty(); return resources.selected_panel->obj.get_selected_difficulty();
} else {
return {};
}
} }
void MusicSelect::Screen::draw_debug() { void MusicSelect::Screen::draw_debug() {

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <map> #include <map>
#include <optional>
#include <stack> #include <stack>
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
@ -29,7 +30,7 @@ namespace MusicSelect {
const Data::SongList& t_song_list, const Data::SongList& t_song_list,
SharedResources& t_resources SharedResources& t_resources
); );
Data::SongDifficulty select_chart(sf::RenderWindow& window); std::optional<Data::SongDifficulty> select_chart(sf::RenderWindow& window);
void draw_debug() override; void draw_debug() override;
private: private:
const Data::SongList song_list; const Data::SongList song_list;