mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
partial 2
This commit is contained in:
parent
7e31de882d
commit
c9e28d39e9
4 changed files with 86 additions and 3 deletions
|
@ -486,10 +486,12 @@ function make.key(setting)
|
||||||
return table.concat(fs), height
|
return table.concat(fs), height
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_submit = function(self, fields)
|
on_submit = function(self, fields, tabview)
|
||||||
if fields[btn_bind] then
|
if fields[btn_bind] then
|
||||||
core.settings:set(setting.name, fields[btn_bind])
|
core.settings:set(setting.name, fields[btn_bind])
|
||||||
return true
|
return true
|
||||||
|
elseif fields[btn_edit] then
|
||||||
|
return show_change_keybinding_dlg(setting, tabview)
|
||||||
elseif fields[btn_clear] then
|
elseif fields[btn_clear] then
|
||||||
core.settings:set(setting.name, "")
|
core.settings:set(setting.name, "")
|
||||||
return true
|
return true
|
||||||
|
|
78
builtin/common/settings/dlg_change_keybinding.lua
Normal file
78
builtin/common/settings/dlg_change_keybinding.lua
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
-- Luanti
|
||||||
|
-- SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
local function get_formspec(dialogdata)
|
||||||
|
local name = dialogdata.setting.name
|
||||||
|
local readable_name = name
|
||||||
|
if dialogdata.setting.readable_name then
|
||||||
|
readable_name = ("%s (%s)"):format(fgettext(dialogdata.setting.readable_name), name)
|
||||||
|
end
|
||||||
|
|
||||||
|
local fs = {
|
||||||
|
"formspec_version[4]",
|
||||||
|
"size[6,2]", -- size element; height can only be determined later
|
||||||
|
("label[0.5,0.8;%s]"):format(readable_name),
|
||||||
|
}
|
||||||
|
|
||||||
|
return table.concat(fs)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function buttonhandler(self, fields)
|
||||||
|
local name = self.data.setting.name
|
||||||
|
if fields.quit or fields.btn_close then
|
||||||
|
self:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local formspec_handlers = {}
|
||||||
|
if INIT == "pause_menu" then
|
||||||
|
core.register_on_formspec_input(function(formname, fields)
|
||||||
|
if formspec_handlers[formname] then
|
||||||
|
formspec_handlers[formname](fields)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local is_mainmenu = INIT == "mainmenu"
|
||||||
|
function show_change_keybinding_dlg(setting, tabview)
|
||||||
|
local dlg
|
||||||
|
if is_mainmenu then
|
||||||
|
dlg = dialog_create("dlg_change_keybinding",
|
||||||
|
get_formspec, buttonhandler)
|
||||||
|
else
|
||||||
|
local name = "__builtin:rebind_" .. setting.name
|
||||||
|
dlg = {
|
||||||
|
show = function()
|
||||||
|
if dlg.removed then
|
||||||
|
--core.open_settings("controls_keyboard_and_mouse")
|
||||||
|
tabview:show()
|
||||||
|
else
|
||||||
|
core.show_formspec(name, get_formspec(dlg.data))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
delete = function()
|
||||||
|
core.show_formspec(name, "")
|
||||||
|
formspec_handlers[name] = nil
|
||||||
|
dlg.removed = true
|
||||||
|
end,
|
||||||
|
data = {},
|
||||||
|
}
|
||||||
|
formspec_handlers[name] = function(fields)
|
||||||
|
if buttonhandler(dlg, fields) then
|
||||||
|
dlg:show()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
dlg.data.setting = setting
|
||||||
|
|
||||||
|
if is_mainmenu then
|
||||||
|
dlg:set_parent(tabview)
|
||||||
|
tabview:hide()
|
||||||
|
end
|
||||||
|
dlg:show()
|
||||||
|
|
||||||
|
return is_mainmenu
|
||||||
|
end
|
|
@ -814,7 +814,9 @@ else
|
||||||
-- case it's a no-op
|
-- case it's a no-op
|
||||||
core.show_formspec("__builtin:settings", "")
|
core.show_formspec("__builtin:settings", "")
|
||||||
end
|
end
|
||||||
|
dialog.show = function() -- Used by the keybinding form
|
||||||
core.show_formspec("__builtin:settings", get_formspec(dialog.data))
|
core.show_formspec("__builtin:settings", get_formspec(dialog.data))
|
||||||
|
end
|
||||||
|
dialog:show()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ local path = core.get_builtin_path() .. "common" .. DIR_DELIM .. "settings" .. D
|
||||||
|
|
||||||
dofile(path .. "settingtypes.lua")
|
dofile(path .. "settingtypes.lua")
|
||||||
dofile(path .. "dlg_change_mapgen_flags.lua")
|
dofile(path .. "dlg_change_mapgen_flags.lua")
|
||||||
|
dofile(path .. "dlg_change_keybinding.lua")
|
||||||
dofile(path .. "dlg_settings.lua")
|
dofile(path .. "dlg_settings.lua")
|
||||||
|
|
||||||
-- Uncomment to generate 'minetest.conf.example' and 'settings_translation_file.cpp'.
|
-- Uncomment to generate 'minetest.conf.example' and 'settings_translation_file.cpp'.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue