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 -- Dropdown labels : Leaves
21 local leaves_style_labels = {
22 fgettext("Opaque Leaves"),
23 fgettext("Simple Leaves"),
24 fgettext("Fancy Leaves")
27 local leaves_style = {
28 table.concat(leaves_style_labels, ","),
29 {"opaque", "simple", "fancy"},
32 -- Dropdown labels : Node highlighting
33 local node_highlighting_style_labels = {
34 fgettext("Node Outlining"),
35 fgettext("Node Highlighting")
38 local node_highlighting_style = {
39 table.concat(node_highlighting_style_labels, ","),
43 -- Dropdown labels : Textures filtering
44 local dd_filter_labels = {
45 fgettext("No Filter"),
46 fgettext("Bilinear Filter"),
47 fgettext("Trilinear Filter")
51 table.concat(dd_filter_labels, ","),
52 {"", "bilinear_filter", "trilinear_filter"},
55 -- Dropdown labels : Mip-mapping
56 local dd_mipmap_labels = {
57 fgettext("No Mipmap"),
59 fgettext("Mipmap + Aniso. Filter")
63 table.concat(dd_mipmap_labels, ","),
64 {"", "mip_map", "anisotropic_filter"},
67 -- Dropdown labels : Anti-aliasing
68 local dd_antialiasing_labels = {
75 local antialiasing = {
76 table.concat(dd_antialiasing_labels, ","),
80 -- Dropdown index getter : Leaves
81 local function getLeavesStyleSettingIndex()
82 local style = core.setting_get("leaves_style")
83 for idx, name in pairs(leaves_style[2]) do
84 if style == name then return idx end
89 -- Dropdown index getter : Node highlighting
90 local function getNodeHighlightingSettingIndex()
91 local style = core.setting_get("node_highlighting")
92 for idx, name in pairs(node_highlighting_style[2]) do
93 if style == name then return idx end
98 -- Dropdown index getter : Textures filtering
99 local function getFilterSettingIndex()
100 if core.setting_get(filters[2][3]) == "true" then
102 elseif core.setting_get(filters[2][3]) == "false" and
103 core.setting_get(filters[2][2]) == "true" then
109 -- Dropdown index getter : Mip-mapping
110 local function getMipmapSettingIndex()
111 if core.setting_get(mipmap[2][3]) == "true" then
113 elseif core.setting_get(mipmap[2][3]) == "false" and
114 core.setting_get(mipmap[2][2]) == "true" then
120 -- Dropdown index getter : Anti-aliasing
121 local function getAntialiasingSettingIndex()
122 local antialiasing_setting = core.setting_get("fsaa")
123 for i = 1, #antialiasing[2] do
124 if antialiasing_setting == antialiasing[2][i] then
131 local function antialiasing_fname_to_name(fname)
132 for i = 1, #dd_antialiasing_labels do
133 if fname == dd_antialiasing_labels[i] then
134 return antialiasing[2][i]
140 local function dlg_confirm_reset_formspec(data)
141 return "size[8,3]" ..
142 "label[1,1;" .. fgettext("Are you sure to reset your singleplayer world?") .. "]" ..
143 "button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;" .. fgettext("Yes") .. "]" ..
144 "button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;" .. fgettext("No") .. "]"
147 local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
149 if fields["dlg_reset_singleplayer_confirm"] ~= nil then
150 local worldlist = core.get_worlds()
151 local found_singleplayerworld = false
153 for i = 1, #worldlist do
154 if worldlist[i].name == "singleplayerworld" then
155 found_singleplayerworld = true
156 gamedata.worldindex = i
160 if found_singleplayerworld then
161 core.delete_world(gamedata.worldindex)
164 core.create_world("singleplayerworld", 1)
165 worldlist = core.get_worlds()
166 found_singleplayerworld = false
168 for i = 1, #worldlist do
169 if worldlist[i].name == "singleplayerworld" then
170 found_singleplayerworld = true
171 gamedata.worldindex = i
182 local function showconfirm_reset(tabview)
183 local new_dlg = dialog_create("reset_spworld",
184 dlg_confirm_reset_formspec,
185 dlg_confirm_reset_btnhandler,
187 new_dlg:set_parent(tabview)
192 local function formspec(tabview, name, tabdata)
194 "box[0,0;3.5,4.5;#999999]" ..
195 "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
196 .. dump(core.setting_getbool("smooth_lighting")) .. "]" ..
197 "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";"
198 .. dump(core.setting_getbool("enable_particles")) .. "]" ..
199 "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
200 .. dump(core.setting_getbool("enable_3d_clouds")) .. "]" ..
201 "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
202 .. dump(core.setting_getbool("opaque_water")) .. "]" ..
203 "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
204 .. dump(core.setting_getbool("connected_glass")) .. "]" ..
205 "dropdown[0.25,2.8;3.3;dd_node_highlighting;" .. node_highlighting_style[1] .. ";"
206 .. getNodeHighlightingSettingIndex() .. "]" ..
207 "dropdown[0.25,3.6;3.3;dd_leaves_style;" .. leaves_style[1] .. ";"
208 .. getLeavesStyleSettingIndex() .. "]" ..
209 "box[3.75,0;3.75,3.45;#999999]" ..
210 "label[3.85,0.1;" .. fgettext("Texturing:") .. "]" ..
211 "dropdown[3.85,0.55;3.85;dd_filters;" .. filters[1] .. ";"
212 .. getFilterSettingIndex() .. "]" ..
213 "dropdown[3.85,1.35;3.85;dd_mipmap;" .. mipmap[1] .. ";"
214 .. getMipmapSettingIndex() .. "]" ..
215 "label[3.85,2.15;" .. fgettext("Antialiasing:") .. "]" ..
216 "dropdown[3.85,2.6;3.85;dd_antialiasing;" .. antialiasing[1] .. ";"
217 .. getAntialiasingSettingIndex() .. "]" ..
218 "box[7.75,0;4,4.4;#999999]" ..
219 "checkbox[8,0;cb_shaders;" .. fgettext("Shaders") .. ";"
220 .. dump(core.setting_getbool("enable_shaders")) .. "]"
222 tab_string = tab_string ..
223 "button[8,4.75;3.75,0.5;btn_change_keys;" .. fgettext("Change keys") .. "]" ..
224 "button[0,4.75;3.75,0.5;btn_advanced_settings;" .. fgettext("Advanced Settings") .. "]"
227 if core.setting_get("touchscreen_threshold") ~= nil then
228 tab_string = tab_string ..
229 "label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" ..
230 "dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" ..
231 ((tonumber(core.setting_get("touchscreen_threshold")) / 10) + 1) .. "]"
234 if core.setting_getbool("enable_shaders") then
235 tab_string = tab_string ..
236 "checkbox[8,0.5;cb_bumpmapping;" .. fgettext("Bump Mapping") .. ";"
237 .. dump(core.setting_getbool("enable_bumpmapping")) .. "]" ..
238 "checkbox[8,1;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
239 .. dump(core.setting_getbool("tone_mapping")) .. "]" ..
240 "checkbox[8,1.5;cb_generate_normalmaps;" .. fgettext("Normal Mapping") .. ";"
241 .. dump(core.setting_getbool("generate_normalmaps")) .. "]" ..
242 "checkbox[8,2;cb_parallax;" .. fgettext("Parallax Occlusion") .. ";"
243 .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]" ..
244 "checkbox[8,2.5;cb_waving_water;" .. fgettext("Waving Water") .. ";"
245 .. dump(core.setting_getbool("enable_waving_water")) .. "]" ..
246 "checkbox[8,3;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
247 .. dump(core.setting_getbool("enable_waving_leaves")) .. "]" ..
248 "checkbox[8,3.5;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
249 .. dump(core.setting_getbool("enable_waving_plants")) .. "]"
251 tab_string = tab_string ..
252 "tablecolumns[color;text]" ..
253 "tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
254 "table[8.33,0.7;3.5,4;shaders;" ..
255 "#888888," .. fgettext("Bump Mapping") .. "," ..
256 "#888888," .. fgettext("Tone Mapping") .. "," ..
257 "#888888," .. fgettext("Normal Mapping") .. "," ..
258 "#888888," .. fgettext("Parallax Occlusion") .. "," ..
259 "#888888," .. fgettext("Waving Water") .. "," ..
260 "#888888," .. fgettext("Waving Leaves") .. "," ..
261 "#888888," .. fgettext("Waving Plants") .. "," ..
268 --------------------------------------------------------------------------------
269 local function handle_settings_buttons(this, fields, tabname, tabdata)
271 if fields["btn_advanced_settings"] ~= nil then
272 local adv_settings_dlg = create_adv_settings_dlg()
273 adv_settings_dlg:set_parent(this)
275 adv_settings_dlg:show()
276 --mm_texture.update("singleplayer", current_game())
279 if fields["cb_smooth_lighting"] then
280 core.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
283 if fields["cb_particles"] then
284 core.setting_set("enable_particles", fields["cb_particles"])
287 if fields["cb_3d_clouds"] then
288 core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
291 if fields["cb_opaque_water"] then
292 core.setting_set("opaque_water", fields["cb_opaque_water"])
295 if fields["cb_connected_glass"] then
296 core.setting_set("connected_glass", fields["cb_connected_glass"])
299 if fields["cb_shaders"] then
300 if (core.setting_get("video_driver") == "direct3d8" or
301 core.setting_get("video_driver") == "direct3d9") then
302 core.setting_set("enable_shaders", "false")
303 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
305 core.setting_set("enable_shaders", fields["cb_shaders"])
309 if fields["cb_bumpmapping"] then
310 core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
313 if fields["cb_tonemapping"] then
314 core.setting_set("tone_mapping", fields["cb_tonemapping"])
317 if fields["cb_generate_normalmaps"] then
318 core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
321 if fields["cb_parallax"] then
322 core.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
325 if fields["cb_waving_water"] then
326 core.setting_set("enable_waving_water", fields["cb_waving_water"])
329 if fields["cb_waving_leaves"] then
330 core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
332 if fields["cb_waving_plants"] then
333 core.setting_set("enable_waving_plants", fields["cb_waving_plants"])
336 if fields["btn_change_keys"] then
337 core.show_keys_menu()
340 if fields["cb_touchscreen_target"] then
341 core.setting_set("touchtarget", fields["cb_touchscreen_target"])
344 if fields["btn_reset_singleplayer"] then
345 showconfirm_reset(this)
349 --Note dropdowns have to be handled LAST!
350 local ddhandled = false
352 for i = 1, #leaves_style_labels do
353 if fields["dd_leaves_style"] == leaves_style_labels[i] then
354 core.setting_set("leaves_style", leaves_style[2][i])
358 for i = 1, #node_highlighting_style_labels do
359 if fields["dd_node_highlighting"] == node_highlighting_style_labels[i] then
360 core.setting_set("node_highlighting", node_highlighting_style[2][i])
364 if fields["dd_filters"] == dd_filter_labels[1] then
365 core.setting_set("bilinear_filter", "false")
366 core.setting_set("trilinear_filter", "false")
368 elseif fields["dd_filters"] == dd_filter_labels[2] then
369 core.setting_set("bilinear_filter", "true")
370 core.setting_set("trilinear_filter", "false")
372 elseif fields["dd_filters"] == dd_filter_labels[3] then
373 core.setting_set("bilinear_filter", "false")
374 core.setting_set("trilinear_filter", "true")
377 if fields["dd_mipmap"] == dd_mipmap_labels[1] then
378 core.setting_set("mip_map", "false")
379 core.setting_set("anisotropic_filter", "false")
381 elseif fields["dd_mipmap"] == dd_mipmap_labels[2] then
382 core.setting_set("mip_map", "true")
383 core.setting_set("anisotropic_filter", "false")
385 elseif fields["dd_mipmap"] == dd_mipmap_labels[3] then
386 core.setting_set("mip_map", "true")
387 core.setting_set("anisotropic_filter", "true")
390 if fields["dd_antialiasing"] then
391 core.setting_set("fsaa",
392 antialiasing_fname_to_name(fields["dd_antialiasing"]))
395 if fields["dd_touchthreshold"] then
396 core.setting_set("touchscreen_threshold", fields["dd_touchthreshold"])
405 caption = fgettext("Settings"),
406 cbf_formspec = formspec,
407 cbf_button_handler = handle_settings_buttons