]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/dlg_settings_advanced.lua
Add search to advanced settings (#4806)
[dragonfireclient.git] / builtin / mainmenu / dlg_settings_advanced.lua
1 --Minetest
2 --Copyright (C) 2015 PilzAdam
3 --
4 --This program is free software; you can redistribute it and/or modify
5 --it under the terms of the GNU Lesser General Public License as published by
6 --the Free Software Foundation; either version 2.1 of the License, or
7 --(at your option) any later version.
8 --
9 --This program is distributed in the hope that it will be useful,
10 --but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 --GNU Lesser General Public License for more details.
13 --
14 --You should have received a copy of the GNU Lesser General Public License along
15 --with this program; if not, write to the Free Software Foundation, Inc.,
16 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 local FILENAME = "settingtypes.txt"
19
20 local CHAR_CLASSES = {
21         SPACE = "[%s]",
22         VARIABLE = "[%w_%-%.]",
23         INTEGER = "[+-]?[%d]",
24         FLOAT = "[+-]?[%d%.]",
25         FLAGS = "[%w_%-%.,]",
26 }
27
28 -- returns error message, or nil
29 local function parse_setting_line(settings, line, read_all, base_level, allow_secure)
30         -- comment
31         local comment = line:match("^#" .. CHAR_CLASSES.SPACE .. "*(.*)$")
32         if comment then
33                 if settings.current_comment == "" then
34                         settings.current_comment = comment
35                 else
36                         settings.current_comment = settings.current_comment .. "\n" .. comment
37                 end
38                 return
39         end
40
41         -- clear current_comment so only comments directly above a setting are bound to it
42         -- but keep a local reference to it for variables in the current line
43         local current_comment = settings.current_comment
44         settings.current_comment = ""
45
46         -- empty lines
47         if line:match("^" .. CHAR_CLASSES.SPACE .. "*$") then
48                 return
49         end
50
51         -- category
52         local stars, category = line:match("^%[([%*]*)([^%]]+)%]$")
53         if category then
54                 table.insert(settings, {
55                         name = category,
56                         level = stars:len() + base_level,
57                         type = "category",
58                 })
59                 return
60         end
61
62         -- settings
63         local first_part, name, readable_name, setting_type = line:match("^"
64                         -- this first capture group matches the whole first part,
65                         --  so we can later strip it from the rest of the line
66                         .. "("
67                                 .. "([" .. CHAR_CLASSES.VARIABLE .. "+)" -- variable name
68                                 .. CHAR_CLASSES.SPACE .. "*"
69                                 .. "%(([^%)]*)%)"  -- readable name
70                                 .. CHAR_CLASSES.SPACE .. "*"
71                                 .. "(" .. CHAR_CLASSES.VARIABLE .. "+)" -- type
72                                 .. CHAR_CLASSES.SPACE .. "*"
73                         .. ")")
74
75         if not first_part then
76                 return "Invalid line"
77         end
78
79         if name:match("secure%.[.]*") and not allow_secure then
80                 return "Tried to add \"secure.\" setting"
81         end
82
83         if readable_name == "" then
84                 readable_name = nil
85         end
86         local remaining_line = line:sub(first_part:len() + 1)
87
88         if setting_type == "int" then
89                 local default, min, max = remaining_line:match("^"
90                                 -- first int is required, the last 2 are optional
91                                 .. "(" .. CHAR_CLASSES.INTEGER .. "+)" .. CHAR_CLASSES.SPACE .. "*"
92                                 .. "(" .. CHAR_CLASSES.INTEGER .. "*)" .. CHAR_CLASSES.SPACE .. "*"
93                                 .. "(" .. CHAR_CLASSES.INTEGER .. "*)"
94                                 .. "$")
95
96                 if not default or not tonumber(default) then
97                         return "Invalid integer setting"
98                 end
99
100                 min = tonumber(min)
101                 max = tonumber(max)
102                 table.insert(settings, {
103                         name = name,
104                         readable_name = readable_name,
105                         type = "int",
106                         default = default,
107                         min = min,
108                         max = max,
109                         comment = current_comment,
110                 })
111                 return
112         end
113
114         if setting_type == "string" or setting_type == "noise_params"
115                         or setting_type == "key" or setting_type == "v3f" then
116                 local default = remaining_line:match("^(.*)$")
117
118                 if not default then
119                         return "Invalid string setting"
120                 end
121                 if setting_type == "key" and not read_all then
122                         -- ignore key type if read_all is false
123                         return
124                 end
125
126                 table.insert(settings, {
127                         name = name,
128                         readable_name = readable_name,
129                         type = setting_type,
130                         default = default,
131                         comment = current_comment,
132                 })
133                 return
134         end
135
136         if setting_type == "bool" then
137                 if remaining_line ~= "false" and remaining_line ~= "true" then
138                         return "Invalid boolean setting"
139                 end
140
141                 table.insert(settings, {
142                         name = name,
143                         readable_name = readable_name,
144                         type = "bool",
145                         default = remaining_line,
146                         comment = current_comment,
147                 })
148                 return
149         end
150
151         if setting_type == "float" then
152                 local default, min, max = remaining_line:match("^"
153                                 -- first float is required, the last 2 are optional
154                                 .. "(" .. CHAR_CLASSES.FLOAT .. "+)" .. CHAR_CLASSES.SPACE .. "*"
155                                 .. "(" .. CHAR_CLASSES.FLOAT .. "*)" .. CHAR_CLASSES.SPACE .. "*"
156                                 .. "(" .. CHAR_CLASSES.FLOAT .. "*)"
157                                 .."$")
158
159                 if not default or not tonumber(default) then
160                         return "Invalid float setting"
161                 end
162
163                 min = tonumber(min)
164                 max = tonumber(max)
165                 table.insert(settings, {
166                         name = name,
167                         readable_name = readable_name,
168                         type = "float",
169                         default = default,
170                         min = min,
171                         max = max,
172                         comment = current_comment,
173                 })
174                 return
175         end
176
177         if setting_type == "enum" then
178                 local default, values = remaining_line:match("^"
179                                 -- first value (default) may be empty (i.e. is optional)
180                                 .. "(" .. CHAR_CLASSES.VARIABLE .. "*)" .. CHAR_CLASSES.SPACE .. "*"
181                                 .. "(" .. CHAR_CLASSES.FLAGS .. "+)"
182                                 .. "$")
183
184                 if not default or values == "" then
185                         return "Invalid enum setting"
186                 end
187
188                 table.insert(settings, {
189                         name = name,
190                         readable_name = readable_name,
191                         type = "enum",
192                         default = default,
193                         values = values:split(",", true),
194                         comment = current_comment,
195                 })
196                 return
197         end
198
199         if setting_type == "path" then
200                 local default = remaining_line:match("^(.*)$")
201
202                 if not default then
203                         return "Invalid path setting"
204                 end
205
206                 table.insert(settings, {
207                         name = name,
208                         readable_name = readable_name,
209                         type = "path",
210                         default = default,
211                         comment = current_comment,
212                 })
213                 return
214         end
215
216         if setting_type == "flags" then
217                 local default, possible = remaining_line:match("^"
218                                 -- first value (default) may be empty (i.e. is optional)
219                                 -- this is implemented by making the last value optional, and
220                                 -- swapping them around if it turns out empty.
221                                 .. "(" .. CHAR_CLASSES.FLAGS .. "+)" .. CHAR_CLASSES.SPACE .. "*"
222                                 .. "(" .. CHAR_CLASSES.FLAGS .. "*)"
223                                 .. "$")
224
225                 if not default or not possible then
226                         return "Invalid flags setting"
227                 end
228
229                 if possible == "" then
230                         possible = default
231                         default = ""
232                 end
233
234                 table.insert(settings, {
235                         name = name,
236                         readable_name = readable_name,
237                         type = "flags",
238                         default = default,
239                         possible = possible,
240                         comment = current_comment,
241                 })
242                 return
243         end
244
245         return "Invalid setting type \"" .. setting_type .. "\""
246 end
247
248 local function parse_single_file(file, filepath, read_all, result, base_level, allow_secure)
249         -- store this helper variable in the table so it's easier to pass to parse_setting_line()
250         result.current_comment = ""
251
252         local line = file:read("*line")
253         while line do
254                 local error_msg = parse_setting_line(result, line, read_all, base_level, allow_secure)
255                 if error_msg then
256                         core.log("error", error_msg .. " in " .. filepath .. " \"" .. line .. "\"")
257                 end
258                 line = file:read("*line")
259         end
260
261         result.current_comment = nil
262 end
263
264 -- read_all: whether to ignore certain setting types for GUI or not
265 -- parse_mods: whether to parse settingtypes.txt in mods and games
266 local function parse_config_file(read_all, parse_mods)
267         local builtin_path = core.get_builtin_path() .. DIR_DELIM .. FILENAME
268         local file = io.open(builtin_path, "r")
269         local settings = {}
270         if not file then
271                 core.log("error", "Can't load " .. FILENAME)
272                 return settings
273         end
274
275         parse_single_file(file, builtin_path, read_all, settings, 0, true)
276
277         file:close()
278
279         if parse_mods then
280                 -- Parse games
281                 local games_category_initialized = false
282                 local index = 1
283                 local game = gamemgr.get_game(index)
284                 while game do
285                         local path = game.path .. DIR_DELIM .. FILENAME
286                         local file = io.open(path, "r")
287                         if file then
288                                 if not games_category_initialized then
289                                         local translation = fgettext_ne("Games"), -- not used, but needed for xgettext
290                                         table.insert(settings, {
291                                                 name = "Games",
292                                                 level = 0,
293                                                 type = "category",
294                                         })
295                                         games_category_initialized = true
296                                 end
297
298                                 table.insert(settings, {
299                                         name = game.name,
300                                         level = 1,
301                                         type = "category",
302                                 })
303
304                                 parse_single_file(file, path, read_all, settings, 2, false)
305
306                                 file:close()
307                         end
308
309                         index = index + 1
310                         game = gamemgr.get_game(index)
311                 end
312
313                 -- Parse mods
314                 local mods_category_initialized = false
315                 local mods = {}
316                 get_mods(core.get_modpath(), mods)
317                 for _, mod in ipairs(mods) do
318                         local path = mod.path .. DIR_DELIM .. FILENAME
319                         local file = io.open(path, "r")
320                         if file then
321                                 if not mods_category_initialized then
322                                         local translation = fgettext_ne("Mods"), -- not used, but needed for xgettext
323                                         table.insert(settings, {
324                                                 name = "Mods",
325                                                 level = 0,
326                                                 type = "category",
327                                         })
328                                         mods_category_initialized = true
329                                 end
330
331                                 table.insert(settings, {
332                                         name = mod.name,
333                                         level = 1,
334                                         type = "category",
335                                 })
336
337                                 parse_single_file(file, path, read_all, settings, 2, false)
338
339                                 file:close()
340                         end
341                 end
342         end
343
344         return settings
345 end
346
347 local function filter_settings(settings, searchstring)
348         if not searchstring or searchstring == "" then
349                 return settings, -1
350         end
351
352         -- Setup the keyword list
353         local keywords = {}
354         for word in searchstring:lower():gmatch("%S+") do
355                 table.insert(keywords, word)
356         end
357
358         local result = {}
359         local category_stack = {}
360         local current_level = 0
361         local best_setting = nil
362         for _, entry in pairs(settings) do
363                 if entry.type == "category" then
364                         -- Remove all settingless categories
365                         while #category_stack > 0 and entry.level <= current_level do
366                                 table.remove(category_stack, #category_stack)
367                                 if #category_stack > 0 then
368                                         current_level = category_stack[#category_stack].level
369                                 else
370                                         current_level = 0
371                                 end
372                         end
373
374                         -- Push category onto stack
375                         category_stack[#category_stack + 1] = entry
376                         current_level = entry.level
377                 else
378                         -- See if setting matches keywords
379                         local setting_score = 0
380                         for k = 1, #keywords do
381                                 local keyword = keywords[k]
382
383                                 if string.find(entry.name:lower(), keyword, 1, true) then
384                                         setting_score = setting_score + 1
385                                 end
386
387                                 if entry.readable_name and
388                                                 string.find(fgettext(entry.readable_name):lower(), keyword, 1, true) then
389                                         setting_score = setting_score + 1
390                                 end
391
392                                 if entry.comment and
393                                                 string.find(fgettext_ne(entry.comment):lower(), keyword, 1, true) then
394                                         setting_score = setting_score + 1
395                                 end
396                         end
397
398                         -- Add setting to results if match
399                         if setting_score > 0 then
400                                 -- Add parent categories
401                                 for _, category in pairs(category_stack) do
402                                         result[#result + 1] = category
403                                 end
404                                 category_stack = {}
405
406                                 -- Add setting
407                                 result[#result + 1] = entry
408                                 entry.score = setting_score
409
410                                 if not best_setting or
411                                                 setting_score > result[best_setting].score then
412                                         best_setting = #result
413                                 end
414                         end
415                 end
416         end
417         return result, best_setting or -1
418 end
419
420 local full_settings = parse_config_file(false, true)
421 local search_string = ""
422 local settings = full_settings
423 local selected_setting = 1
424
425 local function get_current_value(setting)
426         local value = core.setting_get(setting.name)
427         if value == nil then
428                 value = setting.default
429         end
430         return value
431 end
432
433 local function create_change_setting_formspec(dialogdata)
434         local setting = settings[selected_setting]
435         local formspec = "size[10,5.2,true]" ..
436                         "button[5,4.5;2,1;btn_done;" .. fgettext("Save") .. "]" ..
437                         "button[3,4.5;2,1;btn_cancel;" .. fgettext("Cancel") .. "]" ..
438                         "tablecolumns[color;text]" ..
439                         "tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
440                         "table[0,0;10,3;info;"
441
442         if setting.readable_name then
443                 formspec = formspec .. "#FFFF00," .. fgettext(setting.readable_name)
444                                 .. " (" .. core.formspec_escape(setting.name) .. "),"
445         else
446                 formspec = formspec .. "#FFFF00," .. core.formspec_escape(setting.name) .. ","
447         end
448
449         formspec = formspec .. ",,"
450
451         local comment_text = ""
452
453         if setting.comment == "" then
454                 comment_text = fgettext_ne("(No description of setting given)")
455         else
456                 comment_text = fgettext_ne(setting.comment)
457         end
458         for _, comment_line in ipairs(comment_text:split("\n", true)) do
459                 formspec = formspec .. "," .. core.formspec_escape(comment_line) .. ","
460         end
461
462         if setting.type == "flags" then
463                 formspec = formspec .. ",,"
464                                 .. "," .. fgettext("Please enter a comma seperated list of flags.") .. ","
465                                 .. "," .. fgettext("Possible values are: ")
466                                 .. core.formspec_escape(setting.possible:gsub(",", ", ")) .. ","
467         elseif setting.type == "noise_params" then
468                 formspec = formspec .. ",,"
469                                 .. "," .. fgettext("Format: <offset>, <scale>, (<spreadX>, <spreadY>, <spreadZ>), <seed>, <octaves>, <persistence>") .. ","
470                                 .. "," .. fgettext("Optionally the lacunarity can be appended with a leading comma.") .. ","
471         elseif setting.type == "v3f" then
472                 formspec = formspec .. ",,"
473                                 .. "," .. fgettext_ne("Format is 3 numbers separated by commas and inside brackets.") .. ","
474         end
475
476         formspec = formspec:sub(1, -2) -- remove trailing comma
477
478         formspec = formspec .. ";1]"
479
480         if setting.type == "bool" then
481                 local selected_index
482                 if core.is_yes(get_current_value(setting)) then
483                         selected_index = 2
484                 else
485                         selected_index = 1
486                 end
487                 formspec = formspec .. "dropdown[0.5,3.5;3,1;dd_setting_value;"
488                                 .. fgettext("Disabled") .. "," .. fgettext("Enabled") .. ";"
489                                 .. selected_index .. "]"
490
491         elseif setting.type == "enum" then
492                 local selected_index = 0
493                 formspec = formspec .. "dropdown[0.5,3.5;3,1;dd_setting_value;"
494                 for index, value in ipairs(setting.values) do
495                         -- translating value is not possible, since it's the value
496                         --  that we set the setting to
497                         formspec = formspec ..  core.formspec_escape(value) .. ","
498                         if get_current_value(setting) == value then
499                                 selected_index = index
500                         end
501                 end
502                 if #setting.values > 0 then
503                         formspec = formspec:sub(1, -2) -- remove trailing comma
504                 end
505                 formspec = formspec .. ";" .. selected_index .. "]"
506
507         elseif setting.type == "path" then
508                 local current_value = dialogdata.selected_path
509                 if not current_value then
510                         current_value = get_current_value(setting)
511                 end
512                 formspec = formspec .. "field[0.5,4;7.5,1;te_setting_value;;"
513                                 .. core.formspec_escape(current_value) .. "]"
514                                 .. "button[8,3.75;2,1;btn_browser_path;" .. fgettext("Browse") .. "]"
515
516         else
517                 -- TODO: fancy input for float, int, flags, noise_params, v3f
518                 local width = 10
519                 local text = get_current_value(setting)
520                 if dialogdata.error_message then
521                         formspec = formspec .. "tablecolumns[color;text]" ..
522                         "tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
523                         "table[5,3.9;5,0.6;error_message;#FF0000,"
524                                         .. core.formspec_escape(dialogdata.error_message) .. ";0]"
525                         width = 5
526                         if dialogdata.entered_text then
527                                 text = dialogdata.entered_text
528                         end
529                 end
530                 formspec = formspec .. "field[0.5,4;" .. width .. ",1;te_setting_value;;"
531                                 .. core.formspec_escape(text) .. "]"
532         end
533         return formspec
534 end
535
536 local function handle_change_setting_buttons(this, fields)
537         if fields["btn_done"] or fields["key_enter"] then
538                 local setting = settings[selected_setting]
539                 if setting.type == "bool" then
540                         local new_value = fields["dd_setting_value"]
541                         -- Note: new_value is the actual (translated) value shown in the dropdown
542                         core.setting_setbool(setting.name, new_value == fgettext("Enabled"))
543
544                 elseif setting.type == "enum" then
545                         local new_value = fields["dd_setting_value"]
546                         core.setting_set(setting.name, new_value)
547
548                 elseif setting.type == "int" then
549                         local new_value = tonumber(fields["te_setting_value"])
550                         if not new_value or math.floor(new_value) ~= new_value then
551                                 this.data.error_message = fgettext_ne("Please enter a valid integer.")
552                                 this.data.entered_text = fields["te_setting_value"]
553                                 core.update_formspec(this:get_formspec())
554                                 return true
555                         end
556                         if setting.min and new_value < setting.min then
557                                 this.data.error_message = fgettext_ne("The value must be at least $1.", setting.min)
558                                 this.data.entered_text = fields["te_setting_value"]
559                                 core.update_formspec(this:get_formspec())
560                                 return true
561                         end
562                         if setting.max and new_value > setting.max then
563                                 this.data.error_message = fgettext_ne("The value must not be larger than $1.", setting.max)
564                                 this.data.entered_text = fields["te_setting_value"]
565                                 core.update_formspec(this:get_formspec())
566                                 return true
567                         end
568                         core.setting_set(setting.name, new_value)
569
570                 elseif setting.type == "float" then
571                         local new_value = tonumber(fields["te_setting_value"])
572                         if not new_value then
573                                 this.data.error_message = fgettext_ne("Please enter a valid number.")
574                                 this.data.entered_text = fields["te_setting_value"]
575                                 core.update_formspec(this:get_formspec())
576                                 return true
577                         end
578                         core.setting_set(setting.name, new_value)
579
580                 elseif setting.type == "flags" then
581                         local new_value = fields["te_setting_value"]
582                         for _,value in ipairs(new_value:split(",", true)) do
583                                 value = value:trim()
584                                 local possible = "," .. setting.possible .. ","
585                                 if not possible:find("," .. value .. ",", 0, true) then
586                                         this.data.error_message = fgettext_ne("\"$1\" is not a valid flag.", value)
587                                         this.data.entered_text = fields["te_setting_value"]
588                                         core.update_formspec(this:get_formspec())
589                                         return true
590                                 end
591                         end
592                         core.setting_set(setting.name, new_value)
593
594                 else
595                         local new_value = fields["te_setting_value"]
596                         core.setting_set(setting.name, new_value)
597                 end
598                 core.setting_save()
599                 this:delete()
600                 return true
601         end
602
603         if fields["btn_cancel"] then
604                 this:delete()
605                 return true
606         end
607
608         if fields["btn_browser_path"] then
609                 core.show_file_open_dialog("dlg_browse_path", fgettext_ne("Select path"))
610         end
611
612         if fields["dlg_browse_path_accepted"] then
613                 this.data.selected_path = fields["dlg_browse_path_accepted"]
614                 core.update_formspec(this:get_formspec())
615         end
616
617         return false
618 end
619
620 local function create_settings_formspec(tabview, name, tabdata)
621         local formspec = "size[12,6.5;true]" ..
622                         "tablecolumns[color;tree;text,width=32;text]" ..
623                         "tableoptions[background=#00000000;border=false]" ..
624                         "field[0.3,0.1;10.2,1;search_string;;" .. core.formspec_escape(search_string) .. "]" ..
625                         "field_close_on_enter[search_string;false]" ..
626                         "button[10.2,-0.2;2,1;search;" .. fgettext("Search") .. "]" ..
627                         "table[0,0.8;12,4.5;list_settings;"
628
629         local current_level = 0
630         for _, entry in ipairs(settings) do
631                 local name
632                 if not core.setting_getbool("main_menu_technical_settings") and entry.readable_name then
633                         name = fgettext_ne(entry.readable_name)
634                 else
635                         name = entry.name
636                 end
637
638                 if entry.type == "category" then
639                         current_level = entry.level
640                         formspec = formspec .. "#FFFF00," .. current_level .. "," .. fgettext(name) .. ",,"
641
642                 elseif entry.type == "bool" then
643                         local value = get_current_value(entry)
644                         if core.is_yes(value) then
645                                 value = fgettext("Enabled")
646                         else
647                                 value = fgettext("Disabled")
648                         end
649                         formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. ","
650                                         .. value .. ","
651
652                 elseif entry.type == "key" then
653                         -- ignore key settings, since we have a special dialog for them
654
655                 else
656                         formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. ","
657                                         .. core.formspec_escape(get_current_value(entry)) .. ","
658                 end
659         end
660
661         if #settings > 0 then
662                 formspec = formspec:sub(1, -2) -- remove trailing comma
663         end
664         formspec = formspec .. ";" .. selected_setting .. "]" ..
665                         "button[0,6;4,1;btn_back;".. fgettext("< Back to Settings page") .. "]" ..
666                         "button[10,6;2,1;btn_edit;" .. fgettext("Edit") .. "]" ..
667                         "button[7,6;3,1;btn_restore;" .. fgettext("Restore Default") .. "]" ..
668                         "checkbox[0,5.3;cb_tech_settings;" .. fgettext("Show technical names") .. ";"
669                                         .. dump(core.setting_getbool("main_menu_technical_settings")) .. "]"
670
671         return formspec
672 end
673
674 local function handle_settings_buttons(this, fields, tabname, tabdata)
675         local list_enter = false
676         if fields["list_settings"] then
677                 selected_setting = core.get_table_index("list_settings")
678                 if core.explode_table_event(fields["list_settings"]).type == "DCL" then
679                         -- Directly toggle booleans
680                         local setting = settings[selected_setting]
681                         if setting and setting.type == "bool" then
682                                 local current_value = get_current_value(setting)
683                                 core.setting_setbool(setting.name, not core.is_yes(current_value))
684                                 core.setting_save()
685                                 return true
686                         else
687                                 list_enter = true
688                         end
689                 else
690                         return true
691                 end
692         end
693
694         if fields.search or fields.key_enter_field == "search_string" then
695                 if search_string == fields.search_string then
696                         if selected_setting > 0 then
697                                 -- Go to next result on enter press
698                                 local i = selected_setting + 1
699                                 local looped = false
700                                 while i > #settings or settings[i].type == "category" do
701                                         i = i + 1
702                                         if i > #settings then
703                                                 -- Stop infinte looping
704                                                 if looped then
705                                                         return false
706                                                 end
707                                                 i = 1
708                                                 looped = true
709                                         end
710                                 end
711                                 selected_setting = i
712                                 core.update_formspec(this:get_formspec())
713                                 return true
714                         end
715                 else
716                         -- Search for setting
717                         search_string = fields.search_string
718                         settings, selected_setting = filter_settings(full_settings, search_string)
719                         core.update_formspec(this:get_formspec())
720                 end
721                 return true
722         end
723
724         if fields["btn_edit"] or list_enter then
725                 local setting = settings[selected_setting]
726                 if setting and setting.type ~= "category" then
727                         local edit_dialog = dialog_create("change_setting", create_change_setting_formspec,
728                                         handle_change_setting_buttons)
729                         edit_dialog:set_parent(this)
730                         this:hide()
731                         edit_dialog:show()
732                 end
733                 return true
734         end
735
736         if fields["btn_restore"] then
737                 local setting = settings[selected_setting]
738                 if setting and setting.type ~= "category" then
739                         core.setting_set(setting.name, setting.default)
740                         core.setting_save()
741                         core.update_formspec(this:get_formspec())
742                 end
743                 return true
744         end
745
746         if fields["btn_back"] then
747                 this:delete()
748                 return true
749         end
750
751         if fields["cb_tech_settings"] then
752                 core.setting_set("main_menu_technical_settings", fields["cb_tech_settings"])
753                 core.setting_save()
754                 core.update_formspec(this:get_formspec())
755                 return true
756         end
757
758         return false
759 end
760
761 function create_adv_settings_dlg()
762         local dlg = dialog_create("settings_advanced",
763                                 create_settings_formspec,
764                                 handle_settings_buttons,
765                                 nil)
766
767                                 return dlg
768 end
769
770 -- Generate minetest.conf.example and settings_translation_file.cpp
771
772 -- *** Please note ***
773 -- There is text in minetest.conf.example that will not be generated from
774 -- settingtypes.txt but must be preserved:
775 -- The documentation of mapgen noise parameter formats (title plus 16 lines)
776 -- Noise parameter 'mgv5_np_ground' in group format (13 lines)
777
778 --assert(loadfile(core.get_builtin_path()..DIR_DELIM.."mainmenu"..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false))