--Minetest--Copyright (C) 2015 PilzAdam----This program is free software; you can redistribute it and/or modify--it under the terms of the GNU Lesser General Public License as published by--the Free Software Foundation; either version 2.1 of the License, or--(at your option) any later version.----This program is distributed in the hope that it will be useful,--but WITHOUT ANY WARRANTY; without even the implied warranty of--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the--GNU Lesser General Public License for more details.----You should have received a copy of the GNU Lesser General Public License along--with this program; if not, write to the Free Software Foundation, Inc.,--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.local FILENAME ="settingtypes.txt"local CHAR_CLASSES = {
SPACE ="[%s]",
VARIABLE ="[%w_%-%.]",
INTEGER ="[+-]?[%d]",
FLOAT ="[+-]?[%d%.]",
FLAGS ="[%w_%-%.,]",}local functionflags_to_table(flags)return flags:gsub("%s+",""):split(",",true)-- Remove all spaces and splitend-- returns error message, or nillocal functionparse_setting_line(settings, line, read_all, base_level, allow_secure)-- strip carriage returns (CR, /r)
line = line:gsub("\r","")-- commentlocal comment = line:match("^#".. CHAR_CLASSES.SPACE .."*(.*)$")if comment thenif settings.current_comment ==""then
settings.current_comment = comment
else
settings.current_comment = settings.current_comment .."\n".. comment
endreturnend-- clear current_comment so only comments directly above a setting are bound to it-- but keep a local reference to it for variables in the current linelocal current_comment = settings.current_comment
settings.current_comment =""-- empty linesif line:match("^".. CHAR_CLASSES.SPACE .."*$")thenreturnend-- categorylocal stars, category = line:match("^%[([%*]*)([^%]]+)%]$")if category thentable.insert(settings, {
name = category,
level = stars:len() + base_level,type="category",})returnend-- settingslocal first_part, name, readable_name, setting_type = line:match("^"-- this first capture group matches the whole first part,-- so we can later strip it from the rest of the line.."(".."([".. CHAR_CLASSES.VARIABLE .."+)"-- variable name.. CHAR_CLASSES.SPACE .."*".."%(([^%)]*)%)"-- readable name.. CHAR_CLASSES.SPACE .."*".."(".. CHAR_CLASSES.VARIABLE .."+)"-- type.. CHAR_CLASSES.SPACE .."*"..")")if not first_part thenreturn"Invalid line"endif name:match("secure%.[.]*")and not allow_secure thenreturn"Tried to add\"secure.\"setting"endif readable_name ==""then
readable_name =nilendlocal remaining_line = line:sub(first_part:len() +1)if setting_type =="int"thenlocal default,min,max= remaining_line:match("^"-- first int is required, the last 2 are optional.."(".. CHAR_CLASSES.INTEGER .."+)".. CHAR_CLASSES.SPACE .."*".."(".. CHAR_CLASSES.INTEGER .."*)".. CHAR_CLASSES.SPACE .."*".."(".. CHAR_CLASSES.INTEGER .."*)".."$")if not default or nottonumber(default)thenreturn"Invalid integer setting"endmin=tonumber(min)max=tonumber(max)table.insert(settings, {
name = name,
readable_name = readable_name,type="int",
default = default,min=min,max=max,
comment = current_comment,})returnendif setting_type =="string"or setting_type =="key"or setting_type =="v3f"thenlocal default = remaining_line:match("^(.*)$")if not default thenreturn"Invalid string setting"endif setting_type =="key"and not read_all then-- ignore key type if read_all is falsereturnendtable.insert(settings, {
name = name,
readable_name = readable_name,type= setting_type,
default = default,
comment = current_comment,})returnendif setting_type =="noise_params_2d"or setting_type =="noise_params_3d"thenlocal default = remaining_line:match("^(.*)$")if not default thenreturn"Invalid string setting"endlocal values = {}local ti =1local index =1for match in default:gmatch("[+-]?[%d.-e]+")do-- All numeric characters
index = default:find("[+-]?[%d.-e]+", index) + match:len()table.insert(values, match)
ti = ti +1if ti >9thenbreakendend
index = default:find("[^, ]", index)local flags =""if index then
flags = default:sub(index)
default = default:sub(1, index -3)-- Make sure no flags in single-line formatendtable.insert(values, flags)table.insert(settings, {
name = name,
readable_name = readable_name,type= setting_type,
default = default,
default_table = {
offset = values[1],
scale = values[2],
spread = {
x = values[3],
y = values[4],
z = values[5]},
seed = values[6],
octaves = values[7],
persistence = values[8],
lacunarity = values[9],
flags = values[10]},
values = values,
comment = current_comment,
noise_params =true,
flags =flags_to_table("defaults,eased,absvalue")})returnendif setting_type =="bool"thenif remaining_line ~="false"and remaining_line ~="true"thenreturn"Invalid boolean setting"endtable.insert(settings, {
name = name,
readable_name = readable_name,type="bool",
default = remaining_line,
comment = current_comment,})returnendif setting_type =="float"thenlocal default,min,max= remaining_line:match("^"-- first float is required, the last 2 are optional.."(".. CHAR_CLASSES.FLOAT .."+)".. CHAR_CLASSES.SPACE .."*".."(".. CHAR_CLASSES.FLOAT .."*)".. CHAR_CLASSES.SPACE .."*".."(".. CHAR_CLASSES.FLOAT .."*)".."$")if not default or nottonumber(default)thenreturn"Invalid float setting"endmin=tonumber(min)max=tonumber(max)table.insert(settings, {
name = name,
readable_name = readable_name,type="float",
default = default,min=min,max=max,
comment = current_comment,})returnendif setting_type =="enum"thenlocal default, values = remaining_line:match("^"-- first value (default) may be empty (i.e. is optional).."(".. CHAR_CLASSES.VARIABLE .."*)".. CHAR_CLASSES.SPACE .."*".."(".. CHAR_CLASSES.FLAGS .."+)".."$")if not default or values ==""thenreturn"Invalid enum setting"endtable.insert(settings, {
name = name,
readable_name = readable_name,type="enum",
default = default,
values = values:split(",",true),
comment = current_comment,})returnendif setting_type =="path"or setting_type =="filepath"thenlocal default = remaining_line:match("^(.*)$")if not default thenreturn"Invalid path setting"endtable.insert(settings, {
name = name,
readable_name = readable_name,type= setting_type,
default = default,
comment = current_comment,})returnendif setting_type =="flags"thenlocal default, possible = remaining_line:match("^"-- first value (default) may be empty (i.e. is optional)-- this is implemented by making the last value optional, and-- swapping them around if it turns out empty..."(".. CHAR_CLASSES.FLAGS .."+)".. CHAR_CLASSES.SPACE .."*".."(".. CHAR_CLASSES.FLAGS .."*)".."$")if not default or not possible thenreturn"Invalid flags setting"endif possible ==""then
possible = default
default =""endtable.insert(settings, {
name = name,
readable_name = readable_name,type="flags",
default = default,
possible =flags_to_table(possible),
comment = current_comment,})returnendreturn"Invalid setting type\"".. setting_type .."\""endlocal functionparse_single_file(file, filepath, read_all, result, base_level, allow_secure)-- store this helper variable in the table so it's easier to pass to parse_setting_line()
result.current_comment =""local line = file:read("*line")while line dolocal error_msg =parse_setting_line(result, line, read_all, base_level, allow_secure)if error_msg then
core.log("error", error_msg .." in ".. filepath .."\"".. line .."\"")end
line = file:read("*line")end
result.current_comment =nilend-- read_all: whether to ignore certain setting types for GUI or not-- parse_mods: whether to parse settingtypes.txt in mods and gameslocal functionparse_config_file(read_all, parse_mods)local settings = {}dolocal builtin_path = core.get_builtin_path() .. FILENAME
local file = io.open(builtin_path,"r")if not file then
core.log("error","Can't load ".. FILENAME)return settings
endparse_single_file(file, builtin_path, read_all, settings,0,true)
file:close()endif parse_mods then-- Parse gameslocal games_category_initialized =falselocal index =1local game = pkgmgr.get_game(index)while game dolocal path = game.path .. DIR_DELIM .. FILENAME
local file = io.open(path,"r")if file thenif not games_category_initialized thenfgettext_ne("Games")-- not used, but needed for xgettexttable.insert(settings, {
name ="Games",
level =0,type="category",})
games_category_initialized =trueendtable.insert(settings, {
name = game.name,
level =1,type="category",})parse_single_file(file, path, read_all, settings,2,false)
file:close()end
index = index +1
game = pkgmgr.get_game(index)end-- Parse modslocal mods_category_initialized =falselocal mods = {}get_mods(core.get_modpath(),"mods", mods)for _,modinipairs(mods)dolocal path =mod.path .. DIR_DELIM .. FILENAME
local file = io.open(path,"r")if file thenif not mods_category_initialized thenfgettext_ne("Mods")-- not used, but needed for xgettexttable.insert(settings, {
name ="Mods",
level =0,type="category",})
mods_category_initialized =trueendtable.insert(settings, {
name =mod.name,
level =1,type="category",})parse_single_file(file, path, read_all, settings,2,false)
file:close()endendendreturn settings
endlocal functionfilter_settings(settings, searchstring)if not searchstring or searchstring ==""thenreturn settings, -1end-- Setup the keyword listlocal keywords = {}for word in searchstring:lower():gmatch("%S+")dotable.insert(keywords, word)endlocal result = {}local category_stack = {}local current_level =0local best_setting =nilfor _, entry inpairs(settings)doif entry.type=="category"then-- Remove all settingless categorieswhile#category_stack >0and entry.level <= current_level dotable.remove(category_stack, #category_stack)if#category_stack >0then
current_level = category_stack[#category_stack].level
else
current_level =0endend-- Push category onto stack
category_stack[#category_stack +1] = entry
current_level = entry.level
else-- See if setting matches keywordslocal setting_score =0for k =1, #keywords dolocal keyword = keywords[k]ifstring.find(entry.name:lower(), keyword,1,true)then
setting_score = setting_score +1endif entry.readable_name andstring.find(fgettext(entry.readable_name):lower(), keyword,1,true)then
setting_score = setting_score +1endif entry.comment andstring.find(fgettext_ne(entry.comment):lower(), keyword,1,true)then
setting_score = setting_score +1endend-- Add setting to results if matchif setting_score >0then-- Add parent categoriesfor _, category inpairs(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
endendendendreturn result, best_setting or-1endlocal full_settings =parse_config_file(false,true)local search_string =""local settings = full_settings
local selected_setting =1local functionget_current_value(setting)local value = core.settings:get(setting.name)if value ==nil then
value = setting.default
endreturn value
endlocal functionget_current_np_group(setting)local value = core.settings:get_np_group(setting.name)if value ==nil thenreturn setting.values
endlocal p ="%g"return{
p:format(value.offset),
p:format(value.scale),
p:format(value.spread.x),
p:format(value.spread.y),
p:format(value.spread.z),
p:format(value.seed),
p:format(value.octaves),
p:format(value.persistence),
p:format(value.lacunarity),
value.flags
}endlocal functionget_current_np_group_as_string(setting)local value = core.settings:get_np_group(setting.name)if value ==nil thenreturn setting.default
endreturn("%g, %g, (%g, %g, %g), %g, %g, %g, %g"):format(
value.offset,
value.scale,
value.spread.x,
value.spread.y,
value.spread.z,
value.seed,
value.octaves,
value.persistence,
value.lacunarity
) .. (value.flags ~=""and(", ".. value.flags)or"")endlocal checkboxes = {}-- handle checkboxes eventslocal functioncreate_change_setting_formspec(dialogdata)local setting = settings[selected_setting]-- Final formspec will be created at the end of this function-- Default values below, may be changed depending on setting typelocal width =10local height =3.5local description_height =3local formspec =""-- Setting-specific formspec elementsif setting.type=="bool"thenlocal selected_index =1if core.is_yes(get_current_value(setting))then
selected_index =2end
formspec ="dropdown[3,".. height ..";4,1;dd_setting_value;"..fgettext("Disabled") ..","..fgettext("Enabled") ..";".. selected_index .."]"
height = height +1.25elseif setting.type=="enum"thenlocal selected_index =0
formspec ="dropdown[3,".. height ..";4,1;dd_setting_value;"for index, value inipairs(setting.values)do-- translating value is not possible, since it's the value-- that we set the setting to
formspec = formspec .. core.formspec_escape(value) ..","ifget_current_value(setting) == value then
selected_index = index
endendif#setting.values >0then
formspec = formspec:sub(1, -2)-- remove trailing commaend
formspec = formspec ..";".. selected_index .."]"
height = height +1.25elseif setting.type=="path"or setting.type=="filepath"thenlocal current_value = dialogdata.selected_path
if not current_value then
current_value =get_current_value(setting)end
formspec ="field[0.28,".. height +0.15..";8,1;te_setting_value;;".. core.formspec_escape(current_value) .."]".."button[8,".. height -0.15..";2,1;btn_browser_".. setting.type..";"..fgettext("Browse") .."]"
height = height +1.15elseif setting.type=="noise_params_2d"or setting.type=="noise_params_3d"thenlocal t =get_current_np_group(setting)local dimension =3if setting.type=="noise_params_2d"then
dimension =2end-- More space for 3x3 fields
description_height = description_height -1.5
height = height -1.5local fields = {}local functionadd_field(x, name, label, value)
fields[#fields +1] = ("field[%f,%f;3.3,1;%s;%s;%s]"):format(
x, height, name, label, core.formspec_escape(value or""))end-- First row
height = height +0.3add_field(0.3,"te_offset",fgettext("Offset"), t[1])add_field(3.6,"te_scale",fgettext("Scale"), t[2])add_field(6.9,"te_seed",fgettext("Seed"), t[6])
height = height +1.1-- Second rowadd_field(0.3,"te_spreadx",fgettext("X spread"), t[3])if dimension ==3thenadd_field(3.6,"te_spready",fgettext("Y spread"), t[4])else
fields[#fields +1] ="label[4,".. height -0.2..";"..fgettext("2D Noise") .."]"endadd_field(6.9,"te_spreadz",fgettext("Z spread"), t[5])
height = height +1.1-- Third rowadd_field(0.3,"te_octaves",fgettext("Octaves"), t[7])add_field(3.6,"te_persist",fgettext("Persistence"), t[8])add_field(6.9,"te_lacun",fgettext("Lacunarity"), t[9])
height = height +1.1local enabled_flags =flags_to_table(t[10])local flags = {}for _, name inipairs(enabled_flags)do-- Index by name, to avoid iterating over all enabled_flags for every possible flag.
flags[name] =trueendfor _, name inipairs(setting.flags)dolocal checkbox_name ="cb_".. name
local is_enabled = flags[name] ==true-- to get false if nil
checkboxes[checkbox_name] = is_enabled
end-- Flags
formspec =table.concat(fields).."checkbox[0.5,".. height -0.6..";cb_defaults;"--[[~ "defaults" is a noise parameter flag. It describes the default processing options for noise settings in main menu -> "All Settings". ]]..fgettext("defaults") ..";"-- defaults..tostring(flags["defaults"] ==true) .."]"-- to get false if nil.."checkbox[5,".. height -0.6..";cb_eased;"--[[~ "eased" is a noise parameter flag. It is used to make the map smoother and can be enabled in noise settings in main menu -> "All Settings". ]]..fgettext("eased") ..";"-- eased..tostring(flags["eased"] ==true) .."]".."checkbox[5,".. height -0.15..";cb_absvalue;"--[[~ "absvalue" is a noise parameter flag. It is short for "absolute value". It can be enabled in noise settings in main menu -> "All Settings". ]]..fgettext("absvalue") ..";"-- absvalue..tostring(flags["absvalue"] ==true) .."]"
height = height +1elseif setting.type=="v3f"thenlocal val =get_current_value(setting)local v3f = {}for line in val:gmatch("[+-]?[%d.+-eE]+")do-- All numeric characterstable.insert(v3f, line)end
height = height +0.3
formspec = formspec
.."field[0.3,".. height ..";3.3,1;te_x;"..fgettext("X") ..";"-- X.. core.formspec_escape(v3f[1]or"") .."]".."field[3.6,".. height ..";3.3,1;te_y;"..fgettext("Y") ..";"-- Y.. core.formspec_escape(v3f[2]or"") .."]".."field[6.9,".. height ..";3.3,1;te_z;"..fgettext("Z") ..";"-- Z.. core.formspec_escape(v3f[3]or"") .."]"
height = height +1.1elseif setting.type=="flags"thenlocal current_flags =flags_to_table(get_current_value(setting))local flags = {}for _, name inipairs(current_flags)do-- Index by name, to avoid iterating over all enabled_flags for every possible flag.if name:sub(1,2) =="no"then
flags[name:sub(3)] =falseelse
flags[name] =trueendendlocal flags_count = #setting.possible /2local max_height = math.ceil(flags_count /2) /2-- More space for flags
description_height = description_height -1
height = height -1local fields = {}-- To build formspeclocal j =1for _, name inipairs(setting.possible)doif name:sub(1,2) ~="no"thenlocal x =0.5local y = height + j /2-0.75if j -1>= flags_count /2then-- 2nd column
x =5
y = y - max_height
end
j = j +1;local checkbox_name ="cb_".. name
local is_enabled = flags[name] ==true-- to get false if nil
checkboxes[checkbox_name] = is_enabled
fields[#fields +1] = ("checkbox[%f,%f;%s;%s;%s]"):format(
x, y, checkbox_name, name,tostring(is_enabled))endend
formspec =table.concat(fields)
height = height + max_height +0.25else-- TODO: fancy input for float, intlocal text =get_current_value(setting)if dialogdata.error_message and dialogdata.entered_text then
text = dialogdata.entered_text
end
formspec ="field[0.28,".. height +0.15..";".. width ..",1;te_setting_value;;".. core.formspec_escape(text) .."]"
height = height +1.15end-- Box good, textarea bad. Calculate textarea size from box.local functioncreate_textfield(size, label, text, bg_color)local textarea = {
x = size.x +0.3,
y = size.y,
w = size.w +0.25,
h = size.h *1.16+0.12}return("box[%f,%f;%f,%f;%s]textarea[%f,%f;%f,%f;;%s;%s]"):format(
size.x, size.y, size.w, size.h, bg_color or"#000",
textarea.x, textarea.y, textarea.w, textarea.h,
core.formspec_escape(label), core.formspec_escape(text))end-- When there's an error: Shrink description textarea and add error belowif dialogdata.error_message thenlocal error_box = {
x =0,
y = description_height -0.4,
w = width -0.25,
h =0.5}
formspec = formspec ..create_textfield(error_box,"", dialogdata.error_message,"#600")
description_height = description_height -0.75end-- Get description fieldlocal description_box = {
x =0,
y =0.2,
w = width -0.25,
h = description_height
}local setting_name = setting.name
if setting.readable_name then
setting_name =fgettext_ne(setting.readable_name) .." (".. setting.name ..")"endlocal comment_text
if setting.comment ==""then
comment_text =fgettext_ne("(No description of setting given)")else
comment_text =fgettext_ne(setting.comment)endreturn("size[".. width ..",".. height +0.25..",true]"..create_textfield(description_box, setting_name, comment_text) ..
formspec .."button[".. width /2-2.5..",".. height -0.4..";2.5,1;btn_done;"..fgettext("Save") .."]".."button[".. width /2..",".. height -0.4..";2.5,1;btn_cancel;"..fgettext("Cancel") .."]")endlocal functionhandle_change_setting_buttons(this, fields)local setting = settings[selected_setting]if fields["btn_done"]or fields["key_enter"]thenif setting.type=="bool"thenlocal new_value = fields["dd_setting_value"]-- Note: new_value is the actual (translated) value shown in the dropdown
core.settings:set_bool(setting.name, new_value ==fgettext("Enabled"))elseif setting.type=="enum"thenlocal new_value = fields["dd_setting_value"]
core.settings:set(setting.name, new_value)elseif setting.type=="int"thenlocal new_value =tonumber(fields["te_setting_value"])if not new_value or math.floor(new_value) ~= new_value then
this.data.error_message =fgettext_ne("Please enter a valid integer.")
this.data.entered_text = fields["te_setting_value"]
core.update_formspec(this:get_formspec())return trueendif setting.minand new_value < setting.minthen
this.data.error_message =fgettext_ne("The value must be at least $1.", setting.min)
this.data.entered_text = fields["te_setting_value"]
core.update_formspec(this:get_formspec())return trueendif setting.maxand new_value > setting.maxthen
this.data.error_message =fgettext_ne("The value must not be larger than $1.", setting.max)
this.data.entered_text = fields["te_setting_value"]
core.update_formspec(this:get_formspec())return trueend
core.settings:set(setting.name, new_value)elseif setting.type=="float"thenlocal new_value =tonumber(fields["te_setting_value"])if not new_value then
this.data.error_message =fgettext_ne("Please enter a valid number.")
this.data.entered_text = fields["te_setting_value"]
core.update_formspec(this:get_formspec())return trueendif setting.minand new_value < setting.minthen
this.data.error_message =fgettext_ne("The value must be at least $1.", setting.min)
this.data.entered_text = fields["te_setting_value"]
core.update_formspec(this:get_formspec())return trueendif setting.maxand new_value > setting.maxthen
this.data.error_message =fgettext_ne("The value must not be larger than $1.", setting.max)
this.data.entered_text = fields["te_setting_value"]
core.update_formspec(this:get_formspec())return trueend
core.settings:set(setting.name, new_value)elseif setting.type=="flags"thenlocal values = {}for _, name inipairs(setting.possible)doif name:sub(1,2) ~="no"thenif checkboxes["cb_".. name]thentable.insert(values, name)elsetable.insert(values,"no".. name)endendend
checkboxes = {}local new_value =table.concat(values,", ")
core.settings:set(setting.name, new_value)elseif setting.type=="noise_params_2d"or setting.type=="noise_params_3d"thenlocal np_flags = {}for _, name inipairs(setting.flags)doif checkboxes["cb_".. name]thentable.insert(np_flags, name)endend
checkboxes = {}if setting.type=="noise_params_2d"then
fields["te_spready"] = fields["te_spreadz"]endlocal new_value = {
offset = fields["te_offset"],
scale = fields["te_scale"],
spread = {
x = fields["te_spreadx"],
y = fields["te_spready"],
z = fields["te_spreadz"]},
seed = fields["te_seed"],
octaves = fields["te_octaves"],
persistence = fields["te_persist"],
lacunarity = fields["te_lacun"],
flags =table.concat(np_flags,", ")}
core.settings:set_np_group(setting.name, new_value)elseif setting.type=="v3f"thenlocal new_value ="(".. fields["te_x"] ..", ".. fields["te_y"] ..", ".. fields["te_z"] ..")"
core.settings:set(setting.name, new_value)elselocal new_value = fields["te_setting_value"]
core.settings:set(setting.name, new_value)end
core.settings:write()
this:delete()return trueendif fields["btn_cancel"]then
this:delete()return trueendif fields["btn_browser_path"]then
core.show_path_select_dialog("dlg_browse_path",fgettext_ne("Select directory"),false)endif fields["btn_browser_filepath"]then
core.show_path_select_dialog("dlg_browse_path",fgettext_ne("Select file"),true)endif fields["dlg_browse_path_accepted"]then
this.data.selected_path = fields["dlg_browse_path_accepted"]
core.update_formspec(this:get_formspec())endif setting.type=="flags"or setting.type=="noise_params_2d"or setting.type=="noise_params_3d"thenfor name, value inpairs(fields)doif name:sub(1,3) =="cb_"then
checkboxes[name] = value =="true"endendendreturn falseendlocal functioncreate_settings_formspec(tabview, _, tabdata)local formspec ="size[12,5.4;true]".."tablecolumns[color;tree;text,width=28;text]".."tableoptions[background=#00000000;border=false]".."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,3.5;list_settings;"local current_level =0for _, entry inipairs(settings)dolocal name
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
endif entry.type=="category"then
current_level = entry.level
formspec = formspec .."#FFFF00,".. current_level ..","..fgettext(name) ..",,"elseif entry.type=="bool"thenlocal value =get_current_value(entry)if core.is_yes(value)then
value =fgettext("Enabled")else
value =fgettext("Disabled")end
formspec = formspec ..",".. (current_level +1) ..",".. core.formspec_escape(name) ..",".. value ..","elseif entry.type=="key"then--luacheck: ignore-- ignore key settings, since we have a special dialog for themelseif entry.type=="noise_params_2d"or entry.type=="noise_params_3d"then
formspec = formspec ..",".. (current_level +1) ..",".. core.formspec_escape(name) ..",".. core.formspec_escape(get_current_np_group_as_string(entry)) ..","else
formspec = formspec ..",".. (current_level +1) ..",".. core.formspec_escape(name) ..",".. core.formspec_escape(get_current_value(entry)) ..","endendif#settings >0then
formspec = formspec:sub(1, -2)-- remove trailing commaend
formspec = formspec ..";".. selected_setting .."]".."button[0,4.9;4,1;btn_back;"..fgettext("< Back to Settings page") .."]".."button[10,4.9;2,1;btn_edit;"..fgettext("Edit") .."]".."button[7,4.9;3,1;btn_restore;"..fgettext("Restore Default") .."]".."checkbox[0,4.3;cb_tech_settings;"..fgettext("Show technical names") ..";"..dump(core.settings:get_bool("main_menu_technical_settings")) .."]"return formspec
endlocal functionhandle_settings_buttons(this, fields, tabname, tabdata)local list_enter =falseif fields["list_settings"]then
selected_setting = core.get_table_index("list_settings")if core.explode_table_event(fields["list_settings"]).type=="DCL"then-- Directly toggle booleanslocal setting = settings[selected_setting]if setting and setting.type=="bool"thenlocal current_value =get_current_value(setting)
core.settings:set_bool(setting.name,not core.is_yes(current_value))
core.settings:write()return trueelse
list_enter =trueendelsereturn trueendendif fields.search or fields.key_enter_field =="search_string"thenif search_string == fields.search_string thenif selected_setting >0then-- Go to next result on enter presslocal i = selected_setting +1local looped =falsewhile i > #settings or settings[i].type=="category"do
i = i +1if i > #settings then-- Stop infinte loopingif looped thenreturn falseend
i =1
looped =trueendend
selected_setting = i
core.update_formspec(this:get_formspec())return trueendelse-- Search for setting
search_string = fields.search_string
settings, selected_setting =filter_settings(full_settings, search_string)
core.update_formspec(this:get_formspec())endreturn trueendif fields["btn_edit"]or list_enter thenlocal setting = settings[selected_setting]if setting and setting.type~="category"thenlocal edit_dialog =dialog_create("change_setting",
create_change_setting_formspec, handle_change_setting_buttons)
edit_dialog:set_parent(this)
this:hide()
edit_dialog:show()endreturn trueendif fields["btn_restore"]thenlocal setting = settings[selected_setting]if setting and setting.type~="category"then
core.settings:remove(setting.name)
core.settings:write()
core.update_formspec(this:get_formspec())endreturn trueendif fields["btn_back"]then
this:delete()return trueendif fields["cb_tech_settings"]then
core.settings:set("main_menu_technical_settings", fields["cb_tech_settings"])
core.settings:write()
core.update_formspec(this:get_formspec())return trueendreturn falseendfunctioncreate_adv_settings_dlg()local dlg =dialog_create("settings_advanced",
create_settings_formspec,
handle_settings_buttons,nil)return dlg
end-- Uncomment to generate 'minetest.conf.example' and 'settings_translation_file.cpp'.-- For RUN_IN_PLACE the generated files may appear in the 'bin' folder.-- See comment and alternative line at the end of 'generate_from_settingtypes.lua'.--assert(loadfile(core.get_builtin_path().."mainmenu"..DIR_DELIM..-- "generate_from_settingtypes.lua"))(parse_config_file(true, false))