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
132 {"No Filter,Bilinear Filter,Trilinear Filter"},
133 {"", "bilinear_filter", "trilinear_filter"},
137 {"No Mipmap,Mipmap,Mipmap + Aniso. Filter"},
138 {"", "mip_map", "anisotropic_filter"},
141 local function getFilterSettingIndex()
142 if (core.setting_get(filters[2][3]) == "true") then
145 if (core.setting_get(filters[2][3]) == "false" and core.setting_get(filters[2][2]) == "true") then
151 local function getMipmapSettingIndex()
152 if (core.setting_get(mipmap[2][3]) == "true") then
155 if (core.setting_get(mipmap[2][3]) == "false" and core.setting_get(mipmap[2][2]) == "true") then
162 "box[0,0;3.5,3.9;#999999]" ..
163 "checkbox[0.25,0;cb_smooth_lighting;".. fgettext("Smooth Lighting")
164 .. ";".. dump(core.setting_getbool("smooth_lighting")) .. "]"..
165 "checkbox[0.25,0.5;cb_particles;".. fgettext("Enable Particles") .. ";"
166 .. dump(core.setting_getbool("enable_particles")) .. "]"..
167 "checkbox[0.25,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
168 .. dump(core.setting_getbool("enable_3d_clouds")) .. "]"..
169 "checkbox[0.25,1.5;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
170 .. dump(core.setting_getbool("new_style_leaves")) .. "]"..
171 "checkbox[0.25,2.0;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
172 .. dump(core.setting_getbool("opaque_water")) .. "]"..
173 "checkbox[0.25,2.5;cb_connected_glass;".. fgettext("Connected Glass") .. ";"
174 .. dump(core.setting_getbool("connected_glass")) .. "]"..
175 "checkbox[0.25,3.0;cb_node_highlighting;".. fgettext("Node Highlighting") .. ";"
176 .. dump(core.setting_getbool("enable_node_highlighting")) .. "]"..
177 "box[3.75,0;3.75,3.45;#999999]" ..
178 "label[3.85,0.1;".. fgettext("Texturing:") .. "]"..
179 "dropdown[3.85,0.55;3.85;dd_filters;" .. filters[1][1] .. ";"
180 .. getFilterSettingIndex() .. "]" ..
181 "dropdown[3.85,1.35;3.85;dd_mipmap;" .. mipmap[1][1] .. ";"
182 .. getMipmapSettingIndex() .. "]" ..
183 "label[3.85,2.15;".. fgettext("Rendering:") .. "]"..
184 "dropdown[3.85,2.6;3.85;dd_video_driver;"
185 .. video_driver_string .. ";" .. current_video_driver_idx .. "]" ..
186 "tooltip[dd_video_driver;" ..
187 fgettext("Restart minetest for driver change to take effect") .. "]" ..
188 "box[7.75,0;4,4;#999999]" ..
189 "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
190 .. dump(core.setting_getbool("enable_shaders")) .. "]"
192 if PLATFORM ~= "Android" then
193 tab_string = tab_string ..
194 "button[8,4.75;3.75,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
196 tab_string = tab_string ..
197 "button[8,4.75;3.75,0.5;btn_reset_singleplayer;".. fgettext("Reset singleplayer world") .. "]"
199 tab_string = tab_string ..
200 "box[0,4.25;3.5,1.1;#999999]" ..
201 "label[0.25,4.25;" .. fgettext("GUI scale factor") .. "]" ..
202 "scrollbar[0.25,4.75;3,0.4;sb_gui_scaling;horizontal;" ..
203 gui_scale_to_scrollbar() .. "]" ..
204 "tooltip[sb_gui_scaling;" ..
205 fgettext("Scaling factor applied to menu elements: ") ..
206 dump(core.setting_get("gui_scaling")) .. "]"
208 if PLATFORM == "Android" then
209 tab_string = tab_string ..
210 "box[3.75,3.55;3.75,1.8;#999999]" ..
211 "checkbox[3.9,3.45;cb_touchscreen_target;".. fgettext("Touch free target") .. ";"
212 .. dump(core.setting_getbool("touchtarget")) .. "]"
215 if core.setting_get("touchscreen_threshold") ~= nil then
216 tab_string = tab_string ..
217 "label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" ..
218 "dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" ..
219 ((tonumber(core.setting_get("touchscreen_threshold"))/10)+1) .. "]"
222 if core.setting_getbool("enable_shaders") then
223 tab_string = tab_string ..
224 "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
225 .. dump(core.setting_getbool("enable_bumpmapping")) .. "]"..
226 "checkbox[8,1.0;cb_generate_normalmaps;".. fgettext("Generate Normalmaps") .. ";"
227 .. dump(core.setting_getbool("generate_normalmaps")) .. "]"..
228 "checkbox[8,1.5;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
229 .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]"..
230 "checkbox[8,2.0;cb_waving_water;".. fgettext("Waving Water") .. ";"
231 .. dump(core.setting_getbool("enable_waving_water")) .. "]"..
232 "checkbox[8,2.5;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
233 .. dump(core.setting_getbool("enable_waving_leaves")) .. "]"..
234 "checkbox[8,3.0;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
235 .. dump(core.setting_getbool("enable_waving_plants")) .. "]"
237 tab_string = tab_string ..
238 "textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
239 "textlist[8.33,1.2;4,1;;#888888" .. fgettext("Generate Normalmaps") .. ";0;true]" ..
240 "textlist[8.33,1.7;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
241 "textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
242 "textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
243 "textlist[8.33,3.2;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
248 --------------------------------------------------------------------------------
249 local function handle_settings_buttons(this, fields, tabname, tabdata)
250 if fields["cb_fancy_trees"] then
251 core.setting_set("new_style_leaves", fields["cb_fancy_trees"])
254 if fields["cb_smooth_lighting"] then
255 core.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
258 if fields["cb_3d_clouds"] then
259 core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
262 if fields["cb_opaque_water"] then
263 core.setting_set("opaque_water", fields["cb_opaque_water"])
266 if fields["cb_shaders"] then
267 if (core.setting_get("video_driver") == "direct3d8" or core.setting_get("video_driver") == "direct3d9") then
268 core.setting_set("enable_shaders", "false")
269 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
271 core.setting_set("enable_shaders", fields["cb_shaders"])
275 if fields["cb_connected_glass"] then
276 core.setting_set("connected_glass", fields["cb_connected_glass"])
279 if fields["cb_node_highlighting"] then
280 core.setting_set("enable_node_highlighting", fields["cb_node_highlighting"])
283 if fields["cb_particles"] then
284 core.setting_set("enable_particles", fields["cb_particles"])
287 if fields["cb_bumpmapping"] then
288 core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
290 if fields["cb_generate_normalmaps"] then
291 core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
293 if fields["cb_parallax"] then
294 core.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
297 if fields["cb_waving_water"] then
298 core.setting_set("enable_waving_water", fields["cb_waving_water"])
301 if fields["cb_waving_leaves"] then
302 core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
304 if fields["cb_waving_plants"] then
305 core.setting_set("enable_waving_plants", fields["cb_waving_plants"])
308 if fields["btn_change_keys"] ~= nil then
309 core.show_keys_menu()
313 if fields["sb_gui_scaling"] then
314 local event = core.explode_scrollbar_event(fields["sb_gui_scaling"])
316 if event.type == "CHG" then
317 local tosave = string.format("%.2f",scrollbar_to_gui_scale(event.value))
318 core.setting_set("gui_scaling",tosave)
322 if fields["cb_touchscreen_target"] then
323 core.setting_set("touchtarget", fields["cb_touchscreen_target"])
326 if fields["btn_reset_singleplayer"] then
327 showconfirm_reset(this)
331 --Note dropdowns have to be handled LAST!
332 local ddhandled = false
334 if fields["dd_touchthreshold"] then
335 core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"])
338 if fields["dd_video_driver"] then
339 local video_driver = string.gsub(fields["dd_video_driver"], " ", "")
340 core.setting_set("video_driver",string.lower(video_driver))
343 if fields["dd_filters"] == "No Filter" then
344 core.setting_set("bilinear_filter", "false")
345 core.setting_set("trilinear_filter", "false")
347 if fields["dd_filters"] == "Bilinear Filter" then
348 core.setting_set("bilinear_filter", "true")
349 core.setting_set("trilinear_filter", "false")
351 if fields["dd_filters"] == "Trilinear Filter" then
352 core.setting_set("bilinear_filter", "false")
353 core.setting_set("trilinear_filter", "true")
355 if fields["dd_mipmap"] == "No Mipmap" then
356 core.setting_set("mip_map", "false")
357 core.setting_set("anisotropic_filter", "false")
359 if fields["dd_mipmap"] == "Mipmap" then
360 core.setting_set("mip_map", "true")
361 core.setting_set("anisotropic_filter", "false")
363 if fields["dd_mipmap"] == "Mipmap + Aniso. Filter" then
364 core.setting_set("mip_map", "true")
365 core.setting_set("anisotropic_filter", "true")
373 caption = fgettext("Settings"),
374 cbf_formspec = formspec,
375 cbf_button_handler = handle_settings_buttons