From 1ec20de2f5c441aa80998391483d4814880408e8 Mon Sep 17 00:00:00 2001 From: thecozies <79979276+thecozies@users.noreply.github.com> Date: Tue, 30 Apr 2024 09:30:39 -0500 Subject: [PATCH] Show quit game prompt when attempting to close window (#13) --- include/recomp_input.h | 2 ++ src/game/input.cpp | 16 +++++++++++++--- src/ui/ui_config.cpp | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/recomp_input.h b/include/recomp_input.h index dff7ba6..35d30af 100644 --- a/include/recomp_input.h +++ b/include/recomp_input.h @@ -166,6 +166,8 @@ namespace recomp { // TODO move these void quicksave_save(); void quicksave_load(); + + void open_quit_game_prompt(); } #endif diff --git a/src/game/input.cpp b/src/game/input.cpp index f1fe816..1b981cf 100644 --- a/src/game/input.cpp +++ b/src/game/input.cpp @@ -128,9 +128,19 @@ bool sdl_event_filter(void* userdata, SDL_Event* event) { InputState.controller_states.erase(controller_event->which); } break; - case SDL_EventType::SDL_QUIT: - ultramodern::quit(); - return true; + case SDL_EventType::SDL_QUIT: { + if (!ultramodern::is_game_started()) { + 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: { SDL_MouseWheelEvent* wheel_event = &event->wheel; diff --git a/src/ui/ui_config.cpp b/src/ui/ui_config.cpp index 6d2611f..372cdeb 100644 --- a/src/ui/ui_config.cpp +++ b/src/ui/ui_config.cpp @@ -246,7 +246,7 @@ void close_config_menu() { close_config_menu_impl(); } -void open_quit_game_prompt() { +void recomp::open_quit_game_prompt() { prompt_context.open_prompt( "Are you sure you want to quit?", "Any progress since your last save will be lost.", @@ -466,7 +466,7 @@ public: recomp::register_event(listener, "open_quit_game_prompt", [](const std::string& param, Rml::Event& event) { - open_quit_game_prompt(); + recomp::open_quit_game_prompt(); }); recomp::register_event(listener, "toggle_input_device",