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 leaves_style_labels = {
21 fgettext("Opaque Leaves"),
22 fgettext("Simple Leaves"),
23 fgettext("Fancy Leaves")
26 local leaves_style = {
27 {leaves_style_labels[1]..","..leaves_style_labels[2]..","..leaves_style_labels[3]},
28 {"opaque", "simple", "fancy"},
31 local dd_filter_labels = {
32 fgettext("No Filter"),
33 fgettext("Bilinear Filter"),
34 fgettext("Trilinear Filter")
38 {dd_filter_labels[1]..","..dd_filter_labels[2]..","..dd_filter_labels[3]},
39 {"", "bilinear_filter", "trilinear_filter"},
42 local dd_mipmap_labels = {
43 fgettext("No Mipmap"),
45 fgettext("Mipmap + Aniso. Filter")
49 {dd_mipmap_labels[1]..","..dd_mipmap_labels[2]..","..dd_mipmap_labels[3]},
50 {"", "mip_map", "anisotropic_filter"},
53 local function getLeavesStyleSettingIndex()
54 local style = core.setting_get("leaves_style")
55 if (style == leaves_style[2][3]) then
57 elseif (style == leaves_style[2][2]) then
63 local dd_antialiasing_labels = {
70 local antialiasing = {
71 {dd_antialiasing_labels[1]..","..dd_antialiasing_labels[2]..","..
72 dd_antialiasing_labels[3]..","..dd_antialiasing_labels[4]},
76 local function getFilterSettingIndex()
77 if (core.setting_get(filters[2][3]) == "true") then
80 if (core.setting_get(filters[2][3]) == "false" and core.setting_get(filters[2][2]) == "true") then
86 local function getMipmapSettingIndex()
87 if (core.setting_get(mipmap[2][3]) == "true") then
90 if (core.setting_get(mipmap[2][3]) == "false" and core.setting_get(mipmap[2][2]) == "true") then
96 local function getAntialiasingSettingIndex()
97 local antialiasing_setting = core.setting_get("fsaa")
98 for i=1, #(antialiasing[2]) do
99 if antialiasing_setting == antialiasing[2][i] then
106 local function antialiasing_fname_to_name(fname)
107 for i=1, #(dd_antialiasing_labels) do
108 if fname == dd_antialiasing_labels[i] then
109 return antialiasing[2][i]
116 local function dlg_confirm_reset_formspec(data)
119 "label[1,1;".. fgettext("Are you sure to reset your singleplayer world?") .. "]"..
120 "button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;"..
121 fgettext("Yes") .. "]" ..
122 "button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;"..
123 fgettext("No!!!") .. "]"
127 local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
129 if fields["dlg_reset_singleplayer_confirm"] ~= nil then
130 local worldlist = core.get_worlds()
131 local found_singleplayerworld = false
133 for i=1,#worldlist,1 do
134 if worldlist[i].name == "singleplayerworld" then
135 found_singleplayerworld = true
136 gamedata.worldindex = i
140 if found_singleplayerworld then
141 core.delete_world(gamedata.worldindex)
144 core.create_world("singleplayerworld", 1)
146 worldlist = core.get_worlds()
148 found_singleplayerworld = false
150 for i=1,#worldlist,1 do
151 if worldlist[i].name == "singleplayerworld" then
152 found_singleplayerworld = true
153 gamedata.worldindex = i
164 local function showconfirm_reset(tabview)
165 local new_dlg = dialog_create("reset_spworld",
166 dlg_confirm_reset_formspec,
167 dlg_confirm_reset_btnhandler,
169 new_dlg:set_parent(tabview)
174 local function gui_scale_to_scrollbar()
175 local current_value = tonumber(core.setting_get("gui_scaling"))
177 if (current_value == nil) or current_value < 0.25 then
180 if current_value <= 1.25 then
181 return ((current_value - 0.25)/ 1.0) * 700
183 if current_value <= 6 then
184 return ((current_value -1.25) * 100) + 700
190 local function scrollbar_to_gui_scale(value)
191 value = tonumber(value)
193 if (value <= 700) then
194 return ((value / 700) * 1.0) + 0.25
196 if (value <=1000) then
197 return ((value - 700) / 100) + 1.25
203 local function formspec(tabview, name, tabdata)
205 "box[0,0;3.5,4.0;#999999]" ..
206 "checkbox[0.25,0;cb_smooth_lighting;".. fgettext("Smooth Lighting")
207 .. ";".. dump(core.setting_getbool("smooth_lighting")) .. "]"..
208 "checkbox[0.25,0.5;cb_particles;".. fgettext("Enable Particles") .. ";"
209 .. dump(core.setting_getbool("enable_particles")) .. "]"..
210 "checkbox[0.25,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
211 .. dump(core.setting_getbool("enable_3d_clouds")) .. "]"..
212 "checkbox[0.25,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
213 .. dump(core.setting_getbool("opaque_water")) .. "]"..
214 "checkbox[0.25,2.0;cb_connected_glass;".. fgettext("Connected Glass") .. ";"
215 .. dump(core.setting_getbool("connected_glass")) .. "]"..
216 "checkbox[0.25,2.5;cb_node_highlighting;".. fgettext("Node Highlighting") .. ";"
217 .. dump(core.setting_getbool("enable_node_highlighting")) .. "]"..
218 "dropdown[0.25,3.2;3.3;dd_leaves_style;" .. leaves_style[1][1] .. ";"
219 .. getLeavesStyleSettingIndex() .. "]" ..
220 "box[3.75,0;3.75,3.45;#999999]" ..
221 "label[3.85,0.1;".. fgettext("Texturing:") .. "]"..
222 "dropdown[3.85,0.55;3.85;dd_filters;" .. filters[1][1] .. ";"
223 .. getFilterSettingIndex() .. "]" ..
224 "dropdown[3.85,1.35;3.85;dd_mipmap;" .. mipmap[1][1] .. ";"
225 .. getMipmapSettingIndex() .. "]" ..
226 "label[3.85,2.15;".. fgettext("Antialiasing:") .. "]"..
227 "dropdown[3.85,2.6;3.85;dd_antialiasing;" .. antialiasing[1][1] .. ";"
228 .. getAntialiasingSettingIndex() .. "]" ..
229 "box[7.75,0;4,4;#999999]" ..
230 "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
231 .. dump(core.setting_getbool("enable_shaders")) .. "]"
233 if PLATFORM ~= "Android" then
234 tab_string = tab_string ..
235 "button[8,4.75;3.75,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
237 tab_string = tab_string ..
238 "button[8,4.75;3.75,0.5;btn_reset_singleplayer;".. fgettext("Reset singleplayer world") .. "]"
240 tab_string = tab_string ..
241 "box[0,4.25;3.5,1.1;#999999]" ..
242 "label[0.25,4.25;" .. fgettext("GUI scale factor") .. "]" ..
243 "scrollbar[0.25,4.75;3,0.4;sb_gui_scaling;horizontal;" ..
244 gui_scale_to_scrollbar() .. "]" ..
245 "tooltip[sb_gui_scaling;" ..
246 fgettext("Scaling factor applied to menu elements: ") ..
247 dump(core.setting_get("gui_scaling")) .. "]"
249 if PLATFORM == "Android" then
250 tab_string = tab_string ..
251 "box[3.75,3.55;3.75,1.8;#999999]" ..
252 "checkbox[3.9,3.45;cb_touchscreen_target;".. fgettext("Touch free target") .. ";"
253 .. dump(core.setting_getbool("touchtarget")) .. "]"
256 if core.setting_get("touchscreen_threshold") ~= nil then
257 tab_string = tab_string ..
258 "label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" ..
259 "dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" ..
260 ((tonumber(core.setting_get("touchscreen_threshold"))/10)+1) .. "]"
263 if core.setting_getbool("enable_shaders") then
264 tab_string = tab_string ..
265 "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
266 .. dump(core.setting_getbool("enable_bumpmapping")) .. "]"..
267 "checkbox[8,1.0;cb_generate_normalmaps;".. fgettext("Generate Normalmaps") .. ";"
268 .. dump(core.setting_getbool("generate_normalmaps")) .. "]"..
269 "checkbox[8,1.5;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
270 .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]"..
271 "checkbox[8,2.0;cb_waving_water;".. fgettext("Waving Water") .. ";"
272 .. dump(core.setting_getbool("enable_waving_water")) .. "]"..
273 "checkbox[8,2.5;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
274 .. dump(core.setting_getbool("enable_waving_leaves")) .. "]"..
275 "checkbox[8,3.0;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
276 .. dump(core.setting_getbool("enable_waving_plants")) .. "]"
278 tab_string = tab_string ..
279 "textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
280 "textlist[8.33,1.2;4,1;;#888888" .. fgettext("Generate Normalmaps") .. ";0;true]" ..
281 "textlist[8.33,1.7;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
282 "textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
283 "textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
284 "textlist[8.33,3.2;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
289 --------------------------------------------------------------------------------
290 local function handle_settings_buttons(this, fields, tabname, tabdata)
291 if fields["cb_fancy_trees"] then
292 core.setting_set("new_style_leaves", fields["cb_fancy_trees"])
295 if fields["cb_smooth_lighting"] then
296 core.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
299 if fields["cb_3d_clouds"] then
300 core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
303 if fields["cb_opaque_water"] then
304 core.setting_set("opaque_water", fields["cb_opaque_water"])
307 if fields["cb_shaders"] then
308 if (core.setting_get("video_driver") == "direct3d8" or core.setting_get("video_driver") == "direct3d9") then
309 core.setting_set("enable_shaders", "false")
310 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
312 core.setting_set("enable_shaders", fields["cb_shaders"])
316 if fields["cb_connected_glass"] then
317 core.setting_set("connected_glass", fields["cb_connected_glass"])
320 if fields["cb_node_highlighting"] then
321 core.setting_set("enable_node_highlighting", fields["cb_node_highlighting"])
324 if fields["cb_particles"] then
325 core.setting_set("enable_particles", fields["cb_particles"])
328 if fields["cb_bumpmapping"] then
329 core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
331 if fields["cb_generate_normalmaps"] then
332 core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
334 if fields["cb_parallax"] then
335 core.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
338 if fields["cb_waving_water"] then
339 core.setting_set("enable_waving_water", fields["cb_waving_water"])
342 if fields["cb_waving_leaves"] then
343 core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
345 if fields["cb_waving_plants"] then
346 core.setting_set("enable_waving_plants", fields["cb_waving_plants"])
349 if fields["btn_change_keys"] ~= nil then
350 core.show_keys_menu()
354 if fields["sb_gui_scaling"] then
355 local event = core.explode_scrollbar_event(fields["sb_gui_scaling"])
357 if event.type == "CHG" then
358 local tosave = string.format("%.2f",scrollbar_to_gui_scale(event.value))
359 core.setting_set("gui_scaling",tosave)
363 if fields["cb_touchscreen_target"] then
364 core.setting_set("touchtarget", fields["cb_touchscreen_target"])
367 if fields["btn_reset_singleplayer"] then
368 showconfirm_reset(this)
372 --Note dropdowns have to be handled LAST!
373 local ddhandled = false
375 if fields["dd_touchthreshold"] then
376 core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"])
379 if fields["dd_leaves_style"] == leaves_style_labels[3] then
380 core.setting_set("leaves_style", leaves_style[2][3])
383 if fields["dd_leaves_style"] == leaves_style_labels[2] then
384 core.setting_set("leaves_style", leaves_style[2][2])
387 if fields["dd_leaves_style"] == leaves_style_labels[1] then
388 core.setting_set("leaves_style", leaves_style[2][1])
391 if fields["dd_filters"] == dd_filter_labels[1] then
392 core.setting_set("bilinear_filter", "false")
393 core.setting_set("trilinear_filter", "false")
396 if fields["dd_filters"] == dd_filter_labels[2] then
397 core.setting_set("bilinear_filter", "true")
398 core.setting_set("trilinear_filter", "false")
401 if fields["dd_filters"] == dd_filter_labels[3] then
402 core.setting_set("bilinear_filter", "false")
403 core.setting_set("trilinear_filter", "true")
406 if fields["dd_mipmap"] == dd_mipmap_labels[1] then
407 core.setting_set("mip_map", "false")
408 core.setting_set("anisotropic_filter", "false")
411 if fields["dd_mipmap"] == dd_mipmap_labels[2] then
412 core.setting_set("mip_map", "true")
413 core.setting_set("anisotropic_filter", "false")
416 if fields["dd_mipmap"] == dd_mipmap_labels[3] then
417 core.setting_set("mip_map", "true")
418 core.setting_set("anisotropic_filter", "true")
421 core.setting_set("fsaa",
422 antialiasing_fname_to_name(fields["dd_antialiasing"]))
429 caption = fgettext("Settings"),
430 cbf_formspec = formspec,
431 cbf_button_handler = handle_settings_buttons