1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-30 19:22:14 +00:00

use critical key check for keymap_close_world in keybinding change dialog

This commit is contained in:
y5nw 2025-07-11 17:59:14 +02:00
parent 12e83deece
commit efabcd7377
2 changed files with 21 additions and 19 deletions

View file

@ -439,27 +439,14 @@ function make.key(setting)
return height
end
local critical_keys = {
keymap_drop = true,
keymap_dig = true,
keymap_place = true,
}
for _, o in ipairs(core.full_settingtypes) do
if o.type == "key" and o.name ~= setting.name and
is_keybinding_critical(setting.name, o.name) and
has_keybinding_conflict(core.settings:get(o.name):split("|"), value) then
local is_current_close_world = setting.name == "keymap_close_world"
local is_other_close_world = o.name == "keymap_close_world"
local is_current_critical = critical_keys[setting.name]
local is_other_critical = critical_keys[o.name]
if (is_other_critical or is_current_critical) or
(not is_current_close_world and not is_other_close_world) 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
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

View file

@ -28,8 +28,9 @@ local function get_formspec(dialogdata)
for idx, key in ipairs(value) do
local prefix = ""
for _, o in ipairs(core.full_settingtypes) do
if o.type == "key" and o.name ~= name
and has_keybinding_conflict(core.settings:get(o.name):split("|"), key) then
if o.type == "key" and o.name ~= name and
is_keybinding_critical(name, o.name) and
has_keybinding_conflict(core.settings:get(o.name):split("|"), key) then
prefix = mt_color_orange
if idx == selection then
warning = core.colorize(mt_color_orange, fgettext([[Conflicts with "$1"]], fgettext_ne(o.readable_name)))
@ -156,3 +157,17 @@ function has_keybinding_conflict(t1, t2) -- not local as it is also used by the
end
return false
end
local critical_keys = {
keymap_drop = true,
keymap_dig = true,
keymap_place = true,
}
function is_keybinding_critical(n1, n2)
local is_current_close_world = n1 == "keymap_close_world"
local is_other_close_world = n2 == "keymap_close_world"
local is_current_critical = critical_keys[n1]
local is_other_critical = critical_keys[n2]
return (is_other_critical or is_current_critical) or
(not is_current_close_world and not is_other_close_world)
end