mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-30 19:22:14 +00:00
Apply suggestions from code review
This commit is contained in:
parent
792dca6265
commit
6f2ef8c024
1 changed files with 35 additions and 32 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue