mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
allow adding keybindings from setting menu
This commit is contained in:
parent
8eba9ffa2c
commit
9a9fced642
2 changed files with 9 additions and 21 deletions
|
@ -431,9 +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 btn_clear = "unbind_" .. 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("|")
|
||||||
for _, o in ipairs(core.full_settingtypes) do
|
for _, o in ipairs(core.full_settingtypes) do
|
||||||
|
@ -457,33 +455,22 @@ function make.key(setting)
|
||||||
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)),
|
||||||
("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")),
|
|
||||||
}
|
}
|
||||||
if #value < 2 then
|
local edit_label = fgettext("Edit")
|
||||||
table.insert(fs, ("button_key[%f,0;%f,0.8;%s;%s]"):format(
|
if #value <= 1 then
|
||||||
btn_bind_width, btn_bind_width-0.8,
|
edit_label = core.formspec_escape(core.get_keycode_name(value[1] or ""))
|
||||||
btn_bind, core.formspec_escape(value[1] or "")))
|
|
||||||
else
|
|
||||||
table.insert(fs, ("button[%f,0;%f,0.8;%s;%s]"):format(
|
|
||||||
btn_bind_width, btn_bind_width-0.8,
|
|
||||||
btn_edit, fgettext("Edit")))
|
|
||||||
end
|
end
|
||||||
|
table.insert(fs, ("button[%f,0;%f,0.8;%s;%s]"):format(
|
||||||
|
btn_bind_width, btn_bind_width,
|
||||||
|
btn_edit, edit_label))
|
||||||
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_bind] then
|
if fields[btn_edit] 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)
|
||||||
elseif fields[btn_clear] then
|
|
||||||
core.settings:set(setting.name, "")
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ local function get_formspec(dialogdata)
|
||||||
("button_key[0.5,6.7;4.2,0.8;btn_bind;%s]"):format(core.formspec_escape(value[selection] or "")),
|
("button_key[0.5,6.7;4.2,0.8;btn_bind;%s]"):format(core.formspec_escape(value[selection] or "")),
|
||||||
("image_button[4.6,6.7;0.8,0.8;%s;btn_clear;]"):format(
|
("image_button[4.6,6.7;0.8,0.8;%s;btn_clear;]"):format(
|
||||||
core.formspec_escape(defaulttexturedir .. "clear.png")),
|
core.formspec_escape(defaulttexturedir .. "clear.png")),
|
||||||
|
("tooltip[btn_clear;%s]"):format(fgettext("Remove keybinding")),
|
||||||
("button[3.1,7.7;2.4,0.8;btn_close;%s]"):format(fgettext("Cancel")),
|
("button[3.1,7.7;2.4,0.8;btn_close;%s]"):format(fgettext("Cancel")),
|
||||||
("button[0.5,7.7;2.4,0.8;btn_save;%s]"):format(fgettext("Save")),
|
("button[0.5,7.7;2.4,0.8;btn_save;%s]"):format(fgettext("Save")),
|
||||||
}
|
}
|
||||||
|
@ -31,7 +32,7 @@ local function get_formspec(dialogdata)
|
||||||
and has_keybinding_conflict(core.settings:get(o.name):split("|"), key) then
|
and has_keybinding_conflict(core.settings:get(o.name):split("|"), key) then
|
||||||
prefix = mt_color_orange
|
prefix = mt_color_orange
|
||||||
if idx == selection then
|
if idx == selection then
|
||||||
warning = core.colorize(mt_color_orange, fgettext([[Conflicts with "$1"]], fgettext(o.readable_name)))
|
warning = core.colorize(mt_color_orange, fgettext([[Conflicts with "$1"]], fgettext_ne(o.readable_name)))
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue