Skip to content

Commit

Permalink
Settings GUI: Noise parameter setting fixes (#13797)
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Sep 16, 2023
1 parent 8ebaf75 commit 4f735fb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 4 additions & 0 deletions builtin/mainmenu/settings/components.lua
Expand Up @@ -368,6 +368,10 @@ local function noise_params(setting)
setting = setting,

get_formspec = function(self, avail_w)
-- The "defaults" noise parameter flag doesn't reset a noise
-- setting to its default value, so we offer a regular reset button.
self.resettable = core.settings:has(setting.name)

local fs = "label[0,0.4;" .. get_label(setting) .. "]" ..
("button[%f,0;2.5,0.8;%s;%s]"):format(avail_w - 2.5, "edit_" .. setting.name, fgettext("Edit"))
return fs, 0.8
Expand Down
23 changes: 13 additions & 10 deletions builtin/mainmenu/settings/dlg_change_mapgen_flags.lua
Expand Up @@ -49,19 +49,15 @@ local function get_formspec(dialogdata)
-- Final formspec will be created at the end of this function
-- Default values below, may be changed depending on setting type
local width = 10
local height = 3.5
local description_height = 3
local height = 2
local description_height = 1.5

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(
Expand Down Expand Up @@ -109,21 +105,21 @@ local function get_formspec(dialogdata)
.. "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". ]]
for noise settings in the settings menu. ]]
.. 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". ]]
the settings menu. ]]
.. 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". ]]
the settings menu. ]]
.. fgettext("absvalue") .. ";" -- absvalue
.. tostring(flags["absvalue"] == true) .. "]"

Expand Down Expand Up @@ -204,7 +200,7 @@ local function buttonhandler(this, fields)
checkboxes = {}

if setting.type == "noise_params_2d" then
fields["te_spready"] = fields["te_spreadz"]
fields["te_spready"] = fields["te_spreadz"]
end
local new_value = {
offset = fields["te_offset"],
Expand Down Expand Up @@ -232,6 +228,13 @@ local function buttonhandler(this, fields)
return true
end

for name, value in pairs(fields) do
if name:sub(1, 3) == "cb_" then
checkboxes[name] = core.is_yes(value)
return false -- Don't update the formspec!
end
end

return false
end

Expand Down
2 changes: 1 addition & 1 deletion builtin/mainmenu/settings/init.lua
Expand Up @@ -25,4 +25,4 @@ dofile(path .. DIR_DELIM .. "dlg_settings.lua")
-- 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(path .. DIR_DELIM .. "generate_from_settingtypes.lua"))(parse_config_file(true, false))
-- assert(loadfile(path .. DIR_DELIM .. "generate_from_settingtypes.lua"))(settingtypes.parse_config_file(true, false))
1 change: 0 additions & 1 deletion builtin/mainmenu/settings/settingtypes.lua
Expand Up @@ -198,7 +198,6 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se
local flags = ""
if index then
flags = default:sub(index)
default = default:sub(1, index - 3) -- Make sure no flags in single-line format
end
table.insert(values, flags)

Expand Down

0 comments on commit 4f735fb

Please sign in to comment.