]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/dlg_settings_advanced.lua
Advanced settings: Reformat noise parameter format example
[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" or setting_type == "filepath" 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 = setting_type,
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() .. 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.settings: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:") .. ","
470                                 .. "," .. fgettext("<offset>, <scale>, (<spreadX>, <spreadY>, <spreadZ>),") .. ","
471                                 .. "," .. fgettext("<seed>, <octaves>, <persistence>, <lacunarity>") .. ","
472         elseif setting.type == "v3f" then
473                 formspec = formspec .. ",,"
474                                 .. "," .. fgettext_ne("Format is 3 numbers separated by commas and inside brackets.") .. ","
475         end
476
477         formspec = formspec:sub(1, -2) -- remove trailing comma
478
479         formspec = formspec .. ";1]"
480
481         if setting.type == "bool" then
482                 local selected_index
483                 if core.is_yes(get_current_value(setting)) then
484                         selected_index = 2
485                 else
486                         selected_index = 1
487                 end
488                 formspec = formspec .. "dropdown[0.5,3.5;3,1;dd_setting_value;"
489                                 .. fgettext("Disabled") .. "," .. fgettext("Enabled") .. ";"
490                                 .. selected_index .. "]"
491
492         elseif setting.type == "enum" then
493                 local selected_index = 0
494                 formspec = formspec .. "dropdown[0.5,3.5;3,1;dd_setting_value;"
495                 for index, value in ipairs(setting.values) do
496                         -- translating value is not possible, since it's the value
497                         --  that we set the setting to
498                         formspec = formspec ..  core.formspec_escape(value) .. ","
499                         if get_current_value(setting) == value then
500                                 selected_index = index
501                         end
502                 end
503                 if #setting.values > 0 then
504                         formspec = formspec:sub(1, -2) -- remove trailing comma
505                 end
506                 formspec = formspec .. ";" .. selected_index .. "]"
507
508         elseif setting.type == "path" or setting.type == "filepath" then
509                 local current_value = dialogdata.selected_path
510                 if not current_value then
511                         current_value = get_current_value(setting)
512                 end
513                 formspec = formspec .. "field[0.5,4;7.5,1;te_setting_value;;"
514                                 .. core.formspec_escape(current_value) .. "]"
515                                 .. "button[8,3.75;2,1;btn_browser_" .. setting.type .. ";" .. fgettext("Browse") .. "]"
516
517         else
518                 -- TODO: fancy input for float, int, flags, noise_params, v3f
519                 local width = 10
520                 local text = get_current_value(setting)
521                 if dialogdata.error_message then
522                         formspec = formspec .. "tablecolumns[color;text]" ..
523                         "tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
524                         "table[5,3.9;5,0.6;error_message;#FF0000,"
525                                         .. core.formspec_escape(dialogdata.error_message) .. ";0]"
526                         width = 5
527                         if dialogdata.entered_text then
528                                 text = dialogdata.entered_text
529                         end
530                 end
531                 formspec = formspec .. "field[0.5,4;" .. width .. ",1;te_setting_value;;"
532                                 .. core.formspec_escape(text) .. "]"
533         end
534         return formspec
535 end
536
537 local function handle_change_setting_buttons(this, fields)
538         if fields["btn_done"] or fields["key_enter"] then
539                 local setting = settings[selected_setting]
540                 if setting.type == "bool" then
541                         local new_value = fields["dd_setting_value"]
542                         -- Note: new_value is the actual (translated) value shown in the dropdown
543                         core.settings:set_bool(setting.name, new_value == fgettext("Enabled"))
544
545                 elseif setting.type == "enum" then
546                         local new_value = fields["dd_setting_value"]
547                         core.settings:set(setting.name, new_value)
548
549                 elseif setting.type == "int" then
550                         local new_value = tonumber(fields["te_setting_value"])
551                         if not new_value or math.floor(new_value) ~= new_value then
552                                 this.data.error_message = fgettext_ne("Please enter a valid integer.")
553                                 this.data.entered_text = fields["te_setting_value"]
554                                 core.update_formspec(this:get_formspec())
555                                 return true
556                         end
557                         if setting.min and new_value < setting.min then
558                                 this.data.error_message = fgettext_ne("The value must be at least $1.", setting.min)
559                                 this.data.entered_text = fields["te_setting_value"]
560                                 core.update_formspec(this:get_formspec())
561                                 return true
562                         end
563                         if setting.max and new_value > setting.max then
564                                 this.data.error_message = fgettext_ne("The value must not be larger than $1.", setting.max)
565                                 this.data.entered_text = fields["te_setting_value"]
566                                 core.update_formspec(this:get_formspec())
567                                 return true
568                         end
569                         core.settings:set(setting.name, new_value)
570
571                 elseif setting.type == "float" then
572                         local new_value = tonumber(fields["te_setting_value"])
573                         if not new_value then
574                                 this.data.error_message = fgettext_ne("Please enter a valid number.")
575                                 this.data.entered_text = fields["te_setting_value"]
576                                 core.update_formspec(this:get_formspec())
577                                 return true
578                         end
579                         core.settings:set(setting.name, new_value)
580
581                 elseif setting.type == "flags" then
582                         local new_value = fields["te_setting_value"]
583                         for _,value in ipairs(new_value:split(",", true)) do
584                                 value = value:trim()
585                                 local possible = "," .. setting.possible .. ","
586                                 if not possible:find("," .. value .. ",", 0, true) then
587                                         this.data.error_message = fgettext_ne("\"$1\" is not a valid flag.", value)
588                                         this.data.entered_text = fields["te_setting_value"]
589                                         core.update_formspec(this:get_formspec())
590                                         return true
591                                 end
592                         end
593                         core.settings:set(setting.name, new_value)
594
595                 else
596                         local new_value = fields["te_setting_value"]
597                         core.settings:set(setting.name, new_value)
598                 end
599                 core.settings:write()
600                 this:delete()
601                 return true
602         end
603
604         if fields["btn_cancel"] then
605                 this:delete()
606                 return true
607         end
608
609         if fields["btn_browser_path"] then
610                 core.show_path_select_dialog("dlg_browse_path",
611                         fgettext_ne("Select directory"), false)
612         end
613
614         if fields["btn_browser_filepath"] then
615                 core.show_path_select_dialog("dlg_browse_path",
616                         fgettext_ne("Select file"), true)
617         end
618
619         if fields["dlg_browse_path_accepted"] then
620                 this.data.selected_path = fields["dlg_browse_path_accepted"]
621                 core.update_formspec(this:get_formspec())
622         end
623
624         return false
625 end
626
627 local function create_settings_formspec(tabview, name, tabdata)
628         local formspec = "size[12,6.5;true]" ..
629                         "tablecolumns[color;tree;text,width=32;text]" ..
630                         "tableoptions[background=#00000000;border=false]" ..
631                         "field[0.3,0.1;10.2,1;search_string;;" .. core.formspec_escape(search_string) .. "]" ..
632                         "field_close_on_enter[search_string;false]" ..
633                         "button[10.2,-0.2;2,1;search;" .. fgettext("Search") .. "]" ..
634                         "table[0,0.8;12,4.5;list_settings;"
635
636         local current_level = 0
637         for _, entry in ipairs(settings) do
638                 local name
639                 if not core.settings:get_bool("main_menu_technical_settings") and entry.readable_name then
640                         name = fgettext_ne(entry.readable_name)
641                 else
642                         name = entry.name
643                 end
644
645                 if entry.type == "category" then
646                         current_level = entry.level
647                         formspec = formspec .. "#FFFF00," .. current_level .. "," .. fgettext(name) .. ",,"
648
649                 elseif entry.type == "bool" then
650                         local value = get_current_value(entry)
651                         if core.is_yes(value) then
652                                 value = fgettext("Enabled")
653                         else
654                                 value = fgettext("Disabled")
655                         end
656                         formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. ","
657                                         .. value .. ","
658
659                 elseif entry.type == "key" then
660                         -- ignore key settings, since we have a special dialog for them
661
662                 else
663                         formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. ","
664                                         .. core.formspec_escape(get_current_value(entry)) .. ","
665                 end
666         end
667
668         if #settings > 0 then
669                 formspec = formspec:sub(1, -2) -- remove trailing comma
670         end
671         formspec = formspec .. ";" .. selected_setting .. "]" ..
672                         "button[0,6;4,1;btn_back;".. fgettext("< Back to Settings page") .. "]" ..
673                         "button[10,6;2,1;btn_edit;" .. fgettext("Edit") .. "]" ..
674                         "button[7,6;3,1;btn_restore;" .. fgettext("Restore Default") .. "]" ..
675                         "checkbox[0,5.3;cb_tech_settings;" .. fgettext("Show technical names") .. ";"
676                                         .. dump(core.settings:get_bool("main_menu_technical_settings")) .. "]"
677
678         return formspec
679 end
680
681 local function handle_settings_buttons(this, fields, tabname, tabdata)
682         local list_enter = false
683         if fields["list_settings"] then
684                 selected_setting = core.get_table_index("list_settings")
685                 if core.explode_table_event(fields["list_settings"]).type == "DCL" then
686                         -- Directly toggle booleans
687                         local setting = settings[selected_setting]
688                         if setting and setting.type == "bool" then
689                                 local current_value = get_current_value(setting)
690                                 core.settings:set_bool(setting.name, not core.is_yes(current_value))
691                                 core.settings:write()
692                                 return true
693                         else
694                                 list_enter = true
695                         end
696                 else
697                         return true
698                 end
699         end
700
701         if fields.search or fields.key_enter_field == "search_string" then
702                 if search_string == fields.search_string then
703                         if selected_setting > 0 then
704                                 -- Go to next result on enter press
705                                 local i = selected_setting + 1
706                                 local looped = false
707                                 while i > #settings or settings[i].type == "category" do
708                                         i = i + 1
709                                         if i > #settings then
710                                                 -- Stop infinte looping
711                                                 if looped then
712                                                         return false
713                                                 end
714                                                 i = 1
715                                                 looped = true
716                                         end
717                                 end
718                                 selected_setting = i
719                                 core.update_formspec(this:get_formspec())
720                                 return true
721                         end
722                 else
723                         -- Search for setting
724                         search_string = fields.search_string
725                         settings, selected_setting = filter_settings(full_settings, search_string)
726                         core.update_formspec(this:get_formspec())
727                 end
728                 return true
729         end
730
731         if fields["btn_edit"] or list_enter then
732                 local setting = settings[selected_setting]
733                 if setting and setting.type ~= "category" then
734                         local edit_dialog = dialog_create("change_setting", create_change_setting_formspec,
735                                         handle_change_setting_buttons)
736                         edit_dialog:set_parent(this)
737                         this:hide()
738                         edit_dialog:show()
739                 end
740                 return true
741         end
742
743         if fields["btn_restore"] then
744                 local setting = settings[selected_setting]
745                 if setting and setting.type ~= "category" then
746                         core.settings:set(setting.name, setting.default)
747                         core.settings:write()
748                         core.update_formspec(this:get_formspec())
749                 end
750                 return true
751         end
752
753         if fields["btn_back"] then
754                 this:delete()
755                 return true
756         end
757
758         if fields["cb_tech_settings"] then
759                 core.settings:set("main_menu_technical_settings", fields["cb_tech_settings"])
760                 core.settings:write()
761                 core.update_formspec(this:get_formspec())
762                 return true
763         end
764
765         return false
766 end
767
768 function create_adv_settings_dlg()
769         local dlg = dialog_create("settings_advanced",
770                                 create_settings_formspec,
771                                 handle_settings_buttons,
772                                 nil)
773
774                                 return dlg
775 end
776
777 -- Generate minetest.conf.example and settings_translation_file.cpp
778
779 --assert(loadfile(core.get_builtin_path().."mainmenu"..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false))