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")
59 table.concat(labels.leaves, ","),
60 {"opaque", "simple", "fancy"}
63 table.concat(labels.node_highlighting, ","),
64 {"box", "halo", "none"}
67 table.concat(labels.filters, ","),
68 {"", "bilinear_filter", "trilinear_filter"}
71 table.concat(labels.mipmap, ","),
72 {"", "mip_map", "anisotropic_filter"}
75 table.concat(labels.antialiasing, ","),
79 table.concat(labels.shadow_levels, ","),
80 { "0", "1", "2", "3", "4", "5" }
84 local getSettingIndex = {
86 local style = core.settings:get("leaves_style")
87 for idx, name in pairs(dd_options.leaves[2]) do
88 if style == name then return idx end
92 NodeHighlighting = function()
93 local style = core.settings:get("node_highlighting")
94 for idx, name in pairs(dd_options.node_highlighting[2]) do
95 if style == name then return idx end
100 if core.settings:get(dd_options.filters[2][3]) == "true" then
102 elseif core.settings:get(dd_options.filters[2][3]) == "false" and
103 core.settings:get(dd_options.filters[2][2]) == "true" then
109 if core.settings:get(dd_options.mipmap[2][3]) == "true" then
111 elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and
112 core.settings:get(dd_options.mipmap[2][2]) == "true" then
117 Antialiasing = function()
118 local antialiasing_setting = core.settings:get("fsaa")
119 for i = 1, #dd_options.antialiasing[2] do
120 if antialiasing_setting == dd_options.antialiasing[2][i] then
126 ShadowMapping = function()
127 local shadow_setting = core.settings:get("shadow_levels")
128 for i = 1, #dd_options.shadow_levels[2] do
129 if shadow_setting == dd_options.shadow_levels[2][i] then
137 local function antialiasing_fname_to_name(fname)
138 for i = 1, #labels.antialiasing do
139 if fname == labels.antialiasing[i] then
140 return dd_options.antialiasing[2][i]
146 local function formspec(tabview, name, tabdata)
148 "box[0,0;3.75,4.5;#999999]" ..
149 "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
150 .. dump(core.settings:get_bool("smooth_lighting")) .. "]" ..
151 "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";"
152 .. dump(core.settings:get_bool("enable_particles")) .. "]" ..
153 "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
154 .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" ..
155 "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
156 .. dump(core.settings:get_bool("opaque_water")) .. "]" ..
157 "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
158 .. dump(core.settings:get_bool("connected_glass")) .. "]" ..
159 "dropdown[0.25,2.8;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
160 .. getSettingIndex.NodeHighlighting() .. "]" ..
161 "dropdown[0.25,3.6;3.5;dd_leaves_style;" .. dd_options.leaves[1] .. ";"
162 .. getSettingIndex.Leaves() .. "]" ..
163 "box[4,0;3.75,4.9;#999999]" ..
164 "label[4.25,0.1;" .. fgettext("Texturing:") .. "]" ..
165 "dropdown[4.25,0.55;3.5;dd_filters;" .. dd_options.filters[1] .. ";"
166 .. getSettingIndex.Filter() .. "]" ..
167 "dropdown[4.25,1.35;3.5;dd_mipmap;" .. dd_options.mipmap[1] .. ";"
168 .. getSettingIndex.Mipmap() .. "]" ..
169 "label[4.25,2.15;" .. fgettext("Antialiasing:") .. "]" ..
170 "dropdown[4.25,2.6;3.5;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";"
171 .. getSettingIndex.Antialiasing() .. "]" ..
172 "box[8,0;3.75,4.5;#999999]"
174 local video_driver = core.settings:get("video_driver")
175 local shaders_enabled = core.settings:get_bool("enable_shaders")
176 if video_driver == "opengl" then
177 tab_string = tab_string ..
178 "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders") .. ";"
179 .. tostring(shaders_enabled) .. "]"
180 elseif video_driver == "ogles2" then
181 tab_string = tab_string ..
182 "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders (experimental)") .. ";"
183 .. tostring(shaders_enabled) .. "]"
185 core.settings:set_bool("enable_shaders", false)
186 shaders_enabled = false
187 tab_string = tab_string ..
188 "label[8.38,0.2;" .. core.colorize("#888888",
189 fgettext("Shaders (unavailable)")) .. "]"
192 tab_string = tab_string ..
193 "button[8,4.75;3.95,1;btn_change_keys;"
194 .. fgettext("Change Keys") .. "]"
196 tab_string = tab_string ..
197 "button[0,4.75;3.95,1;btn_advanced_settings;"
198 .. fgettext("All Settings") .. "]"
201 if core.settings:get("touchscreen_threshold") ~= nil then
202 tab_string = tab_string ..
203 "label[4.25,3.5;" .. fgettext("Touch threshold (px):") .. "]" ..
204 "dropdown[4.25,3.95;3.5;dd_touchthreshold;0,10,20,30,40,50;" ..
205 ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) ..
208 tab_string = tab_string ..
209 "label[4.25,3.65;" .. fgettext("Screen:") .. "]" ..
210 "checkbox[4.25,3.9;cb_autosave_screensize;" .. fgettext("Autosave Screen Size") .. ";"
211 .. dump(core.settings:get_bool("autosave_screensize")) .. "]"
214 if shaders_enabled then
215 tab_string = tab_string ..
216 "checkbox[8.25,0.5;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
217 .. dump(core.settings:get_bool("tone_mapping")) .. "]" ..
218 "checkbox[8.25,1;cb_waving_water;" .. fgettext("Waving Liquids") .. ";"
219 .. dump(core.settings:get_bool("enable_waving_water")) .. "]" ..
220 "checkbox[8.25,1.5;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
221 .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
222 "checkbox[8.25,2;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
223 .. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
225 if video_driver == "opengl" then
226 tab_string = tab_string ..
227 "label[8.25,2.8;" .. fgettext("Dynamic shadows:") .. "]" ..
228 "label[8.25,3.2;" .. fgettext("(game support required)") .. "]" ..
229 "dropdown[8.25,3.7;3.5;dd_shadows;" .. dd_options.shadow_levels[1] .. ";"
230 .. getSettingIndex.ShadowMapping() .. "]"
232 tab_string = tab_string ..
233 "label[8.38,2.7;" .. core.colorize("#888888",
234 fgettext("Dynamic shadows")) .. "]"
237 tab_string = tab_string ..
238 "label[8.38,0.7;" .. core.colorize("#888888",
239 fgettext("Tone Mapping")) .. "]" ..
240 "label[8.38,1.2;" .. core.colorize("#888888",
241 fgettext("Waving Liquids")) .. "]" ..
242 "label[8.38,1.7;" .. core.colorize("#888888",
243 fgettext("Waving Leaves")) .. "]" ..
244 "label[8.38,2.2;" .. core.colorize("#888888",
245 fgettext("Waving Plants")) .. "]"..
246 "label[8.38,2.7;" .. core.colorize("#888888",
247 fgettext("Dynamic shadows")) .. "]"
253 --------------------------------------------------------------------------------
254 local function handle_settings_buttons(this, fields, tabname, tabdata)
256 if fields["btn_advanced_settings"] ~= nil then
257 local adv_settings_dlg = create_adv_settings_dlg()
258 adv_settings_dlg:set_parent(this)
260 adv_settings_dlg:show()
261 --mm_game_theme.update("singleplayer", current_game())
264 if fields["cb_smooth_lighting"] then
265 core.settings:set("smooth_lighting", fields["cb_smooth_lighting"])
268 if fields["cb_particles"] then
269 core.settings:set("enable_particles", fields["cb_particles"])
272 if fields["cb_3d_clouds"] then
273 core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"])
276 if fields["cb_opaque_water"] then
277 core.settings:set("opaque_water", fields["cb_opaque_water"])
280 if fields["cb_connected_glass"] then
281 core.settings:set("connected_glass", fields["cb_connected_glass"])
284 if fields["cb_autosave_screensize"] then
285 core.settings:set("autosave_screensize", fields["cb_autosave_screensize"])
288 if fields["cb_shaders"] then
289 core.settings:set("enable_shaders", fields["cb_shaders"])
292 if fields["cb_tonemapping"] then
293 core.settings:set("tone_mapping", fields["cb_tonemapping"])
296 if fields["cb_waving_water"] then
297 core.settings:set("enable_waving_water", fields["cb_waving_water"])
300 if fields["cb_waving_leaves"] then
301 core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"])
303 if fields["cb_waving_plants"] then
304 core.settings:set("enable_waving_plants", fields["cb_waving_plants"])
307 if fields["btn_change_keys"] then
308 core.show_keys_menu()
312 --Note dropdowns have to be handled LAST!
313 local ddhandled = false
315 for i = 1, #labels.leaves do
316 if fields["dd_leaves_style"] == labels.leaves[i] then
317 core.settings:set("leaves_style", dd_options.leaves[2][i])
321 for i = 1, #labels.node_highlighting do
322 if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
323 core.settings:set("node_highlighting", dd_options.node_highlighting[2][i])
327 if fields["dd_filters"] == labels.filters[1] then
328 core.settings:set("bilinear_filter", "false")
329 core.settings:set("trilinear_filter", "false")
331 elseif fields["dd_filters"] == labels.filters[2] then
332 core.settings:set("bilinear_filter", "true")
333 core.settings:set("trilinear_filter", "false")
335 elseif fields["dd_filters"] == labels.filters[3] then
336 core.settings:set("bilinear_filter", "false")
337 core.settings:set("trilinear_filter", "true")
340 if fields["dd_mipmap"] == labels.mipmap[1] then
341 core.settings:set("mip_map", "false")
342 core.settings:set("anisotropic_filter", "false")
344 elseif fields["dd_mipmap"] == labels.mipmap[2] then
345 core.settings:set("mip_map", "true")
346 core.settings:set("anisotropic_filter", "false")
348 elseif fields["dd_mipmap"] == labels.mipmap[3] then
349 core.settings:set("mip_map", "true")
350 core.settings:set("anisotropic_filter", "true")
353 if fields["dd_antialiasing"] then
354 core.settings:set("fsaa",
355 antialiasing_fname_to_name(fields["dd_antialiasing"]))
358 if fields["dd_touchthreshold"] then
359 core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"])
363 for i = 1, #labels.shadow_levels do
364 if fields["dd_shadows"] == labels.shadow_levels[i] then
365 core.settings:set("shadow_levels", dd_options.shadow_levels[2][i])
370 if fields["dd_shadows"] == labels.shadow_levels[1] then
371 core.settings:set("enable_dynamic_shadows", "false")
373 local shadow_presets = {
374 [2] = { 62, 512, "true", 0, "false" },
375 [3] = { 93, 1024, "true", 0, "false" },
376 [4] = { 140, 2048, "true", 1, "false" },
377 [5] = { 210, 4096, "true", 2, "true" },
378 [6] = { 300, 8192, "true", 2, "true" },
380 local s = shadow_presets[table.indexof(labels.shadow_levels, fields["dd_shadows"])]
382 core.settings:set("enable_dynamic_shadows", "true")
383 core.settings:set("shadow_map_max_distance", s[1])
384 core.settings:set("shadow_map_texture_size", s[2])
385 core.settings:set("shadow_map_texture_32bit", s[3])
386 core.settings:set("shadow_filters", s[4])
387 core.settings:set("shadow_map_color", s[5])
396 caption = fgettext("Settings"),
397 cbf_formspec = formspec,
398 cbf_button_handler = handle_settings_buttons