Mainmenu: Restore ability to enable flags in settings (#14896)

Fixes flags starting with "no" being hidden
This commit is contained in:
Lars Müller 2024-07-30 21:24:59 +02:00 committed by GitHub
parent 90fccc15eb
commit 30dcd41d91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -306,17 +306,36 @@ function make.flags(setting)
"label[0,0.1;" .. get_label(setting) .. "]", "label[0,0.1;" .. get_label(setting) .. "]",
} }
local value = core.settings:get(setting.name) or setting.default
self.resettable = core.settings:has(setting.name) self.resettable = core.settings:has(setting.name)
checkboxes = {} checkboxes = {}
for _, name in ipairs(value:split(",")) do for _, name in ipairs(setting.possible) do
name = name:trim() checkboxes[name] = false
if name:sub(1, 2) == "no" then
checkboxes[name:sub(3)] = false
elseif name ~= "" then
checkboxes[name] = true
end end
local function apply_flags(flag_string, what)
local prefixed_flags = {}
for _, name in ipairs(flag_string:split(",")) do
prefixed_flags[name:trim()] = true
end
for _, name in ipairs(setting.possible) do
local enabled = prefixed_flags[name]
local disabled = prefixed_flags["no" .. name]
if enabled and disabled then
core.log("warning", "Flag " .. name .. " in " .. what .. " " ..
setting.name .. " both enabled and disabled, ignoring")
elseif enabled then
checkboxes[name] = true
elseif disabled then
checkboxes[name] = false
end
end
end
-- First apply the default, which is necessary since flags
-- which are not overridden may be missing from the value.
apply_flags(setting.default, "default for setting")
local value = core.settings:get(setting.name)
if value then
apply_flags(value, "setting")
end end
local columns = math.max(math.floor(avail_w / 2.5), 1) local columns = math.max(math.floor(avail_w / 2.5), 1)
@ -325,7 +344,6 @@ function make.flags(setting)
local y = 0.55 local y = 0.55
for _, possible in ipairs(setting.possible) do for _, possible in ipairs(setting.possible) do
if possible:sub(1, 2) ~= "no" then
if x >= avail_w then if x >= avail_w then
x = 0 x = 0
y = y + 0.5 y = y + 0.5
@ -337,7 +355,6 @@ function make.flags(setting)
core.formspec_escape(possible), tostring(is_checked)) core.formspec_escape(possible), tostring(is_checked))
x = x + column_width x = x + column_width
end end
end
return table.concat(fs, ""), y + 0.25 return table.concat(fs, ""), y + 0.25
end, end,
@ -355,14 +372,12 @@ function make.flags(setting)
if changed then if changed then
local values = {} local values = {}
for _, name in ipairs(setting.possible) do for _, name in ipairs(setting.possible) do
if name:sub(1, 2) ~= "no" then
if checkboxes[name] then if checkboxes[name] then
table.insert(values, name) table.insert(values, name)
else else
table.insert(values, "no" .. name) table.insert(values, "no" .. name)
end end
end end
end
core.settings:set(setting.name, table.concat(values, ",")) core.settings:set(setting.name, table.concat(values, ","))
end end