]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/tab_settings.lua
Hide "Autosave Screen Size" on Android
[dragonfireclient.git] / builtin / mainmenu / tab_settings.lua
1 --Minetest
2 --Copyright (C) 2013 sapier
3 --
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.
8 --
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.
13 --
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.
17
18 --------------------------------------------------------------------------------
19
20 local labels = {
21         leaves = {
22                 fgettext("Opaque Leaves"),
23                 fgettext("Simple Leaves"),
24                 fgettext("Fancy Leaves")
25         },
26         node_highlighting = {
27                 fgettext("Node Outlining"),
28                 fgettext("Node Highlighting"),
29                 fgettext("None")
30         },
31         filters = {
32                 fgettext("No Filter"),
33                 fgettext("Bilinear Filter"),
34                 fgettext("Trilinear Filter")
35         },
36         mipmap = {
37                 fgettext("No Mipmap"),
38                 fgettext("Mipmap"),
39                 fgettext("Mipmap + Aniso. Filter")
40         },
41         antialiasing = {
42                 fgettext("None"),
43                 fgettext("2x"),
44                 fgettext("4x"),
45                 fgettext("8x")
46         },
47         shadow_levels = {
48                 fgettext("Disabled"),
49                 fgettext("Very Low"),
50                 fgettext("Low"),
51                 fgettext("Medium"),
52                 fgettext("High"),
53                 fgettext("Very High")
54         }
55 }
56
57 local dd_options = {
58         leaves = {
59                 table.concat(labels.leaves, ","),
60                 {"opaque", "simple", "fancy"}
61         },
62         node_highlighting = {
63                 table.concat(labels.node_highlighting, ","),
64                 {"box", "halo", "none"}
65         },
66         filters = {
67                 table.concat(labels.filters, ","),
68                 {"", "bilinear_filter", "trilinear_filter"}
69         },
70         mipmap = {
71                 table.concat(labels.mipmap, ","),
72                 {"", "mip_map", "anisotropic_filter"}
73         },
74         antialiasing = {
75                 table.concat(labels.antialiasing, ","),
76                 {"0", "2", "4", "8"}
77         },
78         shadow_levels = {
79                 table.concat(labels.shadow_levels, ","),
80                 { "0", "1", "2", "3", "4", "5" }
81         }
82 }
83
84 local getSettingIndex = {
85         Leaves = function()
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
89                 end
90                 return 1
91         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
96                 end
97                 return 1
98         end,
99         Filter = function()
100                 if core.settings:get(dd_options.filters[2][3]) == "true" then
101                         return 3
102                 elseif core.settings:get(dd_options.filters[2][3]) == "false" and
103                                 core.settings:get(dd_options.filters[2][2]) == "true" then
104                         return 2
105                 end
106                 return 1
107         end,
108         Mipmap = function()
109                 if core.settings:get(dd_options.mipmap[2][3]) == "true" then
110                         return 3
111                 elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and
112                                 core.settings:get(dd_options.mipmap[2][2]) == "true" then
113                         return 2
114                 end
115                 return 1
116         end,
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
121                                 return i
122                         end
123                 end
124                 return 1
125         end,
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
130                                 return i
131                         end
132                 end
133                 return 1
134         end
135 }
136
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]
141                 end
142         end
143         return 0
144 end
145
146 local function formspec(tabview, name, tabdata)
147         local tab_string =
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]"
173
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) .. "]"
184         else
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)")) .. "]"
190         end
191
192         tab_string = tab_string ..
193                 "button[8,4.75;3.95,1;btn_change_keys;"
194                 .. fgettext("Change Keys") .. "]"
195
196         tab_string = tab_string ..
197                 "button[0,4.75;3.95,1;btn_advanced_settings;"
198                 .. fgettext("All Settings") .. "]"
199
200
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) ..
206                         "]"
207         else
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")) .. "]"
212         end
213
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")) .. "]"..
224                         "label[8.25,2.8;" .. fgettext("Dynamic shadows:") .. "]" ..
225                         "label[8.25,3.2;" .. fgettext("(game support required)") .. "]" ..
226                                         "dropdown[8.25,3.7;3.5;dd_shadows;" .. dd_options.shadow_levels[1] .. ";"
227                                         .. getSettingIndex.ShadowMapping() .. "]"
228         else
229                 tab_string = tab_string ..
230                         "label[8.38,0.7;" .. core.colorize("#888888",
231                                         fgettext("Tone Mapping")) .. "]" ..
232                         "label[8.38,1.2;" .. core.colorize("#888888",
233                                         fgettext("Waving Liquids")) .. "]" ..
234                         "label[8.38,1.7;" .. core.colorize("#888888",
235                                         fgettext("Waving Leaves")) .. "]" ..
236                         "label[8.38,2.2;" .. core.colorize("#888888",
237                                         fgettext("Waving Plants")) .. "]"..
238                         "label[8.38,2.7;" .. core.colorize("#888888",
239                                         fgettext("Dynamic shadows")) .. "]"
240         end
241
242         return tab_string
243 end
244
245 --------------------------------------------------------------------------------
246 local function handle_settings_buttons(this, fields, tabname, tabdata)
247
248         if fields["btn_advanced_settings"] ~= nil then
249                 local adv_settings_dlg = create_adv_settings_dlg()
250                 adv_settings_dlg:set_parent(this)
251                 this:hide()
252                 adv_settings_dlg:show()
253                 --mm_game_theme.update("singleplayer", current_game())
254                 return true
255         end
256         if fields["cb_smooth_lighting"] then
257                 core.settings:set("smooth_lighting", fields["cb_smooth_lighting"])
258                 return true
259         end
260         if fields["cb_particles"] then
261                 core.settings:set("enable_particles", fields["cb_particles"])
262                 return true
263         end
264         if fields["cb_3d_clouds"] then
265                 core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"])
266                 return true
267         end
268         if fields["cb_opaque_water"] then
269                 core.settings:set("opaque_water", fields["cb_opaque_water"])
270                 return true
271         end
272         if fields["cb_connected_glass"] then
273                 core.settings:set("connected_glass", fields["cb_connected_glass"])
274                 return true
275         end
276         if fields["cb_autosave_screensize"] then
277                 core.settings:set("autosave_screensize", fields["cb_autosave_screensize"])
278                 return true
279         end
280         if fields["cb_shaders"] then
281                 core.settings:set("enable_shaders", fields["cb_shaders"])
282                 return true
283         end
284         if fields["cb_tonemapping"] then
285                 core.settings:set("tone_mapping", fields["cb_tonemapping"])
286                 return true
287         end
288         if fields["cb_waving_water"] then
289                 core.settings:set("enable_waving_water", fields["cb_waving_water"])
290                 return true
291         end
292         if fields["cb_waving_leaves"] then
293                 core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"])
294         end
295         if fields["cb_waving_plants"] then
296                 core.settings:set("enable_waving_plants", fields["cb_waving_plants"])
297                 return true
298         end
299         if fields["btn_change_keys"] then
300                 core.show_keys_menu()
301                 return true
302         end
303         if fields["cb_touchscreen_target"] then
304                 core.settings:set("touchtarget", fields["cb_touchscreen_target"])
305                 return true
306         end
307
308         --Note dropdowns have to be handled LAST!
309         local ddhandled = false
310
311         for i = 1, #labels.leaves do
312                 if fields["dd_leaves_style"] == labels.leaves[i] then
313                         core.settings:set("leaves_style", dd_options.leaves[2][i])
314                         ddhandled = true
315                 end
316         end
317         for i = 1, #labels.node_highlighting do
318                 if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
319                         core.settings:set("node_highlighting", dd_options.node_highlighting[2][i])
320                         ddhandled = true
321                 end
322         end
323         if fields["dd_filters"] == labels.filters[1] then
324                 core.settings:set("bilinear_filter", "false")
325                 core.settings:set("trilinear_filter", "false")
326                 ddhandled = true
327         elseif fields["dd_filters"] == labels.filters[2] then
328                 core.settings:set("bilinear_filter", "true")
329                 core.settings:set("trilinear_filter", "false")
330                 ddhandled = true
331         elseif fields["dd_filters"] == labels.filters[3] then
332                 core.settings:set("bilinear_filter", "false")
333                 core.settings:set("trilinear_filter", "true")
334                 ddhandled = true
335         end
336         if fields["dd_mipmap"] == labels.mipmap[1] then
337                 core.settings:set("mip_map", "false")
338                 core.settings:set("anisotropic_filter", "false")
339                 ddhandled = true
340         elseif fields["dd_mipmap"] == labels.mipmap[2] then
341                 core.settings:set("mip_map", "true")
342                 core.settings:set("anisotropic_filter", "false")
343                 ddhandled = true
344         elseif fields["dd_mipmap"] == labels.mipmap[3] then
345                 core.settings:set("mip_map", "true")
346                 core.settings:set("anisotropic_filter", "true")
347                 ddhandled = true
348         end
349         if fields["dd_antialiasing"] then
350                 core.settings:set("fsaa",
351                         antialiasing_fname_to_name(fields["dd_antialiasing"]))
352                 ddhandled = true
353         end
354         if fields["dd_touchthreshold"] then
355                 core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"])
356                 ddhandled = true
357         end
358
359         for i = 1, #labels.shadow_levels do
360                 if fields["dd_shadows"] == labels.shadow_levels[i] then
361                         core.settings:set("shadow_levels", dd_options.shadow_levels[2][i])
362                         ddhandled = true
363                 end
364         end
365
366         if fields["dd_shadows"] == labels.shadow_levels[1] then
367                 core.settings:set("enable_dynamic_shadows", "false")
368         else
369                 local shadow_presets = {
370                         [2] = { 62,  512,  "true", 0, "false" },
371                         [3] = { 93,  1024, "true", 0, "false" },
372                         [4] = { 140, 2048, "true", 1, "false" },
373                         [5] = { 210, 4096, "true", 2,  "true" },
374                         [6] = { 300, 8192, "true", 2,  "true" },
375                 }
376                 local s = shadow_presets[table.indexof(labels.shadow_levels, fields["dd_shadows"])]
377                 if s then
378                         core.settings:set("enable_dynamic_shadows", "true")
379                         core.settings:set("shadow_map_max_distance", s[1])
380                         core.settings:set("shadow_map_texture_size", s[2])
381                         core.settings:set("shadow_map_texture_32bit", s[3])
382                         core.settings:set("shadow_filters", s[4])
383                         core.settings:set("shadow_map_color", s[5])
384                 end
385         end
386
387         return ddhandled
388 end
389
390 return {
391         name = "settings",
392         caption = fgettext("Settings"),
393         cbf_formspec = formspec,
394         cbf_button_handler = handle_settings_buttons
395 }