add search panel in controls-setting page, that search by name and keyname

This commit is contained in:
Sergwest585 2024-10-20 01:24:28 +03:00
parent 67f7006ad0
commit 791bc71a37
4 changed files with 40 additions and 0 deletions

View File

@ -4,6 +4,9 @@
min='0.1' max='10' value='2' step='0.1'
consumer='change_sensitivity'>
</trackbar>
<panel id='search_panel' size='380,60' padding='2' interval='1' max-length='350' color='#0000004C'>
<textbox id='search_textbox' multiline='false' size='300,20' consumer='function(x) search_text=x refresh_search() end'></textbox>
</panel>
<panel id='bindings_panel' size='380,204' padding='2' interval='1' max-length='350' color='#0000004C'>
<!-- content is generated in script -->
</panel>

View File

@ -1,3 +1,32 @@
function refresh_search()
local search_text = document.search_textbox.text
local search_key = document.search_key_checkbox.checked
local panel = document.bindings_panel
local bindings = input.get_bindings()
panel:clear()
table.sort(bindings, function(a, b) return a > b end)
if search_text ~= "" then
for i,name in ipairs(bindings) do
local _name = gui.str(name)
if ((_name:lower():find(search_text:lower()) and not search_key) or
(input.get_binding_text(name):lower():find(search_text:lower()) and search_key)) then
panel:add(gui.template("binding", {
id=name, name=_name
}))
end
end
else
for i,name in ipairs(bindings) do
panel:add(gui.template("binding", {
id=name, name=gui.str(name)
}))
end
end
end
function refresh_sensitivity()
document.sensitivity_label.text = string.format(
"%s: %s",
@ -15,6 +44,11 @@ function on_open()
document.sensitivity_track.value = core.get_setting("camera.sensitivity")
refresh_sensitivity()
document.search_panel:add(string.format(
"<checkbox size='20,20' id='search_key_checkbox' consumer='function(x) refresh_search() end' tooltip='%s'>%s</checkbox>",
gui.str("controls.key.tooltip", "settings"), gui.str("Key", "settings")
))
local panel = document.bindings_panel
local bindings = input.get_bindings()
table.sort(bindings, function(a, b) return a > b end)

View File

@ -14,6 +14,7 @@ world.generators.flat=Flat
# Tooltips
graphics.gamma.tooltip=Lighting brightness curve
graphics.backlight.tooltip=Backlight to prevent total darkness
controls.key.tooltip=Search by attached button name
# Bindings
chunks.reload=Reload Chunks

View File

@ -20,6 +20,7 @@ pack.remove-confirm=Удалить весь поставляемый паком/
# Подсказки
graphics.gamma.tooltip=Кривая яркости освещения
graphics.backlight.tooltip=Подсветка, предотвращающая полную темноту
controls.key.tooltip=Поиск по привязвнной кнопки управления
# Меню
menu.Apply=Применить
@ -70,6 +71,7 @@ settings.Music=Музыка
settings.Regular Sounds=Обычные Звуки
settings.UI Sounds=Звуки Интерфейса
settings.V-Sync=Вертикальная Синхронизация
settings.Key=Кнопка
# Управление
chunks.reload=Перезагрузить Чанки