1
0
minetest-engine-multicraft2/builtin/mainmenu/tab_settings_simple.lua
Maksym H 13c4b3bd20
A new batch of MainMenu improvements (#110)
Co-authored-by: luk3yx <luk3yx@users.noreply.github.com>
2022-12-07 16:05:14 +02:00

335 lines
12 KiB
Lua

--Minetest
--Copyright (C) 2020-2022 MultiCraft Development Team
--Copyright (C) 2013 sapier
--
--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 3.0 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 function create_confirm_reset_dlg()
return dialog_create("reset_all_settings",
function()
return table.concat({
"real_coordinates[true]",
"image[6.5,0.8;2.5,2.5;", defaulttexturedir_esc, "attention.png]",
"style[msg;content_offset=0]",
"image_button[1,3.5;13.5,0.8;;msg;",
fgettext("Reset all settings?"), ";false;false]",
btn_style("reset_confirm", "red"),
"image_button[4.1,5.3;3.5,0.8;;reset_confirm;",
fgettext("Reset"), ";true;false]",
btn_style("reset_cancel"),
"image_button[7.9,5.3;3.5,0.8;;reset_cancel;",
fgettext("Cancel"), ";true;false]",
})
end,
function(this, fields)
if fields["reset_confirm"] then
for _, setting_name in ipairs(core.settings:get_names()) do
if not setting_name:find(".", 1, true) and
setting_name ~= "maintab_LAST" then
core.settings:remove(setting_name)
end
end
-- Reload the entire main menu
dofile(core.get_builtin_path() .. "init.lua")
return true
end
if fields["reset_cancel"] then
this:delete()
return true
end
end,
nil, true)
end
--------------------------------------------------------------------------------
local labels = {
node_highlighting = {
fgettext("Node Outlining"),
fgettext("Node Highlighting"),
fgettext("None")
}
}
local dd_options = {
node_highlighting = {
table.concat(labels.node_highlighting, ","),
{"box", "halo", "none"}
}
}
local getSettingIndex = {
NodeHighlighting = function()
local style = core.settings:get("node_highlighting")
for idx, name in pairs(dd_options.node_highlighting[2]) do
if style == name then return idx end
end
return 1
end
}
local languages, language_dropdown, lang_idx = get_language_list()
local function formspec(tabview, name, tabdata)
local fps = tonumber(core.settings:get("fps_max"))
local range = tonumber(core.settings:get("viewing_range"))
local sensitivity = tonumber(core.settings:get("touch_sensitivity") or 0) * 2000
local touchtarget = core.settings:get_bool("touchtarget", false)
local fancy_leaves = core.settings:get("leaves_style") == "fancy"
local arm_inertia = core.settings:get_bool("arm_inertia", false)
local sound = tonumber(core.settings:get("sound_volume")) ~= 0 and true or false
local tab_string =
"background9[0,0.05;3.85,5.5;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" ..
"checkbox[0.15,-0.1;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
.. dump(core.settings:get_bool("smooth_lighting")) .. "]" ..
"checkbox[0.15,0.45;cb_particles;" .. fgettext("Particles") .. ";"
.. dump(core.settings:get_bool("enable_particles")) .. "]" ..
"checkbox[0.15,1.05;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
.. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" ..
--[["checkbox[0.15,1.65;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
.. dump(core.settings:get_bool("opaque_water")) .. "]" ..
"checkbox[0.15,1.95;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
.. dump(core.settings:get_bool("connected_glass")) .. "]" ..]]
"checkbox[0.15,1.65;cb_fog;" .. fgettext("Fog") .. ";"
.. dump(core.settings:get_bool("enable_fog")) .. "]" ..
"checkbox[0.15,2.25;cb_inventory_items_animations;" .. fgettext("Inv. animations") .. ";"
.. dump(core.settings:get_bool("inventory_items_animations")) .. "]" ..
"checkbox[0.15,2.85;cb_fancy_leaves;" .. fgettext("Fancy Leaves") .. ";"
.. dump(fancy_leaves) .. "]" ..
"checkbox[0.15,3.45;cb_crosshair;" .. fgettext("Crosshair") .. ";"
.. dump(not touchtarget) .. "]" ..
"checkbox[0.15,4.05;cb_arm_inertia;" .. fgettext("Arm inertia") .. ";"
.. dump(arm_inertia) .. "]" ..
"checkbox[0.15,4.65;cb_sound;" .. fgettext("Sound") .. ";"
.. dump(sound) .. "]" ..
"background9[4.1,0.05;3.75,5.5;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" ..
"label[4.25,0.1;" .. fgettext("Maximum FPS") .. ":]" ..
"dropdown[4.25,0.55;3.5;dd_fps_max;30,35,45,60,90;" ..
(fps <= 30 and 1 or fps == 35 and 2 or fps == 45 and 3 or fps == 60 and 4 or 5) .. "]" ..
"label[4.25,1.5;" .. fgettext("Viewing range") .. ":]" ..
"dropdown[4.25,1.95;3.5;dd_viewing_range;30,40,60,80,100,125,150,175,200;" ..
(range <= 30 and 1 or range == 40 and 2 or range == 60 and 3 or
range == 80 and 4 or range == 100 and 5 or range == 125 and 6 or
range == 150 and 7 or range == 175 and 8 or 9) .. "]" ..
"label[4.25,2.9;" .. fgettext("Node highlighting") .. ":]" ..
"dropdown[4.25,3.35;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
.. getSettingIndex.NodeHighlighting() .. "]" ..
"label[4.25,4.3;" .. fgettext("Mouse sensitivity") .. ":]" ..
"scrollbar[4.25,4.75;3.23,0.5;horizontal;sb_sensitivity;" .. sensitivity .. "]" ..
"background9[8.1,0.05;3.85,3.15;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]"
local video_driver = core.settings:get("video_driver")
local shaders_enabled = video_driver == "opengl" or video_driver == "ogles2"
core.settings:set_bool("enable_shaders", shaders_enabled)
if shaders_enabled then
tab_string = tab_string ..
"label[8.25,0.1;" .. fgettext("Shaders") .. "]"
else
tab_string = tab_string ..
"label[8.25,0.1;" .. core.colorize("#888888",
fgettext("Shaders (unavailable)")) .. "]"
end
--[[tab_string = tab_string ..
btn_style("btn_change_keys") ..
"button[8,3.22;3.95,1;btn_change_keys;"
.. fgettext("Change Keys") .. "]"
tab_string = tab_string ..
btn_style("btn_advanced_settings") ..
"button[8,4.57;3.95,1;btn_advanced_settings;"
.. fgettext("All Settings") .. "]"]]
if shaders_enabled then
tab_string = tab_string ..
"checkbox[8.25,0.45;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
.. dump(core.settings:get_bool("tone_mapping")) .. "]" ..
"checkbox[8.25,1.05;cb_waving_water;" .. fgettext("Waving liquids") .. ";"
.. dump(core.settings:get_bool("enable_waving_water")) .. "]" ..
"checkbox[8.25,1.65;cb_waving_leaves;" .. fgettext("Waving leaves") .. ";"
.. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
"checkbox[8.25,2.25;cb_waving_plants;" .. fgettext("Waving plants") .. ";"
.. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
else
tab_string = tab_string ..
"label[8.38,0.65;" .. core.colorize("#888888",
fgettext("Tone Mapping")) .. "]" ..
"label[8.38,1.25;" .. core.colorize("#888888",
fgettext("Waving Liquids")) .. "]" ..
"label[8.38,1.85;" .. core.colorize("#888888",
fgettext("Waving Leaves")) .. "]" ..
"label[8.38,2.45;" .. core.colorize("#888888",
fgettext("Waving Plants")) .. "]"
end
tab_string = tab_string ..
"background9[8.1,3.35;3.85,2.2;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" ..
"label[8.25,3.3;" .. fgettext("Language") .. ":]" ..
"dropdown[8.25,3.75;3.58;dd_language;" .. language_dropdown .. ";" ..
lang_idx .. ";true]" ..
btn_style("btn_reset") ..
"button[8.25,4.6;3.5,0.8;btn_reset;" .. fgettext("Reset all settings") .. "]"
return tab_string
end
--------------------------------------------------------------------------------
local function handle_settings_buttons(this, fields, tabname, tabdata)
--[[if fields["btn_advanced_settings"] ~= nil then
local adv_settings_dlg = create_adv_settings_dlg()
adv_settings_dlg:set_parent(this)
this:hide()
adv_settings_dlg:show()
return true
end]]
if fields["cb_smooth_lighting"] then
core.settings:set("smooth_lighting", fields["cb_smooth_lighting"])
return true
end
if fields["cb_particles"] then
core.settings:set("enable_particles", fields["cb_particles"])
return true
end
if fields["cb_3d_clouds"] then
core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"])
return true
end
if fields["cb_opaque_water"] then
core.settings:set("opaque_water", fields["cb_opaque_water"])
return true
end
--[[if fields["cb_connected_glass"] then
core.settings:set("connected_glass", fields["cb_connected_glass"])
return true
end]]
if fields["cb_fog"] then
core.settings:set("enable_fog", fields["cb_fog"])
return true
end
if fields["cb_inventory_items_animations"] then
core.settings:set("inventory_items_animations", fields["cb_inventory_items_animations"])
return true
end
if fields["cb_fancy_leaves"] then
core.settings:set("leaves_style", (minetest.is_yes(fields["cb_fancy_leaves"]) and "fancy" or "opaque"))
return true
end
if fields["cb_crosshair"] then
core.settings:set_bool("touchtarget", not minetest.is_yes(fields["cb_crosshair"]))
return true
end
if fields["cb_arm_inertia"] then
core.settings:set("arm_inertia", fields["cb_arm_inertia"])
return true
end
if fields["cb_sound"] then
core.settings:set("sound_volume", (minetest.is_yes(fields["cb_sound"]) and "1.0") or "0.0")
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"])
end
if fields["cb_waving_plants"] then
core.settings:set("enable_waving_plants", fields["cb_waving_plants"])
return true
end
--[[if fields["btn_change_keys"] then
core.show_keys_menu()
return true
end]]
if fields["btn_reset"] then
local reset_dlg = create_confirm_reset_dlg()
reset_dlg:set_parent(this)
this:hide()
reset_dlg:show()
return true
end
-- Note dropdowns have to be handled LAST!
local ddhandled = false
if fields["cb_touchscreen_target"] then
core.settings:set("touchtarget", fields["cb_touchscreen_target"])
ddhandled = true
end
for i = 1, #labels.node_highlighting do
if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
core.settings:set("node_highlighting", dd_options.node_highlighting[2][i])
ddhandled = true
end
end
if fields["dd_fps_max"] then
core.settings:set("fps_max", fields["dd_fps_max"])
ddhandled = true
end
if fields["dd_viewing_range"] then
core.settings:set("viewing_range", fields["dd_viewing_range"])
ddhandled = true
end
if fields["sb_sensitivity"] then
-- reset old setting
core.settings:remove("touchscreen_threshold")
local event = core.explode_scrollbar_event(fields["sb_sensitivity"])
if event.type == "CHG" then
core.settings:set("touch_sensitivity", event.value / 2000)
-- The formspec cannot be updated or the scrollbar movement will
-- break.
ddhandled = false
end
end
if fields["dd_language"] then
local new_idx = tonumber(fields["dd_language"])
if lang_idx ~= new_idx then
core.settings:set("language", languages[new_idx] or "")
ddhandled = true
-- Reload the main menu so that everything uses the new language
dofile(core.get_builtin_path() .. "init.lua")
end
end
return ddhandled
end
return {
name = "settings",
caption = "", -- fgettext("Settings"),
cbf_formspec = formspec,
cbf_button_handler = handle_settings_buttons
}