summaryrefslogtreecommitdiff
path: root/builtin/mainmenu/dlg_settings_advanced.lua
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/mainmenu/dlg_settings_advanced.lua')
-rw-r--r--builtin/mainmenu/dlg_settings_advanced.lua162
1 files changed, 132 insertions, 30 deletions
diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua
index b0d923768..206ce1620 100644
--- a/builtin/mainmenu/dlg_settings_advanced.lua
+++ b/builtin/mainmenu/dlg_settings_advanced.lua
@@ -344,11 +344,86 @@ local function parse_config_file(read_all, parse_mods)
return settings
end
-local settings = parse_config_file(false, true)
+local function filter_settings(settings, searchstring)
+ if not searchstring or searchstring == "" then
+ return settings, -1
+ end
+
+ -- Setup the keyword list
+ local keywords = {}
+ for word in searchstring:lower():gmatch("%S+") do
+ table.insert(keywords, word)
+ end
+
+ local result = {}
+ local category_stack = {}
+ local current_level = 0
+ local best_setting = nil
+ for _, entry in pairs(settings) do
+ if entry.type == "category" then
+ -- Remove all settingless categories
+ while #category_stack > 0 and entry.level <= current_level do
+ table.remove(category_stack, #category_stack)
+ if #category_stack > 0 then
+ current_level = category_stack[#category_stack].level
+ else
+ current_level = 0
+ end
+ end
+
+ -- Push category onto stack
+ category_stack[#category_stack + 1] = entry
+ current_level = entry.level
+ else
+ -- See if setting matches keywords
+ local setting_score = 0
+ for k = 1, #keywords do
+ local keyword = keywords[k]
+
+ if string.find(entry.name:lower(), keyword, 1, true) then
+ setting_score = setting_score + 1
+ end
+
+ if entry.readable_name and
+ string.find(fgettext(entry.readable_name):lower(), keyword, 1, true) then
+ setting_score = setting_score + 1
+ end
+
+ if entry.comment and
+ string.find(fgettext_ne(entry.comment):lower(), keyword, 1, true) then
+ setting_score = setting_score + 1
+ end
+ end
+
+ -- Add setting to results if match
+ if setting_score > 0 then
+ -- Add parent categories
+ for _, category in pairs(category_stack) do
+ result[#result + 1] = category
+ end
+ category_stack = {}
+
+ -- Add setting
+ result[#result + 1] = entry
+ entry.score = setting_score
+
+ if not best_setting or
+ setting_score > result[best_setting].score then
+ best_setting = #result
+ end
+ end
+ end
+ end
+ return result, best_setting or -1
+end
+
+local full_settings = parse_config_file(false, true)
+local search_string = ""
+local settings = full_settings
local selected_setting = 1
local function get_current_value(setting)
- local value = core.setting_get(setting.name)
+ local value = core.settings:get(setting.name)
if value == nil then
value = setting.default
end
@@ -464,11 +539,11 @@ local function handle_change_setting_buttons(this, fields)
if setting.type == "bool" then
local new_value = fields["dd_setting_value"]
-- Note: new_value is the actual (translated) value shown in the dropdown
- core.setting_setbool(setting.name, new_value == fgettext("Enabled"))
+ core.settings:set_bool(setting.name, new_value == fgettext("Enabled"))
elseif setting.type == "enum" then
local new_value = fields["dd_setting_value"]
- core.setting_set(setting.name, new_value)
+ core.settings:set(setting.name, new_value)
elseif setting.type == "int" then
local new_value = tonumber(fields["te_setting_value"])
@@ -490,7 +565,7 @@ local function handle_change_setting_buttons(this, fields)
core.update_formspec(this:get_formspec())
return true
end
- core.setting_set(setting.name, new_value)
+ core.settings:set(setting.name, new_value)
elseif setting.type == "float" then
local new_value = tonumber(fields["te_setting_value"])
@@ -500,7 +575,7 @@ local function handle_change_setting_buttons(this, fields)
core.update_formspec(this:get_formspec())
return true
end
- core.setting_set(setting.name, new_value)
+ core.settings:set(setting.name, new_value)
elseif setting.type == "flags" then
local new_value = fields["te_setting_value"]
@@ -514,13 +589,13 @@ local function handle_change_setting_buttons(this, fields)
return true
end
end
- core.setting_set(setting.name, new_value)
+ core.settings:set(setting.name, new_value)
else
local new_value = fields["te_setting_value"]
- core.setting_set(setting.name, new_value)
+ core.settings:set(setting.name, new_value)
end
- core.setting_save()
+ core.settings:write()
this:delete()
return true
end
@@ -544,14 +619,17 @@ end
local function create_settings_formspec(tabview, name, tabdata)
local formspec = "size[12,6.5;true]" ..
- "tablecolumns[color;tree;text;text]" ..
+ "tablecolumns[color;tree;text,width=32;text]" ..
"tableoptions[background=#00000000;border=false]" ..
- "table[0,0;12,5.5;list_settings;"
+ "field[0.3,0.1;10.2,1;search_string;;" .. core.formspec_escape(search_string) .. "]" ..
+ "field_close_on_enter[search_string;false]" ..
+ "button[10.2,-0.2;2,1;search;" .. fgettext("Search") .. "]" ..
+ "table[0,0.8;12,4.5;list_settings;"
local current_level = 0
for _, entry in ipairs(settings) do
local name
- if not core.setting_getbool("main_menu_technical_settings") and entry.readable_name then
+ if not core.settings:get_bool("main_menu_technical_settings") and entry.readable_name then
name = fgettext_ne(entry.readable_name)
else
name = entry.name
@@ -588,7 +666,7 @@ local function create_settings_formspec(tabview, name, tabdata)
"button[10,6;2,1;btn_edit;" .. fgettext("Edit") .. "]" ..
"button[7,6;3,1;btn_restore;" .. fgettext("Restore Default") .. "]" ..
"checkbox[0,5.3;cb_tech_settings;" .. fgettext("Show technical names") .. ";"
- .. dump(core.setting_getbool("main_menu_technical_settings")) .. "]"
+ .. dump(core.settings:get_bool("main_menu_technical_settings")) .. "]"
return formspec
end
@@ -597,13 +675,13 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
local list_enter = false
if fields["list_settings"] then
selected_setting = core.get_table_index("list_settings")
- if core.explode_table_event(fields["list_settings"]).type == "DCL" then
+ if core.explode_table_event(fields["list_settings"]).type == "DCL" then
-- Directly toggle booleans
local setting = settings[selected_setting]
- if setting.type == "bool" then
+ if setting and setting.type == "bool" then
local current_value = get_current_value(setting)
- core.setting_setbool(setting.name, not core.is_yes(current_value))
- core.setting_save()
+ core.settings:set_bool(setting.name, not core.is_yes(current_value))
+ core.settings:write()
return true
else
list_enter = true
@@ -613,9 +691,39 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
end
end
+ if fields.search or fields.key_enter_field == "search_string" then
+ if search_string == fields.search_string then
+ if selected_setting > 0 then
+ -- Go to next result on enter press
+ local i = selected_setting + 1
+ local looped = false
+ while i > #settings or settings[i].type == "category" do
+ i = i + 1
+ if i > #settings then
+ -- Stop infinte looping
+ if looped then
+ return false
+ end
+ i = 1
+ looped = true
+ end
+ end
+ selected_setting = i
+ core.update_formspec(this:get_formspec())
+ return true
+ end
+ else
+ -- Search for setting
+ search_string = fields.search_string
+ settings, selected_setting = filter_settings(full_settings, search_string)
+ core.update_formspec(this:get_formspec())
+ end
+ return true
+ end
+
if fields["btn_edit"] or list_enter then
local setting = settings[selected_setting]
- if setting.type ~= "category" then
+ if setting and setting.type ~= "category" then
local edit_dialog = dialog_create("change_setting", create_change_setting_formspec,
handle_change_setting_buttons)
edit_dialog:set_parent(this)
@@ -627,9 +735,9 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
if fields["btn_restore"] then
local setting = settings[selected_setting]
- if setting.type ~= "category" then
- core.setting_set(setting.name, setting.default)
- core.setting_save()
+ if setting and setting.type ~= "category" then
+ core.settings:set(setting.name, setting.default)
+ core.settings:write()
core.update_formspec(this:get_formspec())
end
return true
@@ -641,8 +749,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
end
if fields["cb_tech_settings"] then
- core.setting_set("main_menu_technical_settings", fields["cb_tech_settings"])
- core.setting_save()
+ core.settings:set("main_menu_technical_settings", fields["cb_tech_settings"])
+ core.settings:write()
core.update_formspec(this:get_formspec())
return true
end
@@ -661,10 +769,4 @@ end
-- Generate minetest.conf.example and settings_translation_file.cpp
--- *** Please note ***
--- There is text in minetest.conf.example that will not be generated from
--- settingtypes.txt but must be preserved:
--- The documentation of mapgen noise parameter formats (title plus 16 lines)
--- Noise parameter 'mgv5_np_ground' in group format (13 lines)
-
---assert(loadfile(core.get_mainmenu_path()..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false))
+--assert(loadfile(core.get_builtin_path()..DIR_DELIM.."mainmenu"..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false))