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

allow directly rebindings keys for actions with one binding

This commit is contained in:
y5nw 2025-05-27 10:51:22 +02:00
parent b7b67e978f
commit 88d887cf8d

View file

@ -431,6 +431,7 @@ local function make_noise_params(setting)
end end
function make.key(setting) function make.key(setting)
local btn_bind = "bind_" .. setting.name
local btn_edit = "edit_" .. setting.name local btn_edit = "edit_" .. setting.name
local function add_conflict_warnings(fs, height) local function add_conflict_warnings(fs, height)
local value = core.settings:get(setting.name):split("|") local value = core.settings:get(setting.name):split("|")
@ -451,25 +452,31 @@ function make.key(setting)
get_formspec = function(self, avail_w) get_formspec = function(self, avail_w)
self.resettable = core.settings:has(setting.name) self.resettable = core.settings:has(setting.name)
local btn_bind_width = math.max(2.5, avail_w/2) local btn_width = math.max(2.5, avail_w/2)
local value = core.settings:get(setting.name):split("|") local value = core.settings:get(setting.name):split("|")
local fs = { local fs = {
("label[0,0.4;%s]"):format(get_label(setting)), ("label[0,0.4;%s]"):format(get_label(setting)),
("tooltip[%s;%s]"):format(btn_edit, fgettext("Edit keybindings")),
} }
local edit_label = fgettext("Edit")
if #value <= 1 then if #value <= 1 then
edit_label = core.formspec_escape(core.get_keycode_name(value[1] or "")) table.insert(fs, ("button_key[%f,0;%f,0.8;%s;%s]"):format(
end btn_width, btn_width-0.8, btn_bind, value[1] or ""))
table.insert(fs, ("image_button[%f,0;0.8,0.8;%s;%s;]"):format(avail_w - 0.8,
core.formspec_escape(defaulttexturedir.."overflow_btn.png"), btn_edit))
else
table.insert(fs, ("button[%f,0;%f,0.8;%s;%s]"):format( table.insert(fs, ("button[%f,0;%f,0.8;%s;%s]"):format(
btn_bind_width, btn_bind_width, btn_width, btn_width, btn_edit, fgettext("Edit")))
btn_edit, edit_label)) end
local height = 0.8 local height = 0.8
height = add_conflict_warnings(fs, height) height = add_conflict_warnings(fs, height)
return table.concat(fs), height return table.concat(fs), height
end, end,
on_submit = function(self, fields, tabview) on_submit = function(self, fields, tabview)
if fields[btn_edit] then if fields[btn_bind] then
core.settings:set(setting.name, fields[btn_bind])
return true
elseif fields[btn_edit] then
return show_change_keybinding_dlg(setting, tabview) return show_change_keybinding_dlg(setting, tabview)
end end
end, end,