|
| 1 | +-- Luanti |
| 2 | +-- Copyright (C) 2025 siliconsniffer |
| 3 | +-- SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 | + |
| 5 | + |
| 6 | +local function exit_dialog_formspec() |
| 7 | + local show_dialog = core.settings:get_bool("enable_esc_dialog", true) |
| 8 | + local formspec = { |
| 9 | + "formspec_version[10]" .. |
| 10 | + "size[10,3.6]" .. |
| 11 | + "style_type[label;font=bold]" .. |
| 12 | + "style[btn_quit_confirm_yes;bgcolor=red]" .. |
| 13 | + "label[0.5,0.5;" .. fgettext("Are you sure you want to quit?") .. "]" .. |
| 14 | + "checkbox[0.5,1.4;cb_show_dialog;" .. fgettext("Always show this dialog.") .. ";" .. tostring(show_dialog) .. "]" .. |
| 15 | + "button[0.5,2.3;3,0.8;btn_quit_confirm_cancel;" .. fgettext("Cancel") .. "]" .. |
| 16 | + "button[6.5,2.3;3,0.8;btn_quit_confirm_yes;" .. fgettext("Quit") .. "]" .. |
| 17 | + "set_focus[btn_quit_confirm_yes]" |
| 18 | + } |
| 19 | + return table.concat(formspec, "") |
| 20 | +end |
| 21 | + |
| 22 | + |
| 23 | +local function exit_dialog_buttonhandler(this, fields) |
| 24 | + if fields.cb_show_dialog ~= nil then |
| 25 | + core.settings:set_bool("enable_esc_dialog", core.is_yes(fields.cb_show_dialog)) |
| 26 | + return false |
| 27 | + elseif fields.btn_quit_confirm_yes then |
| 28 | + this:delete() |
| 29 | + core.close() |
| 30 | + return true |
| 31 | + elseif fields.btn_quit_confirm_cancel then |
| 32 | + this:delete() |
| 33 | + this:show() |
| 34 | + return true |
| 35 | + end |
| 36 | +end |
| 37 | + |
| 38 | + |
| 39 | +local function event_handler(event) |
| 40 | + if event == "DialogShow" then |
| 41 | + mm_game_theme.set_engine(true) -- hide the menu header |
| 42 | + return true |
| 43 | + end |
| 44 | + return false |
| 45 | +end |
| 46 | + |
| 47 | + |
| 48 | +function create_exit_dialog() |
| 49 | + local retval = dialog_create("dlg_exit", |
| 50 | + exit_dialog_formspec, |
| 51 | + exit_dialog_buttonhandler, |
| 52 | + event_handler) |
| 53 | + return retval |
| 54 | +end |
0 commit comments