X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=builtin%2Fmainmenu%2Fdlg_settings_advanced.lua;h=d6f485cf73d29c2176b1c16a51bf8b2e94e9b2d4;hb=21df26984da91143c15587f5a03c98d68c3adc4e;hp=4a6fcfba7cef84d303efb0435c85dc41d1207e51;hpb=0d54399be2af37e334f3506bd09da85ad932b92f;p=dragonfireclient.git diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index 4a6fcfba7..d6f485cf7 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -31,6 +31,10 @@ end -- returns error message, or nil local function parse_setting_line(settings, line, read_all, base_level, allow_secure) + + -- strip carriage returns (CR, /r) + line = line:gsub("\r", "") + -- comment local comment = line:match("^#" .. CHAR_CLASSES.SPACE .. "*(.*)$") if comment then @@ -148,9 +152,9 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se local values = {} local ti = 1 local index = 1 - for line in default:gmatch("[+-]?[%d.-e]+") do -- All numeric characters - index = default:find("[+-]?[%d.-e]+", index) + line:len() - table.insert(values, line) + for match in default:gmatch("[+-]?[%d.-e]+") do -- All numeric characters + index = default:find("[+-]?[%d.-e]+", index) + match:len() + table.insert(values, match) ti = ti + 1 if ti > 9 then break @@ -322,17 +326,20 @@ end -- read_all: whether to ignore certain setting types for GUI or not -- parse_mods: whether to parse settingtypes.txt in mods and games local function parse_config_file(read_all, parse_mods) - local builtin_path = core.get_builtin_path() .. FILENAME - local file = io.open(builtin_path, "r") local settings = {} - if not file then - core.log("error", "Can't load " .. FILENAME) - return settings - end - parse_single_file(file, builtin_path, read_all, settings, 0, true) + do + local 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 + end + + parse_single_file(file, builtin_path, read_all, settings, 0, true) - file:close() + file:close() + end if parse_mods then -- Parse games @@ -344,7 +351,7 @@ local function parse_config_file(read_all, parse_mods) local file = io.open(path, "r") if file then if not games_category_initialized then - local translation = fgettext_ne("Games"), -- not used, but needed for xgettext + fgettext_ne("Games") -- not used, but needed for xgettext table.insert(settings, { name = "Games", level = 0, @@ -371,13 +378,13 @@ local function parse_config_file(read_all, parse_mods) -- Parse mods local mods_category_initialized = false local mods = {} - get_mods(core.get_modpath(), mods) + get_mods(core.get_modpath(), "mods", mods) for _, mod in ipairs(mods) do local path = mod.path .. DIR_DELIM .. FILENAME local file = io.open(path, "r") if file then if not mods_category_initialized then - local translation = fgettext_ne("Mods"), -- not used, but needed for xgettext + fgettext_ne("Mods") -- not used, but needed for xgettext table.insert(settings, { name = "Mods", level = 0, @@ -388,6 +395,37 @@ local function parse_config_file(read_all, parse_mods) table.insert(settings, { name = mod.name, + readable_name = mod.title, + level = 1, + type = "category", + }) + + parse_single_file(file, path, read_all, settings, 2, false) + + file:close() + end + end + + -- Parse clientmods + local clientmods_category_initialized = false + local clientmods = {} + get_mods(core.get_clientmodpath(), "clientmods", clientmods) + for _, clientmod in ipairs(clientmods) do + local path = clientmod.path .. DIR_DELIM .. FILENAME + local file = io.open(path, "r") + if file then + if not clientmods_category_initialized then + fgettext_ne("Clientmods") -- not used, but needed for xgettext + table.insert(settings, { + name = "Clientmods", + level = 0, + type = "category", + }) + clientmods_category_initialized = true + end + + table.insert(settings, { + name = clientmod.name, level = 1, type = "category", }) @@ -490,42 +528,40 @@ end local function get_current_np_group(setting) local value = core.settings:get_np_group(setting.name) - local t = {} if value == nil then - t = setting.values - else - table.insert(t, value.offset) - table.insert(t, value.scale) - table.insert(t, value.spread.x) - table.insert(t, value.spread.y) - table.insert(t, value.spread.z) - table.insert(t, value.seed) - table.insert(t, value.octaves) - table.insert(t, value.persistence) - table.insert(t, value.lacunarity) - table.insert(t, value.flags) + return setting.values end - return t + local 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 + } end local function get_current_np_group_as_string(setting) local value = core.settings:get_np_group(setting.name) - local t if value == nil then - t = setting.default - else - t = value.offset .. ", " .. - value.scale .. ", (" .. - value.spread.x .. ", " .. - value.spread.y .. ", " .. - value.spread.z .. "), " .. - value.seed .. ", " .. - value.octaves .. ", " .. - value.persistence .. ", " .. - value.lacunarity .. ", " .. - value.flags + return setting.default end - return t + return ("%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 "") end local checkboxes = {} -- handle checkboxes events @@ -597,25 +633,26 @@ local function create_change_setting_formspec(dialogdata) 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]) + add_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 row - add_field(0.3, "te_spreadx", "X spread", t[3]) + add_field(0.3, "te_spreadx", fgettext("X spread"), t[3]) if dimension == 3 then - add_field(3.6, "te_spready", "Y spread", t[4]) + add_field(3.6, "te_spready", fgettext("Y spread"), t[4]) else - fields[#fields + 1] = "label[4," .. height - 0.2 .. ";2D Noise]" + fields[#fields + 1] = "label[4," .. height - 0.2 .. ";" .. + fgettext("2D Noise") .. "]" end - add_field(6.9, "te_spreadz", "Z spread", t[5]) + add_field(6.9, "te_spreadz", fgettext("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]) + add_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.1 @@ -632,60 +669,85 @@ local function create_change_setting_formspec(dialogdata) end -- Flags formspec = table.concat(fields) - .. "checkbox[0.5," .. height - 0.6 .. ";cb_defaults;defaults;" -- defaults + .. "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;" -- eased + .. "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;" -- absvalue + .. "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 + 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 + for line in val:gmatch("[+-]?[%d.+-eE]+") 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 + .. "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;Y;" -- Y + .. "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;Z;" -- Z + .. "field[6.9," .. height .. ";3.3,1;te_z;" + .. fgettext("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 current_flags = flags_to_table(get_current_value(setting)) local flags = {} - for _, name in ipairs(enabled_flags) do + for _, name in ipairs(current_flags) do -- Index by name, to avoid iterating over all enabled_flags for every possible flag. - flags[name] = true + if name:sub(1, 2) == "no" then + flags[name:sub(3)] = false + else + flags[name] = true + end end - local flags_count = #setting.possible - local max_height = flags_count / 4 + local flags_count = #setting.possible / 2 + local max_height = math.ceil(flags_count / 2) / 2 -- 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 + local j = 1 + for _, name in ipairs(setting.possible) do + if name:sub(1, 2) ~= "no" then + local x = 0.5 + local y = height + j / 2 - 0.75 + if j - 1 >= flags_count / 2 then -- 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) + ) 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 @@ -744,7 +806,7 @@ local function create_change_setting_formspec(dialogdata) " (" .. setting.name .. ")" end - local comment_text = "" + local comment_text if setting.comment == "" then comment_text = fgettext_ne("(No description of setting given)") else @@ -821,8 +883,12 @@ local function handle_change_setting_buttons(this, fields) elseif setting.type == "flags" then local values = {} for _, name in ipairs(setting.possible) do - if checkboxes["cb_" .. name] then - table.insert(values, name) + if name:sub(1, 2) ~= "no" then + if checkboxes["cb_" .. name] then + table.insert(values, name) + else + table.insert(values, "no" .. name) + end end end @@ -909,7 +975,7 @@ local function handle_change_setting_buttons(this, fields) return false end -local function create_settings_formspec(tabview, name, tabdata) +local function create_settings_formspec(tabview, _, tabdata) local formspec = "size[12,5.4;true]" .. "tablecolumns[color;tree;text,width=28;text]" .. "tableoptions[background=#00000000;border=false]" .. @@ -921,7 +987,7 @@ local function create_settings_formspec(tabview, name, tabdata) local current_level = 0 for _, entry in ipairs(settings) do local name - if not core.settings:get_bool("main_menu_technical_settings") and entry.readable_name then + if not core.settings:get_bool("show_technical_names") and entry.readable_name then name = fgettext_ne(entry.readable_name) else name = entry.name @@ -941,7 +1007,7 @@ local function create_settings_formspec(tabview, name, tabdata) formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. "," .. value .. "," - elseif entry.type == "key" then + elseif entry.type == "key" then --luacheck: ignore -- ignore key settings, since we have a special dialog for them elseif entry.type == "noise_params_2d" or entry.type == "noise_params_3d" then @@ -962,7 +1028,7 @@ local function create_settings_formspec(tabview, name, tabdata) "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")) .. "]" + .. dump(core.settings:get_bool("show_technical_names")) .. "]" return formspec end @@ -1020,8 +1086,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) if fields["btn_edit"] or list_enter then local setting = settings[selected_setting] if setting and setting.type ~= "category" then - local edit_dialog = dialog_create("change_setting", create_change_setting_formspec, - handle_change_setting_buttons) + local edit_dialog = dialog_create("change_setting", + create_change_setting_formspec, handle_change_setting_buttons) edit_dialog:set_parent(this) this:hide() edit_dialog:show() @@ -1045,7 +1111,7 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) end if fields["cb_tech_settings"] then - core.settings:set("main_menu_technical_settings", fields["cb_tech_settings"]) + core.settings:set("show_technical_names", fields["cb_tech_settings"]) core.settings:write() core.update_formspec(this:get_formspec()) return true @@ -1063,7 +1129,9 @@ function create_adv_settings_dlg() 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 +-- 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)) +--assert(loadfile(core.get_builtin_path().."mainmenu"..DIR_DELIM.. +-- "generate_from_settingtypes.lua"))(parse_config_file(true, false))