mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
'All Settings': Don't use checkboxes for 'no...' mapgen flags (#7847)
This commit is contained in:
parent
0013f064ad
commit
cd1d01b8b4
3 changed files with 31 additions and 21 deletions
|
@ -670,14 +670,18 @@ local function create_change_setting_formspec(dialogdata)
|
|||
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
|
||||
|
@ -685,19 +689,21 @@ local function create_change_setting_formspec(dialogdata)
|
|||
|
||||
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
|
||||
if name:sub(1, 2) ~= "no" then
|
||||
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)
|
||||
)
|
||||
fields[#fields + 1] = ("checkbox[%f,%f;%s;%s;%s]"):format(
|
||||
x, y, checkbox_name, name, tostring(is_enabled)
|
||||
)
|
||||
end
|
||||
end
|
||||
formspec = table.concat(fields)
|
||||
height = height + max_height + 0.25
|
||||
|
@ -833,8 +839,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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue