1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Don't break when multiple dialogs are shown on startup (#16204)

This commit is contained in:
grorp 2025-06-01 15:24:14 +02:00 committed by GitHub
parent a2460df316
commit 56a7f0b7cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 26 deletions

View file

@ -118,7 +118,7 @@ function ui.update()
if (active_toplevel_ui_elements > 1) then if (active_toplevel_ui_elements > 1) then
core.log("warning", "more than one active ui ".. core.log("warning", "more than one active ui "..
"element, self most likely isn't intended") "element, this most likely isn't intended")
end end
if (active_toplevel_ui_elements == 0) then if (active_toplevel_ui_elements == 0) then

View file

@ -33,13 +33,13 @@ end
local function buttonhandler(this, fields) local function buttonhandler(this, fields)
if fields.reconfigure then if fields.reconfigure then
local parent = this.parent
close_dialog(this) close_dialog(this)
local maintab = ui.find_by_name("maintab")
local dlg = create_settings_dlg("controls_keyboard_and_mouse") local dlg = create_settings_dlg("controls_keyboard_and_mouse")
dlg:set_parent(maintab) dlg:set_parent(parent)
maintab:hide() parent:hide()
dlg:show() dlg:show()
return true return true
@ -74,7 +74,7 @@ local function create_rebind_keys_dlg()
return dlg return dlg
end end
function migrate_keybindings() function migrate_keybindings(parent)
-- Show migration dialog if the user upgraded from an earlier version -- Show migration dialog if the user upgraded from an earlier version
-- and this has not yet been shown before, *or* if keys settings had to be changed -- and this has not yet been shown before, *or* if keys settings had to be changed
if core.is_first_run then if core.is_first_run then
@ -95,14 +95,14 @@ function migrate_keybindings()
end end
if not has_migration then if not has_migration then
return return parent
end end
local maintab = ui.find_by_name("maintab")
local dlg = create_rebind_keys_dlg() local dlg = create_rebind_keys_dlg()
dlg:set_parent(maintab) dlg:set_parent(parent)
maintab:hide() parent:hide()
dlg:show() dlg:show()
ui.update() ui.update()
return dlg
end end

View file

@ -11,7 +11,7 @@
local SETTING_NAME = "no_mtg_notification" local SETTING_NAME = "no_mtg_notification"
function check_reinstall_mtg() function check_reinstall_mtg(parent)
-- used to be in minetest.conf -- used to be in minetest.conf
if core.settings:get_bool(SETTING_NAME) then if core.settings:get_bool(SETTING_NAME) then
cache_settings:set_bool(SETTING_NAME, true) cache_settings:set_bool(SETTING_NAME, true)
@ -19,14 +19,14 @@ function check_reinstall_mtg()
end end
if cache_settings:get_bool(SETTING_NAME) then if cache_settings:get_bool(SETTING_NAME) then
return return parent
end end
local games = core.get_games() local games = core.get_games()
for _, game in ipairs(games) do for _, game in ipairs(games) do
if game.id == "minetest" then if game.id == "minetest" then
cache_settings:set_bool(SETTING_NAME, true) cache_settings:set_bool(SETTING_NAME, true)
return return parent
end end
end end
@ -40,16 +40,16 @@ function check_reinstall_mtg()
end end
if not mtg_world_found then if not mtg_world_found then
cache_settings:set_bool(SETTING_NAME, true) cache_settings:set_bool(SETTING_NAME, true)
return return parent
end end
local maintab = ui.find_by_name("maintab")
local dlg = create_reinstall_mtg_dlg() local dlg = create_reinstall_mtg_dlg()
dlg:set_parent(maintab) dlg:set_parent(parent)
maintab:hide() parent:hide()
dlg:show() dlg:show()
ui.update() ui.update()
return dlg
end end
local function get_formspec(dialogdata) local function get_formspec(dialogdata)
@ -74,22 +74,22 @@ end
local function buttonhandler(this, fields) local function buttonhandler(this, fields)
if fields.reinstall then if fields.reinstall then
local parent = this.parent
-- Don't set "no_mtg_notification" here so that the dialog will be shown -- Don't set "no_mtg_notification" here so that the dialog will be shown
-- again if downloading MTG fails for whatever reason. -- again if downloading MTG fails for whatever reason.
this:delete() this:delete()
local maintab = ui.find_by_name("maintab")
local dlg = create_contentdb_dlg(nil, "minetest/minetest") local dlg = create_contentdb_dlg(nil, "minetest/minetest")
dlg:set_parent(maintab) dlg:set_parent(parent)
maintab:hide() parent:hide()
dlg:show() dlg:show()
return true return true
end end
if fields.dismiss then if fields.dismiss then
cache_settings:set_bool("no_mtg_notification", true) cache_settings:set_bool(SETTING_NAME, true)
this:delete() this:delete()
return true return true
end end

View file

@ -112,8 +112,12 @@ local function init_globals()
tv_main:show() tv_main:show()
ui.update() ui.update()
check_reinstall_mtg() -- synchronous, chain parents to only show one at a time
migrate_keybindings() local parent = tv_main
parent = migrate_keybindings(parent)
check_reinstall_mtg(parent)
-- asynchronous, will only be shown if we're still on "maintab"
check_new_version() check_new_version()
end end