Show quit game prompt when attempting to close window (#13)

This commit is contained in:
thecozies 2024-04-30 09:30:39 -05:00 committed by GitHub
parent 0aafcb6ee2
commit 1ec20de2f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View File

@ -166,6 +166,8 @@ namespace recomp {
// TODO move these // TODO move these
void quicksave_save(); void quicksave_save();
void quicksave_load(); void quicksave_load();
void open_quit_game_prompt();
} }
#endif #endif

View File

@ -128,9 +128,19 @@ bool sdl_event_filter(void* userdata, SDL_Event* event) {
InputState.controller_states.erase(controller_event->which); InputState.controller_states.erase(controller_event->which);
} }
break; break;
case SDL_EventType::SDL_QUIT: case SDL_EventType::SDL_QUIT: {
ultramodern::quit(); if (!ultramodern::is_game_started()) {
return true; ultramodern::quit();
return true;
}
if (recomp::get_current_menu() != recomp::Menu::Config) {
recomp::set_current_menu(recomp::Menu::Config);
}
recomp::open_quit_game_prompt();
break;
}
case SDL_EventType::SDL_MOUSEWHEEL: case SDL_EventType::SDL_MOUSEWHEEL:
{ {
SDL_MouseWheelEvent* wheel_event = &event->wheel; SDL_MouseWheelEvent* wheel_event = &event->wheel;

View File

@ -246,7 +246,7 @@ void close_config_menu() {
close_config_menu_impl(); close_config_menu_impl();
} }
void open_quit_game_prompt() { void recomp::open_quit_game_prompt() {
prompt_context.open_prompt( prompt_context.open_prompt(
"Are you sure you want to quit?", "Are you sure you want to quit?",
"Any progress since your last save will be lost.", "Any progress since your last save will be lost.",
@ -466,7 +466,7 @@ public:
recomp::register_event(listener, "open_quit_game_prompt", recomp::register_event(listener, "open_quit_game_prompt",
[](const std::string& param, Rml::Event& event) { [](const std::string& param, Rml::Event& event) {
open_quit_game_prompt(); recomp::open_quit_game_prompt();
}); });
recomp::register_event(listener, "toggle_input_device", recomp::register_event(listener, "toggle_input_device",