+ .. "button[8," .. height - 0.15 .. ";2,1;btn_browser_"
+ .. setting.type .. ";" .. fgettext("Browse") .. "]"
+ height = height + 1.15
+
+ elseif setting.type == "noise_params_2d" or setting.type == "noise_params_3d" then
+ local t = get_current_np_group(setting)
+ local dimension = 3
+ if setting.type == "noise_params_2d" then
+ dimension = 2
+ end
+
+ -- More space for 3x3 fields
+ description_height = description_height - 1.5
+ height = height - 1.5
+
+ local fields = {}
+ local function add_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.3
+ add_field(0.3, "te_offset", "Offset", t[1])
+ add_field(3.6, "te_scale", "Scale", t[2])
+ add_field(6.9, "te_seed", "Seed", t[6])
+ height = height + 1.1
+
+ -- Second row
+ add_field(0.3, "te_spreadx", "X spread", t[3])
+ if dimension == 3 then
+ add_field(3.6, "te_spready", "Y spread", t[4])
+ else
+ fields[#fields + 1] = "label[4," .. height - 0.2 .. ";2D Noise]"
+ end
+ add_field(6.9, "te_spreadz", "Z spread", t[5])
+ height = height + 1.1
+
+ -- Third row
+ add_field(0.3, "te_octaves", "Octaves", t[7])
+ add_field(3.6, "te_persist", "Persistance", t[8])
+ add_field(6.9, "te_lacun", "Lacunarity", t[9])
+ height = height + 1.1
+
+
+ local enabled_flags = flags_to_table(t[10])
+ local flags = {}
+ for _, name in ipairs(enabled_flags) do
+ -- Index by name, to avoid iterating over all enabled_flags for every possible flag.
+ flags[name] = true
+ end
+ for _, name in ipairs(setting.flags) do
+ local 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;" -- defaults
+ .. tostring(flags["defaults"] == true) .. "]" -- to get false if nil
+ .. "checkbox[5," .. height - 0.6 .. ";cb_eased;eased;" -- eased
+ .. tostring(flags["eased"] == true) .. "]"
+ .. "checkbox[5," .. height - 0.15 .. ";cb_absvalue;absvalue;" -- absvalue
+ .. tostring(flags["absvalue"] == true) .. "]"
+ height = height + 1
+
+ elseif setting.type == "v3f" then
+ local val = get_current_value(setting)
+ local v3f = {}
+ for line in val:gmatch("[+-]?[%d.-e]+") do -- All numeric characters
+ table.insert(v3f, line)
+ end
+
+ height = height + 0.3
+ formspec = formspec
+ .. "field[0.3," .. height .. ";3.3,1;te_x;X;" -- X
+ .. core.formspec_escape(v3f[1] or "") .. "]"
+ .. "field[3.6," .. height .. ";3.3,1;te_y;Y;" -- Y
+ .. core.formspec_escape(v3f[2] or "") .. "]"
+ .. "field[6.9," .. height .. ";3.3,1;te_z;Z;" -- Z
+ .. core.formspec_escape(v3f[3] or "") .. "]"
+ height = height + 1.1
+
+ elseif setting.type == "flags" then
+ local enabled_flags = flags_to_table(get_current_value(setting))
+ local flags = {}
+ for _, name in ipairs(enabled_flags) do
+ -- Index by name, to avoid iterating over all enabled_flags for every possible flag.
+ flags[name] = true
+ end
+ local flags_count = #setting.possible
+ local max_height = flags_count / 4
+
+ -- More space for flags
+ description_height = description_height - 1
+ height = height - 1
+
+ local fields = {} -- To build formspec
+ for i, name in ipairs(setting.possible) do
+ local x = 0.5
+ local y = height + i / 2 - 0.75
+ if i - 1 >= flags_count / 2 then -- 2nd column
+ x = 5
+ y = y - max_height
+ end
+ 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)
+ )
+ end
+ formspec = table.concat(fields)
+ height = height + max_height + 0.25