From 752ce1a1b23ece5373a2711f7151d0e41cf8be01 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 5 Aug 2023 17:33:18 +0100 Subject: [PATCH] Settings GUI: Move shadow presets to Shaders, remove Most Used (#13713) --- builtin/mainmenu/settings/dlg_settings.lua | 34 +--- .../mainmenu/settings/shader_component.lua | 163 ------------------ .../mainmenu/settings/shadows_component.lua | 121 +++++++++++++ builtin/settingtypes.txt | 2 +- minetest.conf.example | 2 +- src/defaultsettings.cpp | 2 +- 6 files changed, 131 insertions(+), 193 deletions(-) delete mode 100644 builtin/mainmenu/settings/shader_component.lua create mode 100644 builtin/mainmenu/settings/shadows_component.lua diff --git a/builtin/mainmenu/settings/dlg_settings.lua b/builtin/mainmenu/settings/dlg_settings.lua index dc56e5767..92b1acf8e 100644 --- a/builtin/mainmenu/settings/dlg_settings.lua +++ b/builtin/mainmenu/settings/dlg_settings.lua @@ -19,8 +19,8 @@ local component_funcs = dofile(core.get_mainmenu_path() .. DIR_DELIM .. "settings" .. DIR_DELIM .. "components.lua") -local quick_shader_component = dofile(core.get_mainmenu_path() .. DIR_DELIM .. - "settings" .. DIR_DELIM .. "shader_component.lua") +local shadows_component = dofile(core.get_mainmenu_path() .. DIR_DELIM .. + "settings" .. DIR_DELIM .. "shadows_component.lua") local full_settings = settingtypes.parse_config_file(false, true) @@ -61,31 +61,6 @@ local change_keys = { } -add_page({ - id = "most_used", - title = gettext("Most Used"), - content = { - change_keys, - "language", - "fullscreen", - PLATFORM ~= "Android" and "autosave_screensize" or false, - "touchscreen_threshold", - { heading = gettext("Scaling") }, - "gui_scaling", - "hud_scaling", - { heading = gettext("Graphics / Performance") }, - "smooth_lighting", - "enable_particles", - "enable_3d_clouds", - "opaque_water", - "connected_glass", - "node_highlighting", - "leaves_style", - { heading = gettext("Shaders") }, - quick_shader_component, - }, -}) - add_page({ id = "accessibility", title = gettext("Accessibility"), @@ -155,6 +130,11 @@ end load_settingtypes() table.insert(page_by_id.controls_keyboard_and_mouse.content, 1, change_keys) +do + local content = page_by_id.graphics_and_audio_shaders.content + local idx = table.indexof(content, "enable_dynamic_shadows") + table.insert(content, idx, shadows_component) +end local function get_setting_info(name) diff --git a/builtin/mainmenu/settings/shader_component.lua b/builtin/mainmenu/settings/shader_component.lua deleted file mode 100644 index 3db18dbc4..000000000 --- a/builtin/mainmenu/settings/shader_component.lua +++ /dev/null @@ -1,163 +0,0 @@ ---Minetest ---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 ---it under the terms of the GNU Lesser General Public License as published by ---the Free Software Foundation; either version 2.1 of the License, or ---(at your option) any later version. --- ---This program is distributed in the hope that it will be useful, ---but WITHOUT ANY WARRANTY; without even the implied warranty of ---MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ---GNU Lesser General Public License for more details. --- ---You should have received a copy of the GNU Lesser General Public License along ---with this program; if not, write to the Free Software Foundation, Inc., ---51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - -local shadow_levels_labels = { - fgettext("Disabled"), - fgettext("Very Low"), - fgettext("Low"), - fgettext("Medium"), - fgettext("High"), - fgettext("Very High") -} - - -local function get_shadow_mapping_idx() - local level = tonumber(core.settings:get("shadow_levels")) - if level and level >= 0 and level < #shadow_levels_labels then - return level + 1 - end - return 1 -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 { - query_text = "Shaders", - get_formspec = function(self, avail_w) - local fs = "" - - local video_driver = core.get_active_driver() - local shaders_enabled = core.settings:get_bool("enable_shaders") - if video_driver == "opengl" then - fs = fs .. - "checkbox[0,0.25;cb_shaders;" .. fgettext("Shaders") .. ";" - .. tostring(shaders_enabled) .. "]" - elseif video_driver == "ogles2" then - fs = fs .. - "checkbox[0,0.25;cb_shaders;" .. fgettext("Shaders (experimental)") .. ";" - .. tostring(shaders_enabled) .. "]" - else - core.settings:set_bool("enable_shaders", false) - shaders_enabled = false - fs = fs .. - "label[0.13,0.25;" .. core.colorize("#888888", - fgettext("Shaders (unavailable)")) .. "]" - end - - if shaders_enabled then - fs = fs .. - "container[0,0.75]" .. - "checkbox[0,0;cb_tonemapping;" .. fgettext("Tone mapping") .. ";" - .. tostring(core.settings:get_bool("tone_mapping")) .. "]" .. - "checkbox[0,0.5;cb_waving_water;" .. fgettext("Waving liquids") .. ";" - .. tostring(core.settings:get_bool("enable_waving_water")) .. "]" .. - "checkbox[0,1;cb_waving_leaves;" .. fgettext("Waving leaves") .. ";" - .. tostring(core.settings:get_bool("enable_waving_leaves")) .. "]" .. - "checkbox[0,1.5;cb_waving_plants;" .. fgettext("Waving plants") .. ";" - .. tostring(core.settings:get_bool("enable_waving_plants")) .. "]" - - if video_driver == "opengl" then - fs = fs .. - "label[0,2.2;" .. fgettext("Dynamic shadows") .. "]" .. - "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)")) .. "]" - else - fs = fs .. - "label[0,2.2;" .. core.colorize("#888888", fgettext("Dynamic shadows")) .. "]" - end - - fs = fs .. "container_end[]" - else - fs = fs .. - "container[0.35,0.75]" .. - "label[0,0;" .. core.colorize("#888888", - fgettext("Tone mapping")) .. "]" .. - "label[0,0.5;" .. core.colorize("#888888", - fgettext("Waving liquids")) .. "]" .. - "label[0,1;" .. core.colorize("#888888", - fgettext("Waving leaves")) .. "]" .. - "label[0,1.5;" .. core.colorize("#888888", - fgettext("Waving plants")) .. "]".. - "label[0,2;" .. core.colorize("#888888", - fgettext("Dynamic shadows")) .. "]" .. - "container_end[]" - end - return fs, 4.5 - end, - - on_submit = function(self, fields) - if fields.cb_shaders then - core.settings:set("enable_shaders", fields.cb_shaders) - return true - end - if fields.cb_tonemapping then - core.settings:set("tone_mapping", fields.cb_tonemapping) - return true - end - if fields.cb_waving_water then - core.settings:set("enable_waving_water", fields.cb_waving_water) - return true - end - if fields.cb_waving_leaves then - core.settings:set("enable_waving_leaves", fields.cb_waving_leaves) - return true - end - if fields.cb_waving_plants then - core.settings:set("enable_waving_plants", fields.cb_waving_plants) - return true - end - - if fields.dd_shadows then - local old_shadow_level_idx = get_shadow_mapping_idx() - 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 - - set_shadow_mapping_idx(shadow_level_idx) - - local shadow_presets = { - [2] = { 62, 512, "true", 0, "false" }, - [3] = { 93, 1024, "true", 0, "false" }, - [4] = { 140, 2048, "true", 1, "false" }, - [5] = { 210, 4096, "true", 2, "true" }, - [6] = { 300, 8192, "true", 2, "true" }, - } - local preset = shadow_presets[shadow_level_idx] - if preset then - core.settings:set("enable_dynamic_shadows", "true") - core.settings:set("shadow_map_max_distance", preset[1]) - core.settings:set("shadow_map_texture_size", preset[2]) - core.settings:set("shadow_map_texture_32bit", preset[3]) - core.settings:set("shadow_filters", preset[4]) - core.settings:set("shadow_map_color", preset[5]) - else - core.settings:set("enable_dynamic_shadows", "false") - end - return true - end - end, -} diff --git a/builtin/mainmenu/settings/shadows_component.lua b/builtin/mainmenu/settings/shadows_component.lua new file mode 100644 index 000000000..93c071bf7 --- /dev/null +++ b/builtin/mainmenu/settings/shadows_component.lua @@ -0,0 +1,121 @@ +--Minetest +--Copyright (C) 2021-2 x2048 +--Copyright (C) 2022-3 rubenwardy +-- +--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 +--the Free Software Foundation; either version 2.1 of the License, or +--(at your option) any later version. +-- +--This program is distributed in the hope that it will be useful, +--but WITHOUT ANY WARRANTY; without even the implied warranty of +--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +--GNU Lesser General Public License for more details. +-- +--You should have received a copy of the GNU Lesser General Public License along +--with this program; if not, write to the Free Software Foundation, Inc., +--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +local shadow_levels_labels = { + fgettext("Disabled"), + fgettext("Very Low"), + fgettext("Low"), + fgettext("Medium"), + fgettext("High"), + fgettext("Very High"), + fgettext("Custom"), +} +local PRESET_DISABLED = 1 +local PRESET_CUSTOM = #shadow_levels_labels + + +-- max distance, texture size, texture_32bit, filters, map color +local shadow_presets = { + [2] = { 62, 512, true, 0, false }, + [3] = { 93, 1024, true, 0, false }, + [4] = { 140, 2048, true, 1, false }, + [5] = { 210, 4096, true, 2, true }, + [6] = { 300, 8192, true, 2, true }, +} + + +local function detect_mapping_idx() + if not core.settings:get_bool("enable_dynamic_shadows", false) then + return PRESET_DISABLED + end + + local shadow_map_max_distance = tonumber(core.settings:get("shadow_map_max_distance")) + local shadow_map_texture_size = tonumber(core.settings:get("shadow_map_texture_size")) + local shadow_map_texture_32bit = core.settings:get_bool("shadow_map_texture_32bit", false) + local shadow_filters = tonumber(core.settings:get("shadow_filters")) + local shadow_map_color = core.settings:get_bool("shadow_map_color", false) + + for i = 2, 6 do + local preset = shadow_presets[i] + if preset[1] == shadow_map_max_distance and + preset[2] == shadow_map_texture_size and + preset[3] == shadow_map_texture_32bit and + preset[4] == shadow_filters and + preset[5] == shadow_map_color then + return i + end + end + return PRESET_CUSTOM +end + + +local function apply_preset(preset) + if preset then + core.settings:set_bool("enable_dynamic_shadows", true) + core.settings:set("shadow_map_max_distance", preset[1]) + core.settings:set("shadow_map_texture_size", preset[2]) + core.settings:set_bool("shadow_map_texture_32bit", preset[3]) + core.settings:set("shadow_filters", preset[4]) + core.settings:set_bool("shadow_map_color", preset[5]) + else + core.settings:set_bool("enable_dynamic_shadows", false) + end +end + + +return { + query_text = "Shadows", + requires = { + shaders = true, + opengl = true, + }, + get_formspec = function(self, avail_w) + local labels = table.copy(shadow_levels_labels) + local idx = detect_mapping_idx() + + -- Remove "custom" if not already selected + if idx ~= PRESET_CUSTOM then + table.remove(labels, PRESET_CUSTOM) + end + + local fs = + "label[0,0.2;" .. fgettext("Dynamic shadows") .. "]" .. + "dropdown[0,0.4;3,0.8;dd_shadows;" .. table.concat(labels, ",") .. ";" .. idx .. ";true]" .. + "label[0,1.5;" .. core.colorize("#bbb", fgettext("(The game will need to enable shadows as well)")) .. "]" + return fs, 1.8 + end, + on_submit = function(self, fields) + if fields.dd_shadows then + local old_shadow_level_idx = detect_mapping_idx() + 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 + + if shadow_level_idx == PRESET_CUSTOM then + core.settings:set_bool("enable_dynamic_shadows", true) + return true + end + + local preset = shadow_presets[shadow_level_idx] + apply_preset(preset) + return true + end + end, +} diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 573715a26..746e7ce2f 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -430,7 +430,7 @@ enable_dynamic_shadows (Dynamic shadows) bool false shadow_strength_gamma (Shadow strength gamma) float 1.0 0.1 10.0 # Maximum distance to render shadows. -shadow_map_max_distance (Shadow map max distance in nodes to render shadows) float 200.0 10.0 1000.0 +shadow_map_max_distance (Shadow map max distance in nodes to render shadows) float 140.0 10.0 1000.0 # Texture size to render the shadow map on. # This must be a power of two. diff --git a/minetest.conf.example b/minetest.conf.example index 02433473d..2592a09a3 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -433,7 +433,7 @@ # Maximum distance to render shadows. # type: float min: 10 max: 1000 -# shadow_map_max_distance = 200.0 +# shadow_map_max_distance = 140.0 # Texture size to render the shadow map on. # This must be a power of two. diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index a6bc987f2..8744de44d 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -274,7 +274,7 @@ void set_default_settings() // Effects Shadows settings->setDefault("enable_dynamic_shadows", "false"); settings->setDefault("shadow_strength_gamma", "1.0"); - settings->setDefault("shadow_map_max_distance", "200.0"); + settings->setDefault("shadow_map_max_distance", "140.0"); settings->setDefault("shadow_map_texture_size", "2048"); settings->setDefault("shadow_map_texture_32bit", "true"); settings->setDefault("shadow_map_color", "false");