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

Move keybinding settings to (Lua-based) setting menu (#15791)

This commit is contained in:
y5nw 2025-04-20 20:20:49 +02:00 committed by GitHub
parent c1d2124102
commit 23bfb2db72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 591 additions and 782 deletions

11
builtin/common/menu.lua Normal file
View file

@ -0,0 +1,11 @@
-- Luanti
-- SPDX-License-Identifier: LGPL-2.1-or-later
-- These colors are used by the main menu and the settings menu
mt_color_grey = "#AAAAAA"
mt_color_blue = "#6389FF"
mt_color_lightblue = "#99CCFF"
mt_color_green = "#72FF63"
mt_color_dark_green = "#25C191"
mt_color_orange = "#FF8800"
mt_color_red = "#FF3300"

View file

@ -37,6 +37,7 @@ local make = {}
-- * `fs` is a string for the formspec.
-- Components should be relative to `0,0`, and not exceed `avail_w` or the returned `used_height`.
-- * `used_height` is the space used by components in `fs`.
-- * `spacing`: (Optional) the vertical margin to be added before the component (default 0.25)
-- * `on_submit = function(self, fields, parent)`:
-- * `fields`: submitted formspec fields
-- * `parent`: the fstk element for the settings UI, use to show dialogs
@ -442,6 +443,59 @@ local function make_noise_params(setting)
}
end
function make.key(setting)
local btn_bind = "bind_" .. setting.name
local btn_clear = "unbind_" .. setting.name
local function add_conflict_warnings(fs, height)
local value = core.settings:get(setting.name)
if value == "" then
return height
end
for _, o in ipairs(core.full_settingtypes) do
if o.type == "key" and o.name ~= setting.name and core.are_keycodes_equal(core.settings:get(o.name), value) then
table.insert(fs, ("label[0,%f;%s]"):format(height + 0.3,
core.colorize(mt_color_orange, fgettext([[Conflicts with "$1"]], fgettext(o.readable_name)))))
height = height + 0.6
end
end
return height
end
return {
info_text = setting.comment,
setting = setting,
spacing = 0.1,
get_formspec = function(self, avail_w)
self.resettable = core.settings:has(setting.name)
local btn_bind_width = math.max(2.5, avail_w/2)
local value = core.settings:get(setting.name)
local fs = {
("label[0,0.4;%s]"):format(get_label(setting)),
("button_key[%f,0;%f,0.8;%s;%s]"):format(
btn_bind_width, btn_bind_width-0.8,
btn_bind, core.formspec_escape(value)),
("image_button[%f,0;0.8,0.8;%s;%s;]"):format(avail_w - 0.8,
core.formspec_escape(defaulttexturedir .. "clear.png"),
btn_clear),
("tooltip[%s;%s]"):format(btn_clear, fgettext("Remove keybinding")),
}
local height = 0.8
height = add_conflict_warnings(fs, height)
return table.concat(fs), height
end,
on_submit = function(self, fields)
if fields[btn_bind] then
core.settings:set(setting.name, fields[btn_bind])
return true
elseif fields[btn_clear] then
core.settings:set(setting.name, "")
return true
end
end,
}
end
if INIT == "pause_menu" then
-- Making the noise parameter dialog work in the pause menu settings would
-- require porting "FSTK" (at least the dialog API) from the mainmenu formspec

View file

@ -22,7 +22,6 @@ local component_funcs = dofile(path .. "components.lua")
local shadows_component = dofile(path .. "shadows_component.lua")
local loaded = false
local full_settings
local info_icon_path = core.formspec_escape(defaulttexturedir .. "settings_info.png")
local reset_icon_path = core.formspec_escape(defaulttexturedir .. "settings_reset.png")
local all_pages = {}
@ -32,7 +31,7 @@ local filtered_page_by_id = page_by_id
local function get_setting_info(name)
for _, entry in ipairs(full_settings) do
for _, entry in ipairs(core.full_settingtypes) do
if entry.type ~= "category" and entry.name == name then
return entry
end
@ -70,7 +69,7 @@ local function load_settingtypes()
end
end
for _, entry in ipairs(full_settings) do
for _, entry in ipairs(core.full_settingtypes) do
if entry.type == "category" then
if entry.level == 0 then
section = entry.name
@ -104,24 +103,7 @@ local function load()
end
loaded = true
full_settings = settingtypes.parse_config_file(false, true)
local change_keys = {
query_text = "Controls",
requires = {
keyboard_mouse = true,
},
context = "client",
get_formspec = function(self, avail_w)
local btn_w = math.min(avail_w, 3)
return ("button[0,0;%f,0.8;btn_change_keys;%s]"):format(btn_w, fgettext("Controls")), 0.8
end,
on_submit = function(self, fields)
if fields.btn_change_keys then
core.show_keys_menu()
end
end,
}
core.full_settingtypes = settingtypes.parse_config_file(false, true)
local touchscreen_layout = {
query_text = "Touchscreen layout",
@ -166,7 +148,6 @@ local function load()
load_settingtypes()
table.insert(page_by_id.controls_keyboard_and_mouse.content, 1, change_keys)
-- insert after "touch_controls"
table.insert(page_by_id.controls_touchscreen.content, 2, touchscreen_layout)
do
@ -665,7 +646,13 @@ local function get_formspec(dialogdata)
fs[#fs + 1] = "container_end[]"
if used_h > 0 then
y = y + used_h + 0.25
local spacing = 0.25
local next_comp = dialogdata.components[i + 1]
if next_comp and next_comp.spacing then
spacing = next_comp.spacing
end
y = y + used_h + spacing
end
end

View file

@ -249,9 +249,9 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se
if not default then
return "Invalid string setting"
end
if setting_type == "key" and not read_all then
-- ignore key type if read_all is false
return
if setting_type == "key" then
requires.keyboard_mouse = true
end
table.insert(settings, {

View file

@ -15,14 +15,6 @@
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
mt_color_grey = "#AAAAAA"
mt_color_blue = "#6389FF"
mt_color_lightblue = "#99CCFF"
mt_color_green = "#72FF63"
mt_color_dark_green = "#25C191"
mt_color_orange = "#FF8800"
mt_color_red = "#FF3300"
MAIN_TAB_W = 15.5
MAIN_TAB_H = 7.1
TABHEADER_H = 0.85
@ -35,6 +27,7 @@ local basepath = core.get_builtin_path()
defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
DIR_DELIM .. "pack" .. DIR_DELIM
dofile(basepath .. "common" .. DIR_DELIM .. "menu.lua")
dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua")
dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")

View file

@ -8,5 +8,6 @@ defaulttexturedir = ""
local builtin_shared = {}
assert(loadfile(commonpath .. "register.lua"))(builtin_shared)
assert(loadfile(commonpath .. "menu.lua"))(builtin_shared)
assert(loadfile(pausepath .. "register.lua"))(builtin_shared)
dofile(commonpath .. "settings" .. DIR_DELIM .. "init.lua")

View file

@ -31,7 +31,7 @@
# - enum
# - path
# - filepath
# - key (will be ignored in GUI, since a special key change dialog exists)
# - key
# - flags
# - noise_params_2d
# - noise_params_3d
@ -91,6 +91,8 @@
# * touchscreen / keyboard_mouse
# * opengl / gles
# * You can negate any requirement by prepending with !
# * The "keyboard_mouse" requirement is automatically added to settings with the
# "key" type.
#
# Sections are marked by a single line in the format: [Section Name]
# Sub-section are marked by adding * in front of the section name: [*Sub-section]
@ -178,6 +180,228 @@ enable_hotbar_mouse_wheel (Hotbar: Enable mouse wheel for selection) bool true
# Requires: keyboard_mouse
invert_hotbar_mouse_wheel (Hotbar: Invert mouse wheel direction) bool false
[**Keybindings]
# Key for moving the player forward.
keymap_forward (Move forward) key KEY_KEY_W
# Key for moving the player backward.
# Will also disable autoforward, when active.
keymap_backward (Move backward) key KEY_KEY_S
# Key for moving the player left.
keymap_left (Move left) key KEY_KEY_A
# Key for moving the player right.
keymap_right (Move right) key KEY_KEY_D
# Key for jumping.
keymap_jump (Jump) key KEY_SPACE
# Key for sneaking.
# Also used for climbing down and descending in water if aux1_descends is disabled.
keymap_sneak (Sneak) key KEY_LSHIFT
# Key for digging, punching or using something.
# (Note: The actual meaning might vary on a per-game basis.)
keymap_dig (Dig/punch/use) key KEY_LBUTTON
# Key for placing an item/block or for using something.
# (Note: The actual meaning might vary on a per-game basis.)
keymap_place (Place/use) key KEY_RBUTTON
# Key for opening the inventory.
keymap_inventory (Open inventory) key KEY_KEY_I
# Key for moving fast in fast mode.
keymap_aux1 (Aux1) key KEY_KEY_E
# Key for opening the chat window.
keymap_chat (Open chat) key KEY_KEY_T
# Key for opening the chat window to type commands.
keymap_cmd (Command) key /
# Key for opening the chat window to type local commands.
keymap_cmd_local (Local command) key .
# Key for toggling unlimited view range.
keymap_rangeselect (Range select) key
# Key for toggling flying.
keymap_freemove (Toggle fly) key KEY_KEY_K
# Key for toggling pitch move mode.
keymap_pitchmove (Toggle pitchmove) key
# Key for toggling fast mode.
keymap_fastmove (Toggle fast) key KEY_KEY_J
# Key for toggling noclip mode.
keymap_noclip (Toggle noclip) key KEY_KEY_H
# Key for selecting the next item in the hotbar.
keymap_hotbar_next (Hotbar: select next item) key KEY_KEY_N
# Key for selecting the previous item in the hotbar.
keymap_hotbar_previous (Hotbar: select previous item) key KEY_KEY_B
# Key for muting the game.
keymap_mute (Mute) key KEY_KEY_M
# Key for increasing the volume.
keymap_increase_volume (Increase volume) key
# Key for decreasing the volume.
keymap_decrease_volume (Decrease volume) key
# Key for toggling autoforward.
keymap_autoforward (Toggle automatic forward) key
# Key for toggling cinematic mode.
keymap_cinematic (Toggle cinematic mode) key
# Key for toggling display of minimap.
keymap_minimap (Toggle minimap) key KEY_KEY_V
# Key for taking screenshots.
keymap_screenshot (Screenshot) key KEY_F12
# Key for toggling fullscreen mode.
keymap_fullscreen (Toggle fullscreen) key KEY_F11
# Key for dropping the currently selected item.
keymap_drop (Drop item) key KEY_KEY_Q
# Key to use view zoom when possible.
keymap_zoom (Zoom) key KEY_KEY_Z
# Key for toggling the display of the HUD.
keymap_toggle_hud (Toggle HUD) key KEY_F1
# Key for toggling the display of chat.
keymap_toggle_chat (Toggle chat log) key KEY_F2
# Key for toggling the display of the large chat console.
keymap_console (Large chat console) key KEY_F10
# Key for toggling the display of fog.
keymap_toggle_fog (Toggle fog) key KEY_F3
# Key for toggling the display of debug info.
keymap_toggle_debug (Toggle debug info) key KEY_F5
# Key for toggling the display of the profiler. Used for development.
keymap_toggle_profiler (Toggle profiler) key KEY_F6
# Key for toggling the display of mapblock boundaries.
keymap_toggle_block_bounds (Toggle block bounds) key
# Key for switching between first- and third-person camera.
keymap_camera_mode (Toggle camera mode) key KEY_KEY_C
# Key for increasing the viewing range.
keymap_increase_viewing_range_min (Increase view range) key +
# Key for decreasing the viewing range.
keymap_decrease_viewing_range_min (Decrease view range) key -
# Key for selecting the first hotbar slot.
keymap_slot1 (Hotbar slot 1) key KEY_KEY_1
# Key for selecting the second hotbar slot.
keymap_slot2 (Hotbar slot 2) key KEY_KEY_2
# Key for selecting the third hotbar slot.
keymap_slot3 (Hotbar slot 3) key KEY_KEY_3
# Key for selecting the fourth hotbar slot.
keymap_slot4 (Hotbar slot 4) key KEY_KEY_4
# Key for selecting the fifth hotbar slot.
keymap_slot5 (Hotbar slot 5) key KEY_KEY_5
# Key for selecting the sixth hotbar slot.
keymap_slot6 (Hotbar slot 6) key KEY_KEY_6
# Key for selecting the seventh hotbar slot.
keymap_slot7 (Hotbar slot 7) key KEY_KEY_7
# Key for selecting the eighth hotbar slot.
keymap_slot8 (Hotbar slot 8) key KEY_KEY_8
# Key for selecting the ninth hotbar slot.
keymap_slot9 (Hotbar slot 9) key KEY_KEY_9
# Key for selecting the tenth hotbar slot.
keymap_slot10 (Hotbar slot 10) key KEY_KEY_0
# Key for selecting the 11th hotbar slot.
keymap_slot11 (Hotbar slot 11) key
# Key for selecting the 12th hotbar slot.
keymap_slot12 (Hotbar slot 12) key
# Key for selecting the 13th hotbar slot.
keymap_slot13 (Hotbar slot 13) key
# Key for selecting the 14th hotbar slot.
keymap_slot14 (Hotbar slot 14) key
# Key for selecting the 15th hotbar slot.
keymap_slot15 (Hotbar slot 15) key
# Key for selecting the 16th hotbar slot.
keymap_slot16 (Hotbar slot 16) key
# Key for selecting the 17th hotbar slot.
keymap_slot17 (Hotbar slot 17) key
# Key for selecting the 18th hotbar slot.
keymap_slot18 (Hotbar slot 18) key
# Key for selecting the 19th hotbar slot.
keymap_slot19 (Hotbar slot 19) key
# Key for selecting the 20th hotbar slot.
keymap_slot20 (Hotbar slot 20) key
# Key for selecting the 21st hotbar slot.
keymap_slot21 (Hotbar slot 21) key
# Key for selecting the 22nd hotbar slot.
keymap_slot22 (Hotbar slot 22) key
# Key for selecting the 23rd hotbar slot.
keymap_slot23 (Hotbar slot 23) key
# Key for selecting the 24th hotbar slot.
keymap_slot24 (Hotbar slot 24) key
# Key for selecting the 25th hotbar slot.
keymap_slot25 (Hotbar slot 25) key
# Key for selecting the 26th hotbar slot.
keymap_slot26 (Hotbar slot 26) key
# Key for selecting the 27th hotbar slot.
keymap_slot27 (Hotbar slot 27) key
# Key for selecting the 28th hotbar slot.
keymap_slot28 (Hotbar slot 28) key
# Key for selecting the 29th hotbar slot.
keymap_slot29 (Hotbar slot 29) key
# Key for selecting the 30th hotbar slot.
keymap_slot30 (Hotbar slot 30) key
# Key for selecting the 31st hotbar slot.
keymap_slot31 (Hotbar slot 31) key
# Key for selecting the 32nd hotbar slot.
keymap_slot32 (Hotbar slot 32) key
[*Touchscreen]
# Enables the touchscreen controls, allowing you to play the game with a touchscreen.
@ -1825,7 +2049,6 @@ instrument.profiler (Profiler) bool false
# 0 = disable. Useful for developers.
profiler_print_interval (Engine profiling data print interval) int 0 0
[*Advanced]
[**Graphics] [client]
@ -2219,6 +2442,23 @@ curl_parallel_limit (cURL parallel limit) int 8 1 2147483647
# Maximum time a file download (e.g. a mod download) may take, stated in milliseconds.
curl_file_download_timeout (cURL file download timeout) int 300000 5000 2147483647
[**Client Debugging] [client]
# Key for toggling the camera update. Only usable with 'debug' privilege.
keymap_toggle_update_camera (Toggle camera update) key
# Key for switching to the previous entry in Quicktune.
keymap_quicktune_prev (Quicktune: select previous entry) key
# Key for switching to the next entry in Quicktune.
keymap_quicktune_next (Quicktune: select next entry) key
# Key for decrementing the selected value in Quicktune.
keymap_quicktune_dec (Quicktune: decrement value) key
# Key for incrementing the selected value in Quicktune.
keymap_quicktune_inc (Quicktune: increment value) key
[**Miscellaneous]
# Clickable weblinks (middle-click or Ctrl+left-click) enabled in chat console output.
@ -2345,226 +2585,3 @@ show_technical_names (Show technical names) bool false
# Controlled by a checkbox in the settings menu.
show_advanced (Show advanced settings) bool false
# Key for moving the player forward.
keymap_forward (Forward key) key KEY_KEY_W
# Key for moving the player backward.
# Will also disable autoforward, when active.
keymap_backward (Backward key) key KEY_KEY_S
# Key for moving the player left.
keymap_left (Left key) key KEY_KEY_A
# Key for moving the player right.
keymap_right (Right key) key KEY_KEY_D
# Key for jumping.
keymap_jump (Jump key) key KEY_SPACE
# Key for sneaking.
# Also used for climbing down and descending in water if aux1_descends is disabled.
keymap_sneak (Sneak key) key KEY_LSHIFT
# Key for digging, punching or using something.
# (Note: The actual meaning might vary on a per-game basis.)
keymap_dig (Dig/punch/use key) key KEY_LBUTTON
# Key for placing an item/block or for using something.
# (Note: The actual meaning might vary on a per-game basis.)
keymap_place (Place/use key) key KEY_RBUTTON
# Key for opening the inventory.
keymap_inventory (Inventory key) key KEY_KEY_I
# Key for moving fast in fast mode.
keymap_aux1 (Aux1 key) key KEY_KEY_E
# Key for opening the chat window.
keymap_chat (Chat key) key KEY_KEY_T
# Key for opening the chat window to type commands.
keymap_cmd (Command key) key /
# Key for opening the chat window to type local commands.
keymap_cmd_local (Command key) key .
# Key for toggling unlimited view range.
keymap_rangeselect (Range select key) key
# Key for toggling flying.
keymap_freemove (Fly key) key KEY_KEY_K
# Key for toggling pitch move mode.
keymap_pitchmove (Pitch move key) key
# Key for toggling fast mode.
keymap_fastmove (Fast key) key KEY_KEY_J
# Key for toggling noclip mode.
keymap_noclip (Noclip key) key KEY_KEY_H
# Key for selecting the next item in the hotbar.
keymap_hotbar_next (Hotbar next key) key KEY_KEY_N
# Key for selecting the previous item in the hotbar.
keymap_hotbar_previous (Hotbar previous key) key KEY_KEY_B
# Key for muting the game.
keymap_mute (Mute key) key KEY_KEY_M
# Key for increasing the volume.
keymap_increase_volume (Inc. volume key) key
# Key for decreasing the volume.
keymap_decrease_volume (Dec. volume key) key
# Key for toggling autoforward.
keymap_autoforward (Automatic forward key) key
# Key for toggling cinematic mode.
keymap_cinematic (Cinematic mode key) key
# Key for toggling display of minimap.
keymap_minimap (Minimap key) key KEY_KEY_V
# Key for taking screenshots.
keymap_screenshot (Screenshot) key KEY_F12
# Key for toggling fullscreen mode.
keymap_fullscreen (Fullscreen key) key KEY_F11
# Key for dropping the currently selected item.
keymap_drop (Drop item key) key KEY_KEY_Q
# Key to use view zoom when possible.
keymap_zoom (View zoom key) key KEY_KEY_Z
# Key for selecting the first hotbar slot.
keymap_slot1 (Hotbar slot 1 key) key KEY_KEY_1
# Key for selecting the second hotbar slot.
keymap_slot2 (Hotbar slot 2 key) key KEY_KEY_2
# Key for selecting the third hotbar slot.
keymap_slot3 (Hotbar slot 3 key) key KEY_KEY_3
# Key for selecting the fourth hotbar slot.
keymap_slot4 (Hotbar slot 4 key) key KEY_KEY_4
# Key for selecting the fifth hotbar slot.
keymap_slot5 (Hotbar slot 5 key) key KEY_KEY_5
# Key for selecting the sixth hotbar slot.
keymap_slot6 (Hotbar slot 6 key) key KEY_KEY_6
# Key for selecting the seventh hotbar slot.
keymap_slot7 (Hotbar slot 7 key) key KEY_KEY_7
# Key for selecting the eighth hotbar slot.
keymap_slot8 (Hotbar slot 8 key) key KEY_KEY_8
# Key for selecting the ninth hotbar slot.
keymap_slot9 (Hotbar slot 9 key) key KEY_KEY_9
# Key for selecting the tenth hotbar slot.
keymap_slot10 (Hotbar slot 10 key) key KEY_KEY_0
# Key for selecting the 11th hotbar slot.
keymap_slot11 (Hotbar slot 11 key) key
# Key for selecting the 12th hotbar slot.
keymap_slot12 (Hotbar slot 12 key) key
# Key for selecting the 13th hotbar slot.
keymap_slot13 (Hotbar slot 13 key) key
# Key for selecting the 14th hotbar slot.
keymap_slot14 (Hotbar slot 14 key) key
# Key for selecting the 15th hotbar slot.
keymap_slot15 (Hotbar slot 15 key) key
# Key for selecting the 16th hotbar slot.
keymap_slot16 (Hotbar slot 16 key) key
# Key for selecting the 17th hotbar slot.
keymap_slot17 (Hotbar slot 17 key) key
# Key for selecting the 18th hotbar slot.
keymap_slot18 (Hotbar slot 18 key) key
# Key for selecting the 19th hotbar slot.
keymap_slot19 (Hotbar slot 19 key) key
# Key for selecting the 20th hotbar slot.
keymap_slot20 (Hotbar slot 20 key) key
# Key for selecting the 21st hotbar slot.
keymap_slot21 (Hotbar slot 21 key) key
# Key for selecting the 22nd hotbar slot.
keymap_slot22 (Hotbar slot 22 key) key
# Key for selecting the 23rd hotbar slot.
keymap_slot23 (Hotbar slot 23 key) key
# Key for selecting the 24th hotbar slot.
keymap_slot24 (Hotbar slot 24 key) key
# Key for selecting the 25th hotbar slot.
keymap_slot25 (Hotbar slot 25 key) key
# Key for selecting the 26th hotbar slot.
keymap_slot26 (Hotbar slot 26 key) key
# Key for selecting the 27th hotbar slot.
keymap_slot27 (Hotbar slot 27 key) key
# Key for selecting the 28th hotbar slot.
keymap_slot28 (Hotbar slot 28 key) key
# Key for selecting the 29th hotbar slot.
keymap_slot29 (Hotbar slot 29 key) key
# Key for selecting the 30th hotbar slot.
keymap_slot30 (Hotbar slot 30 key) key
# Key for selecting the 31st hotbar slot.
keymap_slot31 (Hotbar slot 31 key) key
# Key for selecting the 32nd hotbar slot.
keymap_slot32 (Hotbar slot 32 key) key
# Key for toggling the display of the HUD.
keymap_toggle_hud (HUD toggle key) key KEY_F1
# Key for toggling the display of chat.
keymap_toggle_chat (Chat toggle key) key KEY_F2
# Key for toggling the display of the large chat console.
keymap_console (Large chat console key) key KEY_F10
# Key for toggling the display of fog.
keymap_toggle_fog (Fog toggle key) key KEY_F3
# Key for toggling the camera update. Only usable with 'debug' privilege.
keymap_toggle_update_camera (Camera update toggle key) key
# Key for toggling the display of debug info.
keymap_toggle_debug (Debug info toggle key) key KEY_F5
# Key for toggling the display of the profiler. Used for development.
keymap_toggle_profiler (Profiler toggle key) key KEY_F6
# Key for toggling the display of mapblock boundaries.
keymap_toggle_block_bounds (Block bounds toggle key) key
# Key for switching between first- and third-person camera.
keymap_camera_mode (Toggle camera mode key) key KEY_KEY_C
# Key for increasing the viewing range.
keymap_increase_viewing_range_min (View range increase key) key +
# Key for decreasing the viewing range.
keymap_decrease_viewing_range_min (View range decrease key) key -