From d28a63f22a967330bbe5370552397548523534e2 Mon Sep 17 00:00:00 2001 From: siliconsniffer <97843108+siliconsniffer@users.noreply.github.com> Date: Thu, 22 May 2025 09:03:33 +0200 Subject: [PATCH 1/3] Are you sure you want to quit? --- builtin/mainmenu/init.lua | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 14185a4843..6865d5fcc3 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -49,7 +49,36 @@ local tabs = { -------------------------------------------------------------------------------- local function main_event_handler(tabview, event) if event == "MenuQuit" then - core.close() + if not ui.childlist["mainmenu_quit_confirm"] then + tabview:hide() + local dlg = dialog_create( + "mainmenu_quit_confirm", + function() + return confirmation_formspec( + fgettext("Are you sure you want to quit?"), + "btn_quit_confirm_yes", fgettext("Quit"), + "btn_quit_confirm_cancel", fgettext("Cancel") + ) + end, + function(this, fields) + if fields.btn_quit_confirm_yes then + this:delete() + core.close() + return true + elseif fields.btn_quit_confirm_cancel or fields.key_escape or fields.quit then + this:delete() + if tabview and tabview.show then + tabview:show() + end + return true + end + end, + nil + ) + dlg:set_parent(tabview) + dlg:show() + end + return true end return true end From 792dca6265b8d98e25f7c0b2a12854b1f7f42991 Mon Sep 17 00:00:00 2001 From: siliconsniffer <97843108+siliconsniffer@users.noreply.github.com> Date: Mon, 23 Jun 2025 14:31:07 +0200 Subject: [PATCH 2/3] Always show this dialog? --- builtin/mainmenu/init.lua | 22 +++++++++++++++------- builtin/settingtypes.txt | 3 +++ src/defaultsettings.cpp | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 6865d5fcc3..6e28629052 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -49,19 +49,25 @@ local tabs = { -------------------------------------------------------------------------------- local function main_event_handler(tabview, event) if event == "MenuQuit" then - if not ui.childlist["mainmenu_quit_confirm"] then + local show_dialog = core.settings:get_bool("enable_esc_dialog") + if not ui.childlist["mainmenu_quit_confirm"] and show_dialog then tabview:hide() local dlg = dialog_create( "mainmenu_quit_confirm", function() - return confirmation_formspec( - fgettext("Are you sure you want to quit?"), - "btn_quit_confirm_yes", fgettext("Quit"), - "btn_quit_confirm_cancel", fgettext("Cancel") - ) + return "size[10,3,true]" .. + "label[0.5,0.5;" .. fgettext("Are you sure you want to quit?") .. "]" .. + "checkbox[0.5,1;cb_show_dialog;" .. fgettext("Always show this dialog.") .. ";" .. tostring(show_dialog) .. "]" .. + "style[btn_quit_confirm_yes;bgcolor=red]" .. + "button[0.5,2.0;2.5,0.5;btn_quit_confirm_yes;" .. fgettext("Quit") .. "]" .. + "button[7.0,2.0;2.5,0.5;btn_quit_confirm_cancel;" .. fgettext("Cancel") .. "]" end, function(this, fields) - if fields.btn_quit_confirm_yes then + if fields.cb_show_dialog ~= nil then + local value = (fields.cb_show_dialog == "true") and "true" or "false" + core.settings:set("enable_esc_dialog", value) + return false + elseif fields.btn_quit_confirm_yes then this:delete() core.close() return true @@ -77,6 +83,8 @@ local function main_event_handler(tabview, event) ) dlg:set_parent(tabview) dlg:show() + else + core.close() end return true end diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 17ecf5b34f..bde9e15e96 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -158,6 +158,9 @@ autojump (Automatic jumping) bool false # On touchscreens, this only affects digging. safe_dig_and_place (Safe digging and placing) bool false +# Enable a confirmation dialog before closing. +enable_esc_dialog (Confirmation dialog before closing) bool true + [*Keyboard and Mouse] # Invert vertical mouse movement. diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 916ce9e51f..9f05d48a89 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -369,6 +369,7 @@ void set_default_settings() settings->setDefault("toggle_sneak_key", "false"); settings->setDefault("toggle_aux1_key", "false"); settings->setDefault("autojump", bool_to_cstr(has_touch)); + settings->setDefault("enable_esc_dialog", "true"); settings->setDefault("continuous_forward", "false"); settings->setDefault("enable_joysticks", "false"); settings->setDefault("joystick_id", "0"); From 6f2ef8c0249c2192dc18c8f8707b5d135404e597 Mon Sep 17 00:00:00 2001 From: siliconsniffer <97843108+siliconsniffer@users.noreply.github.com> Date: Wed, 23 Jul 2025 22:21:38 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- builtin/mainmenu/init.lua | 67 ++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 6e28629052..17655e7524 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -47,42 +47,45 @@ local tabs = { } -------------------------------------------------------------------------------- +local function show_exit_dialog(tabview, show_dialog) + tabview:hide() + local dlg = dialog_create( + "mainmenu_quit_confirm", + function() + return "size[10,3,true]" .. + "label[0.5,0.5;" .. fgettext("Are you sure you want to quit?") .. "]" .. + "checkbox[0.5,1;cb_show_dialog;" .. fgettext("Always show this dialog.") .. ";" .. tostring(show_dialog) .. "]" .. + "style[btn_quit_confirm_yes;bgcolor=red]" .. + "button[0.5,2.0;2.5,0.5;btn_quit_confirm_yes;" .. fgettext("Quit") .. "]" .. + "button[7.0,2.0;2.5,0.5;btn_quit_confirm_cancel;" .. fgettext("Cancel") .. "]" + end, + function(this, fields) + if fields.cb_show_dialog ~= nil then + core.settings:set_bool("enable_esc_dialog", core.is_yes(fields.cb_show_dialog)) + return false + elseif fields.btn_quit_confirm_yes then + this:delete() + core.close() + return true + elseif fields.btn_quit_confirm_cancel or fields.key_escape or fields.quit then + this:delete() + if tabview and tabview.show then + tabview:show() + end + return true + end + end, + nil + ) + dlg:set_parent(tabview) + dlg:show() +end + local function main_event_handler(tabview, event) if event == "MenuQuit" then local show_dialog = core.settings:get_bool("enable_esc_dialog") if not ui.childlist["mainmenu_quit_confirm"] and show_dialog then - tabview:hide() - local dlg = dialog_create( - "mainmenu_quit_confirm", - function() - return "size[10,3,true]" .. - "label[0.5,0.5;" .. fgettext("Are you sure you want to quit?") .. "]" .. - "checkbox[0.5,1;cb_show_dialog;" .. fgettext("Always show this dialog.") .. ";" .. tostring(show_dialog) .. "]" .. - "style[btn_quit_confirm_yes;bgcolor=red]" .. - "button[0.5,2.0;2.5,0.5;btn_quit_confirm_yes;" .. fgettext("Quit") .. "]" .. - "button[7.0,2.0;2.5,0.5;btn_quit_confirm_cancel;" .. fgettext("Cancel") .. "]" - end, - function(this, fields) - if fields.cb_show_dialog ~= nil then - local value = (fields.cb_show_dialog == "true") and "true" or "false" - core.settings:set("enable_esc_dialog", value) - return false - elseif fields.btn_quit_confirm_yes then - this:delete() - core.close() - return true - elseif fields.btn_quit_confirm_cancel or fields.key_escape or fields.quit then - this:delete() - if tabview and tabview.show then - tabview:show() - end - return true - end - end, - nil - ) - dlg:set_parent(tabview) - dlg:show() + show_exit_dialog(tabview, show_dialog) else core.close() end