2022-02-27 21:33:33 +01:00
|
|
|
--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.
|
|
|
|
|
2022-07-29 23:12:22 +12:00
|
|
|
local function create_confirm_reset_dlg()
|
|
|
|
return dialog_create("reset_all_settings",
|
|
|
|
function()
|
2022-11-13 17:44:48 +01:00
|
|
|
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]",
|
|
|
|
})
|
2022-07-29 23:12:22 +12:00
|
|
|
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
|
|
|
|
|
2022-02-27 21:33:33 +01:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-10-03 07:02:49 +13:00
|
|
|
local languages, language_dropdown, lang_idx = get_language_list()
|
2022-07-29 23:12:22 +12:00
|
|
|
|
2022-02-27 21:33:33 +01:00
|
|
|
local function formspec(tabview, name, tabdata)
|
|
|
|
local fps = tonumber(core.settings:get("fps_max"))
|
|
|
|
local range = tonumber(core.settings:get("viewing_range"))
|
2022-12-07 16:05:14 +02:00
|
|
|
local sensitivity = tonumber(core.settings:get("touch_sensitivity") or 0) * 2000
|
|
|
|
local touchtarget = core.settings:get_bool("touchtarget", false)
|
2022-04-09 20:51:22 +02:00
|
|
|
local fancy_leaves = core.settings:get("leaves_style") == "fancy"
|
2022-12-07 16:05:14 +02:00
|
|
|
local arm_inertia = core.settings:get_bool("arm_inertia", false)
|
2022-02-27 21:33:33 +01:00
|
|
|
local sound = tonumber(core.settings:get("sound_volume")) ~= 0 and true or false
|
|
|
|
|
|
|
|
local tab_string =
|
2022-12-07 16:05:14 +02:00
|
|
|
"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") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("smooth_lighting")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[0.15,0.45;cb_particles;" .. fgettext("Particles") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("enable_particles")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[0.15,1.05;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
--[["checkbox[0.15,1.65;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("opaque_water")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[0.15,1.95;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("connected_glass")) .. "]" ..]]
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[0.15,1.65;cb_fog;" .. fgettext("Fog") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("enable_fog")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[0.15,2.25;cb_inventory_items_animations;" .. fgettext("Inv. animations") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("inventory_items_animations")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[0.15,2.85;cb_fancy_leaves;" .. fgettext("Fancy Leaves") .. ";"
|
2022-04-09 20:51:22 +02:00
|
|
|
.. dump(fancy_leaves) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[0.15,3.45;cb_crosshair;" .. fgettext("Crosshair") .. ";"
|
|
|
|
.. dump(not touchtarget) .. "]" ..
|
|
|
|
"checkbox[0.15,4.05;cb_arm_inertia;" .. fgettext("Arm inertia") .. ";"
|
2022-11-13 17:44:48 +01:00
|
|
|
.. dump(arm_inertia) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[0.15,4.65;cb_sound;" .. fgettext("Sound") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(sound) .. "]" ..
|
2022-07-29 23:12:22 +12:00
|
|
|
|
2022-12-07 16:05:14 +02:00
|
|
|
"background9[4.1,0.05;3.75,5.5;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
|
2022-12-07 16:05:14 +02:00
|
|
|
"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) .. "]" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
|
|
|
|
"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;" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
(range <= 30 and 1 or range == 40 and 2 or range == 60 and 3 or
|
2022-02-27 21:33:33 +01:00
|
|
|
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) .. "]" ..
|
|
|
|
|
2022-12-07 16:05:14 +02:00
|
|
|
"label[4.25,2.9;" .. fgettext("Node highlighting") .. ":]" ..
|
|
|
|
"dropdown[4.25,3.35;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. getSettingIndex.NodeHighlighting() .. "]" ..
|
|
|
|
|
2022-12-07 16:05:14 +02:00
|
|
|
"label[4.25,4.3;" .. fgettext("Mouse sensitivity") .. ":]" ..
|
|
|
|
"scrollbar[4.25,4.75;3.23,0.5;horizontal;sb_sensitivity;" .. sensitivity .. "]" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
|
2022-12-07 16:05:14 +02:00
|
|
|
"background9[8.1,0.05;3.85,3.15;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]"
|
2022-02-27 21:33:33 +01:00
|
|
|
|
|
|
|
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 ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"label[8.25,0.1;" .. fgettext("Shaders") .. "]"
|
2022-02-27 21:33:33 +01:00
|
|
|
else
|
|
|
|
tab_string = tab_string ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"label[8.25,0.1;" .. core.colorize("#888888",
|
2022-02-27 21:33:33 +01:00
|
|
|
fgettext("Shaders (unavailable)")) .. "]"
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[tab_string = tab_string ..
|
2022-11-13 17:44:48 +01:00
|
|
|
btn_style("btn_change_keys") ..
|
2022-02-27 21:33:33 +01:00
|
|
|
"button[8,3.22;3.95,1;btn_change_keys;"
|
|
|
|
.. fgettext("Change Keys") .. "]"
|
|
|
|
|
|
|
|
tab_string = tab_string ..
|
2022-11-13 17:44:48 +01:00
|
|
|
btn_style("btn_advanced_settings") ..
|
2022-02-27 21:33:33 +01:00
|
|
|
"button[8,4.57;3.95,1;btn_advanced_settings;"
|
|
|
|
.. fgettext("All Settings") .. "]"]]
|
|
|
|
|
|
|
|
if shaders_enabled then
|
|
|
|
tab_string = tab_string ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[8.25,0.45;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("tone_mapping")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[8.25,1.05;cb_waving_water;" .. fgettext("Waving liquids") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("enable_waving_water")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[8.25,1.65;cb_waving_leaves;" .. fgettext("Waving leaves") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"checkbox[8.25,2.25;cb_waving_plants;" .. fgettext("Waving plants") .. ";"
|
2022-02-27 21:33:33 +01:00
|
|
|
.. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
|
|
|
|
else
|
|
|
|
tab_string = tab_string ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"label[8.38,0.65;" .. core.colorize("#888888",
|
2022-02-27 21:33:33 +01:00
|
|
|
fgettext("Tone Mapping")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"label[8.38,1.25;" .. core.colorize("#888888",
|
2022-02-27 21:33:33 +01:00
|
|
|
fgettext("Waving Liquids")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"label[8.38,1.85;" .. core.colorize("#888888",
|
2022-02-27 21:33:33 +01:00
|
|
|
fgettext("Waving Leaves")) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"label[8.38,2.45;" .. core.colorize("#888888",
|
2022-02-27 21:33:33 +01:00
|
|
|
fgettext("Waving Plants")) .. "]"
|
|
|
|
end
|
|
|
|
|
2022-07-29 23:12:22 +12:00
|
|
|
tab_string = tab_string ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"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 .. ";" ..
|
2022-07-29 23:12:22 +12:00
|
|
|
lang_idx .. ";true]" ..
|
2022-11-13 17:44:48 +01:00
|
|
|
btn_style("btn_reset") ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"button[8.25,4.6;3.5,0.8;btn_reset;" .. fgettext("Reset all settings") .. "]"
|
2022-07-29 23:12:22 +12:00
|
|
|
|
2022-02-27 21:33:33 +01:00
|
|
|
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
|
2022-12-07 16:05:14 +02:00
|
|
|
core.settings:set("leaves_style", (minetest.is_yes(fields["cb_fancy_leaves"]) and "fancy" or "opaque"))
|
2022-04-09 20:51:22 +02:00
|
|
|
return true
|
2022-02-27 21:33:33 +01:00
|
|
|
end
|
2022-12-07 16:05:14 +02:00
|
|
|
if fields["cb_crosshair"] then
|
|
|
|
core.settings:set_bool("touchtarget", not minetest.is_yes(fields["cb_crosshair"]))
|
2022-02-27 21:33:33 +01:00
|
|
|
return true
|
|
|
|
end
|
2022-11-13 17:44:48 +01:00
|
|
|
if fields["cb_arm_inertia"] then
|
|
|
|
core.settings:set("arm_inertia", fields["cb_arm_inertia"])
|
2022-07-29 23:12:22 +12:00
|
|
|
return true
|
|
|
|
end
|
2022-02-27 21:33:33 +01:00
|
|
|
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]]
|
|
|
|
|
2022-07-29 23:12:22 +12:00
|
|
|
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
|
|
|
|
|
2022-04-09 20:51:22 +02:00
|
|
|
-- Note dropdowns have to be handled LAST!
|
|
|
|
local ddhandled = false
|
|
|
|
|
2022-02-27 21:33:33 +01:00
|
|
|
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
|
2022-11-11 22:23:55 +01:00
|
|
|
core.settings:set("touch_sensitivity", event.value / 2000)
|
2022-02-27 21:33:33 +01:00
|
|
|
|
|
|
|
-- The formspec cannot be updated or the scrollbar movement will
|
|
|
|
-- break.
|
|
|
|
ddhandled = false
|
|
|
|
end
|
|
|
|
end
|
2022-07-29 23:12:22 +12:00
|
|
|
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
|
2022-02-27 21:33:33 +01:00
|
|
|
|
|
|
|
return ddhandled
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
name = "settings",
|
|
|
|
caption = "", -- fgettext("Settings"),
|
|
|
|
cbf_formspec = formspec,
|
|
|
|
cbf_button_handler = handle_settings_buttons
|
|
|
|
}
|