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,4.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 "label[3.85,3.45;" .. fgettext("Screen:") .. "]" ..
203 "checkbox[3.85,3.6;cb_autosave_screensize;" .. fgettext("Autosave screen size") .. ";"
204 .. dump(core.setting_getbool("autosave_screensize")) .. "]" ..
205 "box[7.75,0;4,4.4;#999999]" ..
206 "checkbox[8,0;cb_shaders;" .. fgettext("Shaders") .. ";"
207 .. dump(core.setting_getbool("enable_shaders")) .. "]"
209 if PLATFORM == "Android" then
210 tab_string = tab_string ..
211 "button[8,4.75;3.75,0.5;btn_reset_singleplayer;"
212 .. fgettext("Reset singleplayer world") .. "]"
214 tab_string = tab_string ..
215 "button[8,4.85;3.75,0.5;btn_change_keys;"
216 .. fgettext("Change keys") .. "]"
219 tab_string = tab_string ..
220 "button[0,4.85;3.75,0.5;btn_advanced_settings;"
221 .. fgettext("Advanced Settings") .. "]"
224 if core.setting_get("touchscreen_threshold") ~= nil then
225 tab_string = tab_string ..
226 "label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" ..
227 "dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" ..
228 ((tonumber(core.setting_get("touchscreen_threshold")) / 10) + 1) .. "]"
231 if core.setting_getbool("enable_shaders") then
232 tab_string = tab_string ..
233 "checkbox[8,0.5;cb_bumpmapping;" .. fgettext("Bump Mapping") .. ";"
234 .. dump(core.setting_getbool("enable_bumpmapping")) .. "]" ..
235 "checkbox[8,1;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
236 .. dump(core.setting_getbool("tone_mapping")) .. "]" ..
237 "checkbox[8,1.5;cb_generate_normalmaps;" .. fgettext("Normal Mapping") .. ";"
238 .. dump(core.setting_getbool("generate_normalmaps")) .. "]" ..
239 "checkbox[8,2;cb_parallax;" .. fgettext("Parallax Occlusion") .. ";"
240 .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]" ..
241 "checkbox[8,2.5;cb_waving_water;" .. fgettext("Waving Water") .. ";"
242 .. dump(core.setting_getbool("enable_waving_water")) .. "]" ..
243 "checkbox[8,3;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
244 .. dump(core.setting_getbool("enable_waving_leaves")) .. "]" ..
245 "checkbox[8,3.5;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
246 .. dump(core.setting_getbool("enable_waving_plants")) .. "]"
248 tab_string = tab_string ..
249 "tablecolumns[color;text]" ..
250 "tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
251 "table[8.33,0.7;3.5,4;shaders;" ..
252 "#888888," .. fgettext("Bump Mapping") .. "," ..
253 "#888888," .. fgettext("Tone Mapping") .. "," ..
254 "#888888," .. fgettext("Normal Mapping") .. "," ..
255 "#888888," .. fgettext("Parallax Occlusion") .. "," ..
256 "#888888," .. fgettext("Waving Water") .. "," ..
257 "#888888," .. fgettext("Waving Leaves") .. "," ..
258 "#888888," .. fgettext("Waving Plants") .. "," ..
265 --------------------------------------------------------------------------------
266 local function handle_settings_buttons(this, fields, tabname, tabdata)
268 if fields["btn_advanced_settings"] ~= nil then
269 local adv_settings_dlg = create_adv_settings_dlg()
270 adv_settings_dlg:set_parent(this)
272 adv_settings_dlg:show()
273 --mm_texture.update("singleplayer", current_game())
276 if fields["cb_smooth_lighting"] then
277 core.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
280 if fields["cb_particles"] then
281 core.setting_set("enable_particles", fields["cb_particles"])
284 if fields["cb_3d_clouds"] then
285 core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
288 if fields["cb_opaque_water"] then
289 core.setting_set("opaque_water", fields["cb_opaque_water"])
292 if fields["cb_connected_glass"] then
293 core.setting_set("connected_glass", fields["cb_connected_glass"])
296 if fields["cb_autosave_screensize"] then
297 core.setting_set("autosave_screensize", fields["cb_autosave_screensize"])
300 if fields["cb_shaders"] then
301 if (core.setting_get("video_driver") == "direct3d8" or
302 core.setting_get("video_driver") == "direct3d9") then
303 core.setting_set("enable_shaders", "false")
304 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
306 core.setting_set("enable_shaders", fields["cb_shaders"])
310 if fields["cb_bumpmapping"] then
311 core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
314 if fields["cb_tonemapping"] then
315 core.setting_set("tone_mapping", fields["cb_tonemapping"])
318 if fields["cb_generate_normalmaps"] then
319 core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
322 if fields["cb_parallax"] then
323 core.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
326 if fields["cb_waving_water"] then
327 core.setting_set("enable_waving_water", fields["cb_waving_water"])
330 if fields["cb_waving_leaves"] then
331 core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
333 if fields["cb_waving_plants"] then
334 core.setting_set("enable_waving_plants", fields["cb_waving_plants"])
337 if fields["btn_change_keys"] then
338 core.show_keys_menu()
341 if fields["cb_touchscreen_target"] then
342 core.setting_set("touchtarget", fields["cb_touchscreen_target"])
345 if fields["btn_reset_singleplayer"] then
346 showconfirm_reset(this)
350 --Note dropdowns have to be handled LAST!
351 local ddhandled = false
353 for i = 1, #labels.leaves do
354 if fields["dd_leaves_style"] == labels.leaves[i] then
355 core.setting_set("leaves_style", dd_options.leaves[2][i])
359 for i = 1, #labels.node_highlighting do
360 if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
361 core.setting_set("node_highlighting", dd_options.node_highlighting[2][i])
365 if fields["dd_filters"] == labels.filters[1] then
366 core.setting_set("bilinear_filter", "false")
367 core.setting_set("trilinear_filter", "false")
369 elseif fields["dd_filters"] == labels.filters[2] then
370 core.setting_set("bilinear_filter", "true")
371 core.setting_set("trilinear_filter", "false")
373 elseif fields["dd_filters"] == labels.filters[3] then
374 core.setting_set("bilinear_filter", "false")
375 core.setting_set("trilinear_filter", "true")
378 if fields["dd_mipmap"] == labels.mipmap[1] then
379 core.setting_set("mip_map", "false")
380 core.setting_set("anisotropic_filter", "false")
382 elseif fields["dd_mipmap"] == labels.mipmap[2] then
383 core.setting_set("mip_map", "true")
384 core.setting_set("anisotropic_filter", "false")
386 elseif fields["dd_mipmap"] == labels.mipmap[3] then
387 core.setting_set("mip_map", "true")
388 core.setting_set("anisotropic_filter", "true")
391 if fields["dd_antialiasing"] then
392 core.setting_set("fsaa",
393 antialiasing_fname_to_name(fields["dd_antialiasing"]))
396 if fields["dd_touchthreshold"] then
397 core.setting_set("touchscreen_threshold", fields["dd_touchthreshold"])
406 caption = fgettext("Settings"),
407 cbf_formspec = formspec,
408 cbf_button_handler = handle_settings_buttons