]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/tab_settings.lua
Add '@n' escape sequences and some documentation on translated strings.
[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 }
48
49 local dd_options = {
50         leaves = {
51                 table.concat(labels.leaves, ","),
52                 {"opaque", "simple", "fancy"}
53         },
54         node_highlighting = {
55                 table.concat(labels.node_highlighting, ","),
56                 {"box", "halo", "none"}
57         },
58         filters = {
59                 table.concat(labels.filters, ","),
60                 {"", "bilinear_filter", "trilinear_filter"}
61         },
62         mipmap = {
63                 table.concat(labels.mipmap, ","),
64                 {"", "mip_map", "anisotropic_filter"}
65         },
66         antialiasing = {
67                 table.concat(labels.antialiasing, ","),
68                 {"0", "2", "4", "8"}
69         }
70 }
71
72 local getSettingIndex = {
73         Leaves = function()
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
77                 end
78                 return 1
79         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
84                 end
85                 return 1
86         end,
87         Filter = function()
88                 if core.settings:get(dd_options.filters[2][3]) == "true" then
89                         return 3
90                 elseif core.settings:get(dd_options.filters[2][3]) == "false" and
91                                 core.settings:get(dd_options.filters[2][2]) == "true" then
92                         return 2
93                 end
94                 return 1
95         end,
96         Mipmap = function()
97                 if core.settings:get(dd_options.mipmap[2][3]) == "true" then
98                         return 3
99                 elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and
100                                 core.settings:get(dd_options.mipmap[2][2]) == "true" then
101                         return 2
102                 end
103                 return 1
104         end,
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
109                                 return i
110                         end
111                 end
112                 return 1
113         end
114 }
115
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]
120                 end
121         end
122         return 0
123 end
124
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") .. "]"
130 end
131
132 local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
133
134         if fields["dlg_reset_singleplayer_confirm"] ~= nil then
135                 local worldlist = core.get_worlds()
136                 local found_singleplayerworld = false
137
138                 for i = 1, #worldlist do
139                         if worldlist[i].name == "singleplayerworld" then
140                                 found_singleplayerworld = true
141                                 gamedata.worldindex = i
142                         end
143                 end
144
145                 if found_singleplayerworld then
146                         core.delete_world(gamedata.worldindex)
147                 end
148
149                 core.create_world("singleplayerworld", 1)
150                 worldlist = core.get_worlds()
151                 found_singleplayerworld = false
152
153                 for i = 1, #worldlist do
154                         if worldlist[i].name == "singleplayerworld" then
155                                 found_singleplayerworld = true
156                                 gamedata.worldindex = i
157                         end
158                 end
159         end
160
161         this.parent:show()
162         this:hide()
163         this:delete()
164         return true
165 end
166
167 local function showconfirm_reset(tabview)
168         local new_dlg = dialog_create("reset_spworld",
169                 dlg_confirm_reset_formspec,
170                 dlg_confirm_reset_btnhandler,
171                 nil)
172         new_dlg:set_parent(tabview)
173         tabview:hide()
174         new_dlg:show()
175 end
176
177 local function formspec(tabview, name, tabdata)
178         local tab_string =
179                 "box[0,0;3.5,4.5;#999999]" ..
180                 "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
181                                 .. dump(core.settings:get_bool("smooth_lighting")) .. "]" ..
182                 "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";"
183                                 .. dump(core.settings:get_bool("enable_particles")) .. "]" ..
184                 "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
185                                 .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" ..
186                 "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
187                                 .. dump(core.settings:get_bool("opaque_water")) .. "]" ..
188                 "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
189                                 .. dump(core.settings:get_bool("connected_glass")) .. "]" ..
190                 "dropdown[0.25,2.8;3.3;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
191                                 .. getSettingIndex.NodeHighlighting() .. "]" ..
192                 "dropdown[0.25,3.6;3.3;dd_leaves_style;" .. dd_options.leaves[1] .. ";"
193                                 .. getSettingIndex.Leaves() .. "]" ..
194                 "box[3.75,0;3.75,4.45;#999999]" ..
195                 "label[3.85,0.1;" .. fgettext("Texturing:") .. "]" ..
196                 "dropdown[3.85,0.55;3.85;dd_filters;" .. dd_options.filters[1] .. ";"
197                                 .. getSettingIndex.Filter() .. "]" ..
198                 "dropdown[3.85,1.35;3.85;dd_mipmap;" .. dd_options.mipmap[1] .. ";"
199                                 .. getSettingIndex.Mipmap() .. "]" ..
200                 "label[3.85,2.15;" .. fgettext("Antialiasing:") .. "]" ..
201                 "dropdown[3.85,2.6;3.85;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";"
202                                 .. getSettingIndex.Antialiasing() .. "]" ..
203                 "label[3.85,3.45;" .. fgettext("Screen:") .. "]" ..
204                 "checkbox[3.85,3.6;cb_autosave_screensize;" .. fgettext("Autosave screen size") .. ";"
205                                 .. dump(core.settings:get_bool("autosave_screensize")) .. "]" ..
206                 "box[7.75,0;4,4.4;#999999]" ..
207                 "checkbox[8,0;cb_shaders;" .. fgettext("Shaders") .. ";"
208                                 .. dump(core.settings:get_bool("enable_shaders")) .. "]"
209
210         if PLATFORM == "Android" then
211                 tab_string = tab_string ..
212                         "button[8,4.75;3.75,0.5;btn_reset_singleplayer;"
213                         .. fgettext("Reset singleplayer world") .. "]"
214         else
215                 tab_string = tab_string ..
216                         "button[8,4.85;3.75,0.5;btn_change_keys;"
217                         .. fgettext("Change keys") .. "]"
218         end
219
220         tab_string = tab_string ..
221                 "button[0,4.85;3.75,0.5;btn_advanced_settings;"
222                 .. fgettext("Advanced Settings") .. "]"
223
224
225         if core.settings:get("touchscreen_threshold") ~= nil then
226                 tab_string = tab_string ..
227                         "label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" ..
228                         "dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" ..
229                         ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) .. "]"
230         end
231
232         if core.settings:get_bool("enable_shaders") then
233                 tab_string = tab_string ..
234                         "checkbox[8,0.5;cb_bumpmapping;" .. fgettext("Bump Mapping") .. ";"
235                                         .. dump(core.settings:get_bool("enable_bumpmapping")) .. "]" ..
236                         "checkbox[8,1;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
237                                         .. dump(core.settings:get_bool("tone_mapping")) .. "]" ..
238                         "checkbox[8,1.5;cb_generate_normalmaps;" .. fgettext("Normal Mapping") .. ";"
239                                         .. dump(core.settings:get_bool("generate_normalmaps")) .. "]" ..
240                         "checkbox[8,2;cb_parallax;" .. fgettext("Parallax Occlusion") .. ";"
241                                         .. dump(core.settings:get_bool("enable_parallax_occlusion")) .. "]" ..
242                         "checkbox[8,2.5;cb_waving_water;" .. fgettext("Waving Water") .. ";"
243                                         .. dump(core.settings:get_bool("enable_waving_water")) .. "]" ..
244                         "checkbox[8,3;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
245                                         .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
246                         "checkbox[8,3.5;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
247                                         .. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
248         else
249                 tab_string = tab_string ..
250                         "label[8.38,0.7;" .. core.colorize("#888888",
251                                         fgettext("Bump Mapping")) .. "]" ..
252                         "label[8.38,1.2;" .. core.colorize("#888888",
253                                         fgettext("Tone Mapping")) .. "]" ..
254                         "label[8.38,1.7;" .. core.colorize("#888888",
255                                         fgettext("Normal Mapping")) .. "]" ..
256                         "label[8.38,2.2;" .. core.colorize("#888888",
257                                         fgettext("Parallax Occlusion")) .. "]" ..
258                         "label[8.38,2.7;" .. core.colorize("#888888",
259                                         fgettext("Waving Water")) .. "]" ..
260                         "label[8.38,3.2;" .. core.colorize("#888888",
261                                         fgettext("Waving Leaves")) .. "]" ..
262                         "label[8.38,3.7;" .. core.colorize("#888888",
263                                         fgettext("Waving Plants")) .. "]"
264         end
265
266         return tab_string
267 end
268
269 --------------------------------------------------------------------------------
270 local function handle_settings_buttons(this, fields, tabname, tabdata)
271
272         if fields["btn_advanced_settings"] ~= nil then
273                 local adv_settings_dlg = create_adv_settings_dlg()
274                 adv_settings_dlg:set_parent(this)
275                 this:hide()
276                 adv_settings_dlg:show()
277                 --mm_texture.update("singleplayer", current_game())
278                 return true
279         end
280         if fields["cb_smooth_lighting"] then
281                 core.settings:set("smooth_lighting", fields["cb_smooth_lighting"])
282                 return true
283         end
284         if fields["cb_particles"] then
285                 core.settings:set("enable_particles", fields["cb_particles"])
286                 return true
287         end
288         if fields["cb_3d_clouds"] then
289                 core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"])
290                 return true
291         end
292         if fields["cb_opaque_water"] then
293                 core.settings:set("opaque_water", fields["cb_opaque_water"])
294                 return true
295         end
296         if fields["cb_connected_glass"] then
297                 core.settings:set("connected_glass", fields["cb_connected_glass"])
298                 return true
299         end
300         if fields["cb_autosave_screensize"] then
301                 core.settings:set("autosave_screensize", fields["cb_autosave_screensize"])
302                 return true
303         end
304         if fields["cb_shaders"] then
305                 if (core.settings:get("video_driver") == "direct3d8" or
306                                 core.settings:get("video_driver") == "direct3d9") then
307                         core.settings:set("enable_shaders", "false")
308                         gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
309                 else
310                         core.settings:set("enable_shaders", fields["cb_shaders"])
311                 end
312                 return true
313         end
314         if fields["cb_bumpmapping"] then
315                 core.settings:set("enable_bumpmapping", fields["cb_bumpmapping"])
316                 return true
317         end
318         if fields["cb_tonemapping"] then
319                 core.settings:set("tone_mapping", fields["cb_tonemapping"])
320                 return true
321         end
322         if fields["cb_generate_normalmaps"] then
323                 core.settings:set("generate_normalmaps", fields["cb_generate_normalmaps"])
324                 return true
325         end
326         if fields["cb_parallax"] then
327                 core.settings:set("enable_parallax_occlusion", fields["cb_parallax"])
328                 return true
329         end
330         if fields["cb_waving_water"] then
331                 core.settings:set("enable_waving_water", fields["cb_waving_water"])
332                 return true
333         end
334         if fields["cb_waving_leaves"] then
335                 core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"])
336         end
337         if fields["cb_waving_plants"] then
338                 core.settings:set("enable_waving_plants", fields["cb_waving_plants"])
339                 return true
340         end
341         if fields["btn_change_keys"] then
342                 core.show_keys_menu()
343                 return true
344         end
345         if fields["cb_touchscreen_target"] then
346                 core.settings:set("touchtarget", fields["cb_touchscreen_target"])
347                 return true
348         end
349         if fields["btn_reset_singleplayer"] then
350                 showconfirm_reset(this)
351                 return true
352         end
353
354         --Note dropdowns have to be handled LAST!
355         local ddhandled = false
356
357         for i = 1, #labels.leaves do
358                 if fields["dd_leaves_style"] == labels.leaves[i] then
359                         core.settings:set("leaves_style", dd_options.leaves[2][i])
360                         ddhandled = true
361                 end
362         end
363         for i = 1, #labels.node_highlighting do
364                 if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
365                         core.settings:set("node_highlighting", dd_options.node_highlighting[2][i])
366                         ddhandled = true
367                 end
368         end
369         if fields["dd_filters"] == labels.filters[1] then
370                 core.settings:set("bilinear_filter", "false")
371                 core.settings:set("trilinear_filter", "false")
372                 ddhandled = true
373         elseif fields["dd_filters"] == labels.filters[2] then
374                 core.settings:set("bilinear_filter", "true")
375                 core.settings:set("trilinear_filter", "false")
376                 ddhandled = true
377         elseif fields["dd_filters"] == labels.filters[3] then
378                 core.settings:set("bilinear_filter", "false")
379                 core.settings:set("trilinear_filter", "true")
380                 ddhandled = true
381         end
382         if fields["dd_mipmap"] == labels.mipmap[1] then
383                 core.settings:set("mip_map", "false")
384                 core.settings:set("anisotropic_filter", "false")
385                 ddhandled = true
386         elseif fields["dd_mipmap"] == labels.mipmap[2] then
387                 core.settings:set("mip_map", "true")
388                 core.settings:set("anisotropic_filter", "false")
389                 ddhandled = true
390         elseif fields["dd_mipmap"] == labels.mipmap[3] then
391                 core.settings:set("mip_map", "true")
392                 core.settings:set("anisotropic_filter", "true")
393                 ddhandled = true
394         end
395         if fields["dd_antialiasing"] then
396                 core.settings:set("fsaa",
397                         antialiasing_fname_to_name(fields["dd_antialiasing"]))
398                 ddhandled = true
399         end
400         if fields["dd_touchthreshold"] then
401                 core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"])
402                 ddhandled = true
403         end
404
405         return ddhandled
406 end
407
408 return {
409         name = "settings",
410         caption = fgettext("Settings"),
411         cbf_formspec = formspec,
412         cbf_button_handler = handle_settings_buttons
413 }