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"),
32 fgettext("No Filter"),
33 fgettext("Bilinear Filter"),
34 fgettext("Trilinear Filter")
37 fgettext("No Mipmap"),
39 fgettext("Mipmap + Aniso. Filter")
51 table.concat(labels.leaves, ","),
52 {"opaque", "simple", "fancy"}
55 table.concat(labels.node_highlighting, ","),
56 {"box", "halo", "none"}
59 table.concat(labels.filters, ","),
60 {"", "bilinear_filter", "trilinear_filter"}
63 table.concat(labels.mipmap, ","),
64 {"", "mip_map", "anisotropic_filter"}
67 table.concat(labels.antialiasing, ","),
72 local getSettingIndex = {
74 local style = core.settings:get("leaves_style")
75 for idx, name in pairs(dd_options.leaves[2]) do
76 if style == name then return idx end
80 NodeHighlighting = function()
81 local style = core.settings:get("node_highlighting")
82 for idx, name in pairs(dd_options.node_highlighting[2]) do
83 if style == name then return idx end
88 if core.settings:get(dd_options.filters[2][3]) == "true" then
90 elseif core.settings:get(dd_options.filters[2][3]) == "false" and
91 core.settings:get(dd_options.filters[2][2]) == "true" then
97 if core.settings:get(dd_options.mipmap[2][3]) == "true" then
99 elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and
100 core.settings:get(dd_options.mipmap[2][2]) == "true" then
105 Antialiasing = function()
106 local antialiasing_setting = core.settings:get("fsaa")
107 for i = 1, #dd_options.antialiasing[2] do
108 if antialiasing_setting == dd_options.antialiasing[2][i] then
116 local function antialiasing_fname_to_name(fname)
117 for i = 1, #labels.antialiasing do
118 if fname == labels.antialiasing[i] then
119 return dd_options.antialiasing[2][i]
125 local function dlg_confirm_reset_formspec(data)
126 return "size[8,3]" ..
127 "label[1,1;" .. fgettext("Are you sure to reset your singleplayer world?") .. "]" ..
128 "button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;" .. fgettext("Yes") .. "]" ..
129 "button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;" .. fgettext("No") .. "]"
132 local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
134 if fields["dlg_reset_singleplayer_confirm"] ~= nil then
135 local worldlist = core.get_worlds()
136 local found_singleplayerworld = false
138 for i = 1, #worldlist do
139 if worldlist[i].name == "singleplayerworld" then
140 found_singleplayerworld = true
141 gamedata.worldindex = i
145 if found_singleplayerworld then
146 core.delete_world(gamedata.worldindex)
149 core.create_world("singleplayerworld", 1)
150 worldlist = core.get_worlds()
152 for i = 1, #worldlist do
153 if worldlist[i].name == "singleplayerworld" then
154 gamedata.worldindex = i
165 local function showconfirm_reset(tabview)
166 local new_dlg = dialog_create("reset_spworld",
167 dlg_confirm_reset_formspec,
168 dlg_confirm_reset_btnhandler,
170 new_dlg:set_parent(tabview)
175 local function formspec(tabview, name, tabdata)
177 "box[0,0;3.75,4.5;#999999]" ..
178 "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
179 .. dump(core.settings:get_bool("smooth_lighting")) .. "]" ..
180 "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";"
181 .. dump(core.settings:get_bool("enable_particles")) .. "]" ..
182 "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
183 .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" ..
184 "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
185 .. dump(core.settings:get_bool("opaque_water")) .. "]" ..
186 "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
187 .. dump(core.settings:get_bool("connected_glass")) .. "]" ..
188 "dropdown[0.25,2.8;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
189 .. getSettingIndex.NodeHighlighting() .. "]" ..
190 "dropdown[0.25,3.6;3.5;dd_leaves_style;" .. dd_options.leaves[1] .. ";"
191 .. getSettingIndex.Leaves() .. "]" ..
192 "box[4,0;3.75,4.5;#999999]" ..
193 "label[4.25,0.1;" .. fgettext("Texturing:") .. "]" ..
194 "dropdown[4.25,0.55;3.5;dd_filters;" .. dd_options.filters[1] .. ";"
195 .. getSettingIndex.Filter() .. "]" ..
196 "dropdown[4.25,1.35;3.5;dd_mipmap;" .. dd_options.mipmap[1] .. ";"
197 .. getSettingIndex.Mipmap() .. "]" ..
198 "label[4.25,2.15;" .. fgettext("Antialiasing:") .. "]" ..
199 "dropdown[4.25,2.6;3.5;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";"
200 .. getSettingIndex.Antialiasing() .. "]" ..
201 "label[4.25,3.45;" .. fgettext("Screen:") .. "]" ..
202 "checkbox[4.25,3.6;cb_autosave_screensize;" .. fgettext("Autosave Screen Size") .. ";"
203 .. dump(core.settings:get_bool("autosave_screensize")) .. "]" ..
204 "box[8,0;3.75,4.5;#999999]"
206 local video_driver = core.settings:get("video_driver")
207 local shaders_supported = video_driver == "opengl"
208 local shaders_enabled = false
209 if shaders_supported then
210 shaders_enabled = core.settings:get_bool("enable_shaders")
211 tab_string = tab_string ..
212 "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders") .. ";"
213 .. tostring(shaders_enabled) .. "]"
215 core.settings:set_bool("enable_shaders", false)
216 tab_string = tab_string ..
217 "label[8.38,0.2;" .. core.colorize("#888888",
218 fgettext("Shaders (unavailable)")) .. "]"
221 if core.settings:get("main_menu_style") == "simple" then
222 -- 'Reset singleplayer world' only functions with simple menu
223 tab_string = tab_string ..
224 "button[8,4.75;3.95,1;btn_reset_singleplayer;"
225 .. fgettext("Reset singleplayer world") .. "]"
227 tab_string = tab_string ..
228 "button[8,4.75;3.95,1;btn_change_keys;"
229 .. fgettext("Change Keys") .. "]"
232 tab_string = tab_string ..
233 "button[0,4.75;3.95,1;btn_advanced_settings;"
234 .. fgettext("All Settings") .. "]"
237 if core.settings:get("touchscreen_threshold") ~= nil then
238 tab_string = tab_string ..
239 "label[4.3,4.2;" .. fgettext("Touchthreshold: (px)") .. "]" ..
240 "dropdown[4.25,4.65;3.5;dd_touchthreshold;0,10,20,30,40,50;" ..
241 ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) ..
242 "]box[4.0,4.5;3.75,1.0;#999999]"
245 if shaders_enabled then
246 tab_string = tab_string ..
247 "checkbox[8.25,0.5;cb_bumpmapping;" .. fgettext("Bump Mapping") .. ";"
248 .. dump(core.settings:get_bool("enable_bumpmapping")) .. "]" ..
249 "checkbox[8.25,1;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
250 .. dump(core.settings:get_bool("tone_mapping")) .. "]" ..
251 "checkbox[8.25,1.5;cb_generate_normalmaps;" .. fgettext("Generate Normal Maps") .. ";"
252 .. dump(core.settings:get_bool("generate_normalmaps")) .. "]" ..
253 "checkbox[8.25,2;cb_parallax;" .. fgettext("Parallax Occlusion") .. ";"
254 .. dump(core.settings:get_bool("enable_parallax_occlusion")) .. "]" ..
255 "checkbox[8.25,2.5;cb_waving_water;" .. fgettext("Waving Liquids") .. ";"
256 .. dump(core.settings:get_bool("enable_waving_water")) .. "]" ..
257 "checkbox[8.25,3;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
258 .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
259 "checkbox[8.25,3.5;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
260 .. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
262 tab_string = tab_string ..
263 "label[8.38,0.7;" .. core.colorize("#888888",
264 fgettext("Bump Mapping")) .. "]" ..
265 "label[8.38,1.2;" .. core.colorize("#888888",
266 fgettext("Tone Mapping")) .. "]" ..
267 "label[8.38,1.7;" .. core.colorize("#888888",
268 fgettext("Generate Normal Maps")) .. "]" ..
269 "label[8.38,2.2;" .. core.colorize("#888888",
270 fgettext("Parallax Occlusion")) .. "]" ..
271 "label[8.38,2.7;" .. core.colorize("#888888",
272 fgettext("Waving Liquids")) .. "]" ..
273 "label[8.38,3.2;" .. core.colorize("#888888",
274 fgettext("Waving Leaves")) .. "]" ..
275 "label[8.38,3.7;" .. core.colorize("#888888",
276 fgettext("Waving Plants")) .. "]"
282 --------------------------------------------------------------------------------
283 local function handle_settings_buttons(this, fields, tabname, tabdata)
285 if fields["btn_advanced_settings"] ~= nil then
286 local adv_settings_dlg = create_adv_settings_dlg()
287 adv_settings_dlg:set_parent(this)
289 adv_settings_dlg:show()
290 --mm_texture.update("singleplayer", current_game())
293 if fields["cb_smooth_lighting"] then
294 core.settings:set("smooth_lighting", fields["cb_smooth_lighting"])
297 if fields["cb_particles"] then
298 core.settings:set("enable_particles", fields["cb_particles"])
301 if fields["cb_3d_clouds"] then
302 core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"])
305 if fields["cb_opaque_water"] then
306 core.settings:set("opaque_water", fields["cb_opaque_water"])
309 if fields["cb_connected_glass"] then
310 core.settings:set("connected_glass", fields["cb_connected_glass"])
313 if fields["cb_autosave_screensize"] then
314 core.settings:set("autosave_screensize", fields["cb_autosave_screensize"])
317 if fields["cb_shaders"] then
318 if (core.settings:get("video_driver") == "direct3d8" or
319 core.settings:get("video_driver") == "direct3d9") then
320 core.settings:set("enable_shaders", "false")
321 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
323 core.settings:set("enable_shaders", fields["cb_shaders"])
327 if fields["cb_bumpmapping"] then
328 core.settings:set("enable_bumpmapping", fields["cb_bumpmapping"])
331 if fields["cb_tonemapping"] then
332 core.settings:set("tone_mapping", fields["cb_tonemapping"])
335 if fields["cb_generate_normalmaps"] then
336 core.settings:set("generate_normalmaps", fields["cb_generate_normalmaps"])
339 if fields["cb_parallax"] then
340 core.settings:set("enable_parallax_occlusion", fields["cb_parallax"])
343 if fields["cb_waving_water"] then
344 core.settings:set("enable_waving_water", fields["cb_waving_water"])
347 if fields["cb_waving_leaves"] then
348 core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"])
350 if fields["cb_waving_plants"] then
351 core.settings:set("enable_waving_plants", fields["cb_waving_plants"])
354 if fields["btn_change_keys"] then
355 core.show_keys_menu()
358 if fields["cb_touchscreen_target"] then
359 core.settings:set("touchtarget", fields["cb_touchscreen_target"])
362 if fields["btn_reset_singleplayer"] then
363 showconfirm_reset(this)
367 --Note dropdowns have to be handled LAST!
368 local ddhandled = false
370 for i = 1, #labels.leaves do
371 if fields["dd_leaves_style"] == labels.leaves[i] then
372 core.settings:set("leaves_style", dd_options.leaves[2][i])
376 for i = 1, #labels.node_highlighting do
377 if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
378 core.settings:set("node_highlighting", dd_options.node_highlighting[2][i])
382 if fields["dd_filters"] == labels.filters[1] then
383 core.settings:set("bilinear_filter", "false")
384 core.settings:set("trilinear_filter", "false")
386 elseif fields["dd_filters"] == labels.filters[2] then
387 core.settings:set("bilinear_filter", "true")
388 core.settings:set("trilinear_filter", "false")
390 elseif fields["dd_filters"] == labels.filters[3] then
391 core.settings:set("bilinear_filter", "false")
392 core.settings:set("trilinear_filter", "true")
395 if fields["dd_mipmap"] == labels.mipmap[1] then
396 core.settings:set("mip_map", "false")
397 core.settings:set("anisotropic_filter", "false")
399 elseif fields["dd_mipmap"] == labels.mipmap[2] then
400 core.settings:set("mip_map", "true")
401 core.settings:set("anisotropic_filter", "false")
403 elseif fields["dd_mipmap"] == labels.mipmap[3] then
404 core.settings:set("mip_map", "true")
405 core.settings:set("anisotropic_filter", "true")
408 if fields["dd_antialiasing"] then
409 core.settings:set("fsaa",
410 antialiasing_fname_to_name(fields["dd_antialiasing"]))
413 if fields["dd_touchthreshold"] then
414 core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"])
423 caption = fgettext("Settings"),
424 cbf_formspec = formspec,
425 cbf_button_handler = handle_settings_buttons