Add quit confirmation dialog

On Android, the back button opens the dialog.
This commit is contained in:
kichikuou
2025-03-06 08:54:57 +09:00
parent 9733caf10f
commit c8ef298c56
3 changed files with 35 additions and 1 deletions
+33 -1
View File
@@ -33,9 +33,17 @@ void NACT::handle_event(SDL_Event e)
switch (e.type) {
case SDL_QUIT:
quit(0);
show_quit_dialog();
break;
#ifdef __ANDROID__
case SDL_KEYUP:
if (e.key.keysym.scancode == SDL_SCANCODE_AC_BACK) {
show_quit_dialog();
}
break;
#endif
case SDL_MOUSEMOTION:
mousex = e.motion.x * ags->screen_width / ags->window_width;
mousey = e.motion.y * ags->screen_height / ags->window_height;
@@ -148,6 +156,30 @@ void NACT::set_cursor(int x, int y)
SDL_WarpMouseInWindow(g_window, x, y);
}
void NACT::show_quit_dialog()
{
const SDL_MessageBoxButtonData buttons[] = {
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "Quit" },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "Cancel" },
};
const SDL_MessageBoxData messagebox_data = {
SDL_MESSAGEBOX_INFORMATION,
nullptr,
"System3",
"Quit game?\nAny unsaved progress will be lost.",
SDL_arraysize(buttons),
buttons,
};
int buttonid = 0;
if (SDL_ShowMessageBox(&messagebox_data, &buttonid) < 0) {
WARNING("error displaying message box");
return;
}
if (buttonid == 1) {
quit(0);
}
}
#ifdef __EMSCRIPTEN__
extern "C" {