Skip to content

Commit 7e53e65

Browse files
authored
Show unavailable settings in menu (#16679)
1 parent 7c310cd commit 7e53e65

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

builtin/common/settings/components.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,33 @@ local function is_valid_number(value)
4545
end
4646

4747

48-
function make.heading(text)
48+
function make.heading(text, info_text)
4949
return {
5050
full_width = true,
51+
info_text = info_text,
5152
get_formspec = function(self, avail_w)
5253
return ("label[0,0.6;%s]box[0,0.9;%f,0.05;#ccc6]"):format(core.formspec_escape(text), avail_w), 1.2
5354
end,
5455
}
5556
end
5657

5758

59+
function make.unavail_list(settings)
60+
return {
61+
full_width = true,
62+
get_formspec = function(self, avail_w)
63+
local h = 0.2
64+
local fs = {}
65+
for _, setting in ipairs(settings) do
66+
fs[#fs + 1] = ("label[0.3,%f;%s]"):format(h,
67+
core.colorize("#bbb", core.formspec_escape(get_label(setting))))
68+
h = h + 0.4
69+
end
70+
return table.concat(fs, ""), h
71+
end,
72+
}
73+
end
74+
5875
function make.note(text)
5976
return {
6077
full_width = true,

builtin/common/settings/dlg_settings.lua

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ local function load()
137137

138138
-- insert after "touch_controls"
139139
table.insert(page_by_id.controls_touchscreen.content, 2, touchscreen_layout)
140+
140141
do
141142
local content = page_by_id.graphics_and_audio_effects.content
142143
local idx = table.indexof(content, "enable_dynamic_shadows")
@@ -407,18 +408,8 @@ function page_has_contents(page, actual_content)
407408
for _, item in ipairs(actual_content) do
408409
if item == false or item.heading then --luacheck: ignore
409410
-- skip
410-
elseif type(item) == "string" then
411-
local setting = get_setting_info(item)
412-
assert(setting, "Unknown setting: " .. item)
413-
if check_requirements(setting.name, setting.requires, setting.context) then
414-
return true
415-
end
416-
elseif item.get_formspec then
417-
if check_requirements(item.id, item.requires, item.context) then
418-
return true
419-
end
420411
else
421-
error("Unknown content in page: " .. dump(item))
412+
return true
422413
end
423414
end
424415

@@ -429,6 +420,7 @@ end
429420
local function build_page_components(page)
430421
-- Filter settings based on requirements
431422
local content = {}
423+
local settings_off = {}
432424
local last_heading
433425
for _, item in ipairs(page.content) do
434426
if item == false then --luacheck: ignore
@@ -437,8 +429,9 @@ local function build_page_components(page)
437429
last_heading = item
438430
else
439431
local name, requires, context
432+
local setting
440433
if type(item) == "string" then
441-
local setting = get_setting_info(item)
434+
setting = get_setting_info(item)
442435
assert(setting, "Unknown setting: " .. item)
443436
name = setting.name
444437
requires = setting.requires
@@ -457,6 +450,8 @@ local function build_page_components(page)
457450
last_heading = nil
458451
end
459452
content[#content + 1] = item
453+
elseif setting then
454+
settings_off[#settings_off + 1] = setting
460455
end
461456
end
462457
end
@@ -475,6 +470,14 @@ local function build_page_components(page)
475470
retval[i] = component_funcs.heading(item.heading)
476471
end
477472
end
473+
474+
if #settings_off > 0 then
475+
retval[#retval + 1] = component_funcs.heading(fgettext_ne("Unavailable"),
476+
-- luacheck: ignore
477+
fgettext_ne("These settings are unavailable due to your platform, hardware or in combination with the current settings.")
478+
)
479+
retval[#retval + 1] = component_funcs.unavail_list(settings_off)
480+
end
478481
return retval
479482
end
480483

0 commit comments

Comments
 (0)