mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Migrate existing keycode-based keybindings (#16049)
Co-authored-by: grorp <gregor.parzefall@posteo.de> Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
600763dffc
commit
57c1ab905c
13 changed files with 140 additions and 13 deletions
|
@ -9,3 +9,7 @@ mt_color_green = "#72FF63"
|
|||
mt_color_dark_green = "#25C191"
|
||||
mt_color_orange = "#FF8800"
|
||||
mt_color_red = "#FF3300"
|
||||
|
||||
function core.are_keycodes_equal(k1, k2)
|
||||
return core.normalize_keycode(k1) == core.normalize_keycode(k2)
|
||||
end
|
||||
|
|
|
@ -634,6 +634,10 @@ if core.gettext then -- for client and mainmenu
|
|||
function fgettext(text, ...)
|
||||
return core.formspec_escape(fgettext_ne(text, ...))
|
||||
end
|
||||
|
||||
function hgettext(text, ...)
|
||||
return core.hypertext_escape(fgettext_ne(text, ...))
|
||||
end
|
||||
end
|
||||
|
||||
local ESCAPE_CHAR = string.char(0x1b)
|
||||
|
|
|
@ -778,11 +778,11 @@ end
|
|||
|
||||
|
||||
if INIT == "mainmenu" then
|
||||
function create_settings_dlg()
|
||||
function create_settings_dlg(page_id)
|
||||
load()
|
||||
local dlg = dialog_create("dlg_settings", get_formspec, buttonhandler, eventhandler)
|
||||
|
||||
dlg.data.page_id = update_filtered_pages("")
|
||||
dlg.data.page_id = page_id or update_filtered_pages("")
|
||||
|
||||
return dlg
|
||||
end
|
||||
|
|
108
builtin/mainmenu/dlg_rebind_keys.lua
Normal file
108
builtin/mainmenu/dlg_rebind_keys.lua
Normal file
|
@ -0,0 +1,108 @@
|
|||
-- Luanti
|
||||
-- SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
-- Modified based on dlg_reinstall_mtg.lua
|
||||
-- Note that this is only needed for migrating from <5.11 to 5.12.
|
||||
|
||||
local doc_url = "https://docs.luanti.org/for-players/controls/"
|
||||
local SETTING_NAME = "no_keycode_migration_warning"
|
||||
|
||||
local function get_formspec(dialogdata)
|
||||
local markup = table.concat({
|
||||
"<big>" .. hgettext("Keybindings changed") .. "</big>",
|
||||
hgettext("The input handling system was reworked in Luanti 5.12.0."),
|
||||
hgettext("As a result, your keybindings may have been changed."),
|
||||
hgettext("Check out the key settings or refer to the documentation:"),
|
||||
("<action name='doc_url'><style color='cyan' hovercolor='orangered'>%s</style></action>"):format(doc_url),
|
||||
}, "\n")
|
||||
|
||||
return table.concat({
|
||||
"formspec_version[6]",
|
||||
"size[12,7]",
|
||||
"hypertext[0.5,0.5;11,4.7;text;", core.formspec_escape(markup), "]",
|
||||
"container[0.5,5.7]",
|
||||
"button[0,0;4,0.8;dismiss;", fgettext("Close"), "]",
|
||||
"button[4.5,0;6.5,0.8;reconfigure;", fgettext("Open settings"), "]",
|
||||
"container_end[]",
|
||||
})
|
||||
end
|
||||
|
||||
local function close_dialog(this)
|
||||
cache_settings:set_bool(SETTING_NAME, true)
|
||||
this:delete()
|
||||
end
|
||||
|
||||
local function buttonhandler(this, fields)
|
||||
if fields.reconfigure then
|
||||
close_dialog(this)
|
||||
|
||||
local maintab = ui.find_by_name("maintab")
|
||||
|
||||
local dlg = create_settings_dlg("controls_keyboard_and_mouse")
|
||||
dlg:set_parent(maintab)
|
||||
maintab:hide()
|
||||
dlg:show()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
if fields.dismiss then
|
||||
close_dialog(this)
|
||||
return true
|
||||
end
|
||||
|
||||
if fields.text == "action:doc_url" then
|
||||
core.open_url(doc_url)
|
||||
end
|
||||
end
|
||||
|
||||
local function eventhandler(event)
|
||||
if event == "DialogShow" then
|
||||
mm_game_theme.set_engine()
|
||||
return true
|
||||
elseif event == "MenuQuit" then
|
||||
-- Don't allow closing the dialog with ESC, but still allow exiting
|
||||
-- Luanti
|
||||
core.close()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function create_rebind_keys_dlg()
|
||||
local dlg = dialog_create("dlg_rebind_keys", get_formspec,
|
||||
buttonhandler, eventhandler)
|
||||
return dlg
|
||||
end
|
||||
|
||||
function migrate_keybindings()
|
||||
-- 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
|
||||
if core.is_first_run then
|
||||
cache_settings:set_bool(SETTING_NAME, true)
|
||||
end
|
||||
local has_migration = not cache_settings:get_bool(SETTING_NAME)
|
||||
|
||||
-- normalize all existing key settings, this converts them from KEY_KEY_C to SYSTEM_SCANCODE_6
|
||||
local settings = core.settings:to_table()
|
||||
for name, value in pairs(settings) do
|
||||
if name:match("^keymap_") then
|
||||
local normalized = core.normalize_keycode(value)
|
||||
if value ~= normalized then
|
||||
has_migration = true
|
||||
core.settings:set(name, normalized)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not has_migration then
|
||||
return
|
||||
end
|
||||
|
||||
local maintab = ui.find_by_name("maintab")
|
||||
|
||||
local dlg = create_rebind_keys_dlg()
|
||||
dlg:set_parent(maintab)
|
||||
maintab:hide()
|
||||
dlg:show()
|
||||
ui.update()
|
||||
end
|
|
@ -54,10 +54,10 @@ end
|
|||
|
||||
local function get_formspec(dialogdata)
|
||||
local markup = table.concat({
|
||||
"<big>", fgettext("Minetest Game is no longer installed by default"), "</big>\n",
|
||||
fgettext("For a long time, Luanti shipped with a default game called \"Minetest Game\". " ..
|
||||
"<big>", hgettext("Minetest Game is no longer installed by default"), "</big>\n",
|
||||
hgettext("For a long time, Luanti shipped with a default game called \"Minetest Game\". " ..
|
||||
"Since version 5.8.0, Luanti ships without a default game."), "\n",
|
||||
fgettext("If you want to continue playing in your Minetest Game worlds, you need to reinstall Minetest Game."),
|
||||
hgettext("If you want to continue playing in your Minetest Game worlds, you need to reinstall Minetest Game."),
|
||||
})
|
||||
|
||||
return table.concat({
|
||||
|
|
|
@ -35,6 +35,7 @@ dofile(menupath .. DIR_DELIM .. "dlg_register.lua")
|
|||
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_version_info.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_reinstall_mtg.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_rebind_keys.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_clients_list.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_server_list_mods.lua")
|
||||
|
||||
|
@ -112,6 +113,7 @@ local function init_globals()
|
|||
ui.update()
|
||||
|
||||
check_reinstall_mtg()
|
||||
migrate_keybindings()
|
||||
check_new_version()
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue