1
0
mirror of synced 2025-02-08 22:59:41 +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
};
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) {

View File

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

View File

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