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 --------------------------------------------------------------------------------
22 fgettext("Opaque Leaves"),
23 fgettext("Simple Leaves"),
24 fgettext("Fancy Leaves")
27 fgettext("Node Outlining"),
28 fgettext("Node Highlighting")
31 fgettext("No Filter"),
32 fgettext("Bilinear Filter"),
33 fgettext("Trilinear Filter")
36 fgettext("No Mipmap"),
38 fgettext("Mipmap + Aniso. Filter")
50 table.concat(labels.leaves, ","),
51 {"opaque", "simple", "fancy"}
54 table.concat(labels.node_highlighting, ","),
58 table.concat(labels.filters, ","),
59 {"", "bilinear_filter", "trilinear_filter"}
62 table.concat(labels.mipmap, ","),
63 {"", "mip_map", "anisotropic_filter"}
66 table.concat(labels.antialiasing, ","),
71 local getSettingIndex = {
73 local style = core.setting_get("leaves_style")
74 for idx, name in pairs(dd_options.leaves[2]) do
75 if style == name then return idx end
79 NodeHighlighting = function()
80 local style = core.setting_get("node_highlighting")
81 for idx, name in pairs(dd_options.node_highlighting[2]) do
82 if style == name then return idx end
87 if core.setting_get(dd_options.filters[2][3]) == "true" then
89 elseif core.setting_get(dd_options.filters[2][3]) == "false" and
90 core.setting_get(dd_options.filters[2][2]) == "true" then
96 if core.setting_get(dd_options.mipmap[2][3]) == "true" then
98 elseif core.setting_get(dd_options.mipmap[2][3]) == "false" and
99 core.setting_get(dd_options.mipmap[2][2]) == "true" then
104 Antialiasing = function()
105 local antialiasing_setting = core.setting_get("fsaa")
106 for i = 1, #dd_options.antialiasing[2] do
107 if antialiasing_setting == dd_options.antialiasing[2][i] then
115 local function antialiasing_fname_to_name(fname)
116 for i = 1, #labels.antialiasing do
117 if fname == labels.antialiasing[i] then
118 return dd_options.antialiasing[2][i]
124 local function dlg_confirm_reset_formspec(data)
125 return "size[8,3]" ..
126 "label[1,1;" .. fgettext("Are you sure to reset your singleplayer world?") .. "]" ..
127 "button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;" .. fgettext("Yes") .. "]" ..
128 "button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;" .. fgettext("No") .. "]"
131 local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
133 if fields["dlg_reset_singleplayer_confirm"] ~= nil then
134 local worldlist = core.get_worlds()
135 local found_singleplayerworld = false
137 for i = 1, #worldlist do
138 if worldlist[i].name == "singleplayerworld" then
139 found_singleplayerworld = true
140 gamedata.worldindex = i
144 if found_singleplayerworld then
145 core.delete_world(gamedata.worldindex)
148 core.create_world("singleplayerworld", 1)
149 worldlist = core.get_worlds()
150 found_singleplayerworld = false
152 for i = 1, #worldlist do
153 if worldlist[i].name == "singleplayerworld" then
154 found_singleplayerworld = true
155 gamedata.worldindex = i
166 local function showconfirm_reset(tabview)
167 local new_dlg = dialog_create("reset_spworld",
168 dlg_confirm_reset_formspec,
169 dlg_confirm_reset_btnhandler,
171 new_dlg:set_parent(tabview)
176 local function formspec(tabview, name, tabdata)
178 "box[0,0;3.5,4.5;#999999]" ..
179 "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
180 .. dump(core.setting_getbool("smooth_lighting")) .. "]" ..
181 "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";"
182 .. dump(core.setting_getbool("enable_particles")) .. "]" ..
183 "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
184 .. dump(core.setting_getbool("enable_3d_clouds")) .. "]" ..
185 "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
186 .. dump(core.setting_getbool("opaque_water")) .. "]" ..
187 "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
188 .. dump(core.setting_getbool("connected_glass")) .. "]" ..
189 "dropdown[0.25,2.8;3.3;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
190 .. getSettingIndex.NodeHighlighting() .. "]" ..
191 "dropdown[0.25,3.6;3.3;dd_leaves_style;" .. dd_options.leaves[1] .. ";"
192 .. getSettingIndex.Leaves() .. "]" ..
193 "box[3.75,0;3.75,3.45;#999999]" ..
194 "label[3.85,0.1;" .. fgettext("Texturing:") .. "]" ..
195 "dropdown[3.85,0.55;3.85;dd_filters;" .. dd_options.filters[1] .. ";"
196 .. getSettingIndex.Filter() .. "]" ..
197 "dropdown[3.85,1.35;3.85;dd_mipmap;" .. dd_options.mipmap[1] .. ";"
198 .. getSettingIndex.Mipmap() .. "]" ..
199 "label[3.85,2.15;" .. fgettext("Antialiasing:") .. "]" ..
200 "dropdown[3.85,2.6;3.85;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";"
201 .. getSettingIndex.Antialiasing() .. "]" ..
202 "box[7.75,0;4,4.4;#999999]" ..
203 "checkbox[8,0;cb_shaders;" .. fgettext("Shaders") .. ";"
204 .. dump(core.setting_getbool("enable_shaders")) .. "]"
206 if PLATFORM == "Android" then
207 tab_string = tab_string ..
208 "button[8,4.75;3.75,0.5;btn_reset_singleplayer;"
209 .. fgettext("Reset singleplayer world") .. "]"
211 tab_string = tab_string ..
212 "button[8,4.75;3.75,0.5;btn_change_keys;"
213 .. fgettext("Change keys") .. "]"
216 tab_string = tab_string ..
217 "button[0,4.75;3.75,0.5;btn_advanced_settings;"
218 .. fgettext("Advanced Settings") .. "]"
221 if core.setting_get("touchscreen_threshold") ~= nil then
222 tab_string = tab_string ..
223 "label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" ..
224 "dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" ..
225 ((tonumber(core.setting_get("touchscreen_threshold")) / 10) + 1) .. "]"
228 if core.setting_getbool("enable_shaders") then
229 tab_string = tab_string ..
230 "checkbox[8,0.5;cb_bumpmapping;" .. fgettext("Bump Mapping") .. ";"
231 .. dump(core.setting_getbool("enable_bumpmapping")) .. "]" ..
232 "checkbox[8,1;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
233 .. dump(core.setting_getbool("tone_mapping")) .. "]" ..
234 "checkbox[8,1.5;cb_generate_normalmaps;" .. fgettext("Normal Mapping") .. ";"
235 .. dump(core.setting_getbool("generate_normalmaps")) .. "]" ..
236 "checkbox[8,2;cb_parallax;" .. fgettext("Parallax Occlusion") .. ";"
237 .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]" ..
238 "checkbox[8,2.5;cb_waving_water;" .. fgettext("Waving Water") .. ";"
239 .. dump(core.setting_getbool("enable_waving_water")) .. "]" ..
240 "checkbox[8,3;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
241 .. dump(core.setting_getbool("enable_waving_leaves")) .. "]" ..
242 "checkbox[8,3.5;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
243 .. dump(core.setting_getbool("enable_waving_plants")) .. "]"
245 tab_string = tab_string ..
246 "tablecolumns[color;text]" ..
247 "tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
248 "table[8.33,0.7;3.5,4;shaders;" ..
249 "#888888," .. fgettext("Bump Mapping") .. "," ..
250 "#888888," .. fgettext("Tone Mapping") .. "," ..
251 "#888888," .. fgettext("Normal Mapping") .. "," ..
252 "#888888," .. fgettext("Parallax Occlusion") .. "," ..
253 "#888888," .. fgettext("Waving Water") .. "," ..
254 "#888888," .. fgettext("Waving Leaves") .. "," ..
255 "#888888," .. fgettext("Waving Plants") .. "," ..
262 --------------------------------------------------------------------------------
263 local function handle_settings_buttons(this, fields, tabname, tabdata)
265 if fields["btn_advanced_settings"] ~= nil then
266 local adv_settings_dlg = create_adv_settings_dlg()
267 adv_settings_dlg:set_parent(this)
269 adv_settings_dlg:show()
270 --mm_texture.update("singleplayer", current_game())
273 if fields["cb_smooth_lighting"] then
274 core.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
277 if fields["cb_particles"] then
278 core.setting_set("enable_particles", fields["cb_particles"])
281 if fields["cb_3d_clouds"] then
282 core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
285 if fields["cb_opaque_water"] then
286 core.setting_set("opaque_water", fields["cb_opaque_water"])
289 if fields["cb_connected_glass"] then
290 core.setting_set("connected_glass", fields["cb_connected_glass"])
293 if fields["cb_shaders"] then
294 if (core.setting_get("video_driver") == "direct3d8" or
295 core.setting_get("video_driver") == "direct3d9") then
296 core.setting_set("enable_shaders", "false")
297 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
299 core.setting_set("enable_shaders", fields["cb_shaders"])
303 if fields["cb_bumpmapping"] then
304 core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
307 if fields["cb_tonemapping"] then
308 core.setting_set("tone_mapping", fields["cb_tonemapping"])
311 if fields["cb_generate_normalmaps"] then
312 core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
315 if fields["cb_parallax"] then
316 core.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
319 if fields["cb_waving_water"] then
320 core.setting_set("enable_waving_water", fields["cb_waving_water"])
323 if fields["cb_waving_leaves"] then
324 core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
326 if fields["cb_waving_plants"] then
327 core.setting_set("enable_waving_plants", fields["cb_waving_plants"])
330 if fields["btn_change_keys"] then
331 core.show_keys_menu()
334 if fields["cb_touchscreen_target"] then
335 core.setting_set("touchtarget", fields["cb_touchscreen_target"])
338 if fields["btn_reset_singleplayer"] then
339 showconfirm_reset(this)
343 --Note dropdowns have to be handled LAST!
344 local ddhandled = false
346 for i = 1, #labels.leaves do
347 if fields["dd_leaves_style"] == labels.leaves[i] then
348 core.setting_set("leaves_style", dd_options.leaves[2][i])
352 for i = 1, #labels.node_highlighting do
353 if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
354 core.setting_set("node_highlighting", dd_options.node_highlighting[2][i])
358 if fields["dd_filters"] == labels.filters[1] then
359 core.setting_set("bilinear_filter", "false")
360 core.setting_set("trilinear_filter", "false")
362 elseif fields["dd_filters"] == labels.filters[2] then
363 core.setting_set("bilinear_filter", "true")
364 core.setting_set("trilinear_filter", "false")
366 elseif fields["dd_filters"] == labels.filters[3] then
367 core.setting_set("bilinear_filter", "false")
368 core.setting_set("trilinear_filter", "true")
371 if fields["dd_mipmap"] == labels.mipmap[1] then
372 core.setting_set("mip_map", "false")
373 core.setting_set("anisotropic_filter", "false")
375 elseif fields["dd_mipmap"] == labels.mipmap[2] then
376 core.setting_set("mip_map", "true")
377 core.setting_set("anisotropic_filter", "false")
379 elseif fields["dd_mipmap"] == labels.mipmap[3] then
380 core.setting_set("mip_map", "true")
381 core.setting_set("anisotropic_filter", "true")
384 if fields["dd_antialiasing"] then
385 core.setting_set("fsaa",
386 antialiasing_fname_to_name(fields["dd_antialiasing"]))
389 if fields["dd_touchthreshold"] then
390 core.setting_set("touchscreen_threshold", fields["dd_touchthreshold"])
399 caption = fgettext("Settings"),
400 cbf_formspec = formspec,
401 cbf_button_handler = handle_settings_buttons