2 --Copyright (C) 2013 sapier
4 --This program is free software; you can redistribute it and/or modify
5 --it under the terms of the GNU Lesser General Public License as published by
6 --the Free Software Foundation; either version 2.1 of the License, or
7 --(at your option) any later version.
9 --This program is distributed in the hope that it will be useful,
10 --but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 --GNU Lesser General Public License for more details.
14 --You should have received a copy of the GNU Lesser General Public License along
15 --with this program; if not, write to the Free Software Foundation, Inc.,
16 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 --------------------------------------------------------------------------------
20 local function dlg_confirm_reset_formspec(data)
23 "label[1,1;".. fgettext("Are you sure to reset your singleplayer world?") .. "]"..
24 "button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;"..
25 fgettext("Yes") .. "]" ..
26 "button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;"..
27 fgettext("No!!!") .. "]"
31 local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
33 if fields["dlg_reset_singleplayer_confirm"] ~= nil then
34 local worldlist = core.get_worlds()
35 local found_singleplayerworld = false
37 for i=1,#worldlist,1 do
38 if worldlist[i].name == "singleplayerworld" then
39 found_singleplayerworld = true
40 gamedata.worldindex = i
44 if found_singleplayerworld then
45 core.delete_world(gamedata.worldindex)
48 core.create_world("singleplayerworld", 1)
50 worldlist = core.get_worlds()
52 found_singleplayerworld = false
54 for i=1,#worldlist,1 do
55 if worldlist[i].name == "singleplayerworld" then
56 found_singleplayerworld = true
57 gamedata.worldindex = i
68 local function showconfirm_reset(tabview)
69 local new_dlg = dialog_create("reset_spworld",
70 dlg_confirm_reset_formspec,
71 dlg_confirm_reset_btnhandler,
73 new_dlg:set_parent(tabview)
78 local function gui_scale_to_scrollbar()
80 local current_value = tonumber(core.setting_get("gui_scaling"))
82 if (current_value == nil) or current_value < 0.25 then
86 if current_value <= 1.25 then
87 return ((current_value - 0.25)/ 1.0) * 700
90 if current_value <= 6 then
91 return ((current_value -1.25) * 100) + 700
97 local function scrollbar_to_gui_scale(value)
99 value = tonumber(value)
101 if (value <= 700) then
102 return ((value / 700) * 1.0) + 0.25
105 if (value <=1000) then
106 return ((value - 700) / 100) + 1.25
112 local function formspec(tabview, name, tabdata)
113 local video_drivers = core.get_video_drivers()
115 local video_driver_string = ""
116 local current_video_driver_idx = 0
117 local current_video_driver = core.setting_get("video_driver")
118 for i=1, #video_drivers, 1 do
121 video_driver_string = video_driver_string .. ","
123 video_driver_string = video_driver_string .. video_drivers[i]
125 local video_driver = string.gsub(video_drivers[i], " ", "")
126 if current_video_driver:lower() == video_driver:lower() then
127 current_video_driver_idx = i
133 "vertlabel[0,-0.25;" .. fgettext("SETTINGS") .. "]" ..
134 "box[0.75,0;3.25,4;#999999]" ..
135 "checkbox[1,0;cb_smooth_lighting;".. fgettext("Smooth Lighting")
136 .. ";".. dump(core.setting_getbool("smooth_lighting")) .. "]"..
137 "checkbox[1,0.5;cb_particles;".. fgettext("Enable Particles") .. ";"
138 .. dump(core.setting_getbool("enable_particles")) .. "]"..
139 "checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
140 .. dump(core.setting_getbool("enable_3d_clouds")) .. "]"..
141 "checkbox[1,1.5;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
142 .. dump(core.setting_getbool("new_style_leaves")) .. "]"..
143 "checkbox[1,2.0;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
144 .. dump(core.setting_getbool("opaque_water")) .. "]"..
145 "checkbox[1,2.5;cb_connected_glass;".. fgettext("Connected Glass") .. ";"
146 .. dump(core.setting_getbool("connected_glass")) .. "]"..
147 "dropdown[1,3.25;3;dd_video_driver;"
148 .. video_driver_string .. ";" .. current_video_driver_idx .. "]" ..
149 "tooltip[dd_video_driver;" ..
150 fgettext("Restart minetest for driver change to take effect") .. "]" ..
151 "box[4.25,0;3.25,2.5;#999999]" ..
152 "checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
153 .. dump(core.setting_getbool("mip_map")) .. "]"..
154 "checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
155 .. dump(core.setting_getbool("anisotropic_filter")) .. "]"..
156 "checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
157 .. dump(core.setting_getbool("bilinear_filter")) .. "]"..
158 "checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
159 .. dump(core.setting_getbool("trilinear_filter")) .. "]"..
160 "box[7.75,0;4,4;#999999]" ..
161 "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
162 .. dump(core.setting_getbool("enable_shaders")) .. "]"
163 if PLATFORM ~= "Android" then
164 tab_string = tab_string ..
165 "button[8,4.75;3.75,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
167 tab_string = tab_string ..
168 "button[8,4.75;3.75,0.5;btn_reset_singleplayer;".. fgettext("Reset singleplayer world") .. "]"
170 tab_string = tab_string ..
171 "box[0.75,4.25;3.25,1.25;#999999]" ..
172 "label[1,4.25;" .. fgettext("GUI scale factor") .. "]" ..
173 "scrollbar[1,4.75;2.75,0.4;sb_gui_scaling;horizontal;" ..
174 gui_scale_to_scrollbar() .. "]" ..
175 "tooltip[sb_gui_scaling;" ..
176 fgettext("Scaling factor applied to menu elements: ") ..
177 dump(core.setting_get("gui_scaling")) .. "]"
179 if PLATFORM == "Android" then
180 tab_string = tab_string ..
181 "box[4.25,2.75;3.25,2.15;#999999]" ..
182 "checkbox[4.5,2.75;cb_touchscreen_target;".. fgettext("Touch free target") .. ";"
183 .. dump(core.setting_getbool("touchtarget")) .. "]"
186 if core.setting_get("touchscreen_threshold") ~= nil then
187 tab_string = tab_string ..
188 "label[4.5,3.5;" .. fgettext("Touchthreshold (px)") .. "]" ..
189 "dropdown[4.5,4;3;dd_touchthreshold;0,10,20,30,40,50;" ..
190 ((tonumber(core.setting_get("touchscreen_threshold"))/10)+1) .. "]"
193 if core.setting_getbool("enable_shaders") then
194 tab_string = tab_string ..
195 "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
196 .. dump(core.setting_getbool("enable_bumpmapping")) .. "]"..
197 "checkbox[8,1.0;cb_generate_normalmaps;".. fgettext("Generate Normalmaps") .. ";"
198 .. dump(core.setting_getbool("generate_normalmaps")) .. "]"..
199 "checkbox[8,1.5;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
200 .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]"..
201 "checkbox[8,2.0;cb_waving_water;".. fgettext("Waving Water") .. ";"
202 .. dump(core.setting_getbool("enable_waving_water")) .. "]"..
203 "checkbox[8,2.5;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
204 .. dump(core.setting_getbool("enable_waving_leaves")) .. "]"..
205 "checkbox[8,3.0;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
206 .. dump(core.setting_getbool("enable_waving_plants")) .. "]"
208 tab_string = tab_string ..
209 "textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
210 "textlist[8.33,1.2;4,1;;#888888" .. fgettext("Generate Normalmaps") .. ";0;true]" ..
211 "textlist[8.33,1.7;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
212 "textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
213 "textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
214 "textlist[8.33,3.2;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
219 --------------------------------------------------------------------------------
220 local function handle_settings_buttons(this, fields, tabname, tabdata)
221 if fields["cb_fancy_trees"] then
222 core.setting_set("new_style_leaves", fields["cb_fancy_trees"])
225 if fields["cb_smooth_lighting"] then
226 core.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
229 if fields["cb_3d_clouds"] then
230 core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
233 if fields["cb_opaque_water"] then
234 core.setting_set("opaque_water", fields["cb_opaque_water"])
237 if fields["cb_mipmapping"] then
238 core.setting_set("mip_map", fields["cb_mipmapping"])
241 if fields["cb_anisotrophic"] then
242 core.setting_set("anisotropic_filter", fields["cb_anisotrophic"])
245 if fields["cb_bilinear"] then
246 core.setting_set("bilinear_filter", fields["cb_bilinear"])
249 if fields["cb_trilinear"] then
250 core.setting_set("trilinear_filter", fields["cb_trilinear"])
253 if fields["cb_shaders"] then
254 if (core.setting_get("video_driver") == "direct3d8" or core.setting_get("video_driver") == "direct3d9") then
255 core.setting_set("enable_shaders", "false")
256 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
258 core.setting_set("enable_shaders", fields["cb_shaders"])
262 if fields["cb_connected_glass"] then
263 core.setting_set("connected_glass", fields["cb_connected_glass"])
266 if fields["cb_particles"] then
267 core.setting_set("enable_particles", fields["cb_particles"])
270 if fields["cb_bumpmapping"] then
271 core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
273 if fields["cb_generate_normalmaps"] then
274 core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
276 if fields["cb_parallax"] then
277 core.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
280 if fields["cb_waving_water"] then
281 core.setting_set("enable_waving_water", fields["cb_waving_water"])
284 if fields["cb_waving_leaves"] then
285 core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
287 if fields["cb_waving_plants"] then
288 core.setting_set("enable_waving_plants", fields["cb_waving_plants"])
291 if fields["btn_change_keys"] ~= nil then
292 core.show_keys_menu()
296 if fields["sb_gui_scaling"] then
297 local event = core.explode_scrollbar_event(fields["sb_gui_scaling"])
299 if event.type == "CHG" then
300 local tosave = string.format("%.2f",scrollbar_to_gui_scale(event.value))
301 core.setting_set("gui_scaling",tosave)
305 if fields["cb_touchscreen_target"] then
306 core.setting_set("touchtarget", fields["cb_touchscreen_target"])
309 if fields["btn_reset_singleplayer"] then
310 showconfirm_reset(this)
314 --Note dropdowns have to be handled LAST!
315 local ddhandled = false
316 if fields["dd_touchthreshold"] then
317 core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"])
320 if fields["dd_video_driver"] then
321 local video_driver = string.gsub(fields["dd_video_driver"], " ", "")
322 core.setting_set("video_driver",string.lower(video_driver))
331 caption = fgettext("Settings"),
332 cbf_formspec = formspec,
333 cbf_button_handler = handle_settings_buttons