2
0

tab_settings.lua 13 KB

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