Fix shadows dropdown and clean up shader settings (#13481)

This commit is contained in:
rubenwardy 2023-05-03 22:28:02 +01:00 committed by GitHub
parent ad37df7f2e
commit bc4fc6d648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,7 @@
--Minetest --Minetest
--Copyright (C) 2022 rubenwardy --Copyright (C) 2013 sapier
--Copyright (C) 2021-2 x2048
--Copyright (C) 2022-3 rubenwardy
-- --
--This program is free software; you can redistribute it and/or modify --This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by --it under the terms of the GNU Lesser General Public License as published by
@ -26,23 +28,21 @@ local shadow_levels_labels = {
} }
local shadow_levels_options = { local function get_shadow_mapping_idx()
table.concat(shadow_levels_labels, ","), local level = tonumber(core.settings:get("shadow_levels"))
{ "0", "1", "2", "3", "4", "5" } if level and level >= 0 and level < #shadow_levels_labels then
} return level + 1
local function get_shadow_mapping_id()
local shadow_setting = core.settings:get("shadow_levels")
for i = 1, #shadow_levels_options[2] do
if shadow_setting == shadow_levels_options[2][i] then
return i
end
end end
return 1 return 1
end end
local function set_shadow_mapping_idx(v)
assert(v >= 1 and v <= #shadow_levels_labels)
core.settings:set("shadow_levels", tostring(v - 1))
end
return { return {
query_text = "Shaders", query_text = "Shaders",
get_formspec = function(self, avail_w) get_formspec = function(self, avail_w)
@ -81,7 +81,8 @@ return {
if video_driver == "opengl" then if video_driver == "opengl" then
fs = fs .. fs = fs ..
"label[0,2.2;" .. fgettext("Dynamic shadows") .. "]" .. "label[0,2.2;" .. fgettext("Dynamic shadows") .. "]" ..
"dropdown[0,2.4;3,0.8;dd_shadows;" .. shadow_levels_options[1] .. ";" .. get_shadow_mapping_id() .. "]" .. "dropdown[0,2.4;3,0.8;dd_shadows;" .. table.concat(shadow_levels_labels, ",") .. ";" ..
get_shadow_mapping_idx() .. ";true]" ..
"label[0,3.5;" .. core.colorize("#bbb", fgettext("(The game will need to enable shadows as well)")) .. "]" "label[0,3.5;" .. core.colorize("#bbb", fgettext("(The game will need to enable shadows as well)")) .. "]"
else else
fs = fs .. fs = fs ..
@ -129,15 +130,15 @@ return {
return true return true
end end
for i = 1, #shadow_levels_labels do if fields.dd_shadows then
if fields.dd_shadows == shadow_levels_labels[i] then local old_shadow_level_idx = get_shadow_mapping_idx()
core.settings:set("shadow_levels", shadow_levels_options[2][i]) local shadow_level_idx = tonumber(fields.dd_shadows)
if shadow_level_idx == nil or shadow_level_idx == old_shadow_level_idx then
return false
end end
end
if fields.dd_shadows == shadow_levels_labels[1] then set_shadow_mapping_idx(shadow_level_idx)
core.settings:set("enable_dynamic_shadows", "false")
else
local shadow_presets = { local shadow_presets = {
[2] = { 62, 512, "true", 0, "false" }, [2] = { 62, 512, "true", 0, "false" },
[3] = { 93, 1024, "true", 0, "false" }, [3] = { 93, 1024, "true", 0, "false" },
@ -145,15 +146,18 @@ return {
[5] = { 210, 4096, "true", 2, "true" }, [5] = { 210, 4096, "true", 2, "true" },
[6] = { 300, 8192, "true", 2, "true" }, [6] = { 300, 8192, "true", 2, "true" },
} }
local s = shadow_presets[table.indexof(shadow_levels_labels, fields.dd_shadows)] local preset = shadow_presets[shadow_level_idx]
if s then if preset then
core.settings:set("enable_dynamic_shadows", "true") core.settings:set("enable_dynamic_shadows", "true")
core.settings:set("shadow_map_max_distance", s[1]) core.settings:set("shadow_map_max_distance", preset[1])
core.settings:set("shadow_map_texture_size", s[2]) core.settings:set("shadow_map_texture_size", preset[2])
core.settings:set("shadow_map_texture_32bit", s[3]) core.settings:set("shadow_map_texture_32bit", preset[3])
core.settings:set("shadow_filters", s[4]) core.settings:set("shadow_filters", preset[4])
core.settings:set("shadow_map_color", s[5]) core.settings:set("shadow_map_color", preset[5])
else
core.settings:set("enable_dynamic_shadows", "false")
end end
return true
end end
end, end,
} }