tab_settings.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. shadow_levels = {
  46. fgettext("Disabled"),
  47. fgettext("Very Low"),
  48. fgettext("Low"),
  49. fgettext("Medium"),
  50. fgettext("High"),
  51. fgettext("Very High")
  52. }
  53. }
  54. local dd_options = {
  55. leaves = {
  56. table.concat(labels.leaves, ","),
  57. {"opaque", "simple", "fancy"}
  58. },
  59. node_highlighting = {
  60. table.concat(labels.node_highlighting, ","),
  61. {"box", "halo", "none"}
  62. },
  63. filters = {
  64. table.concat(labels.filters, ","),
  65. {"", "bilinear_filter", "trilinear_filter"}
  66. },
  67. mipmap = {
  68. table.concat(labels.mipmap, ","),
  69. {"", "mip_map", "anisotropic_filter"}
  70. },
  71. antialiasing = {
  72. table.concat(labels.antialiasing, ","),
  73. {"0", "2", "4", "8"}
  74. },
  75. shadow_levels = {
  76. table.concat(labels.shadow_levels, ","),
  77. { "0", "1", "2", "3", "4", "5" }
  78. }
  79. }
  80. local getSettingIndex = {
  81. Leaves = function()
  82. local style = core.settings:get("leaves_style")
  83. for idx, name in pairs(dd_options.leaves[2]) do
  84. if style == name then return idx end
  85. end
  86. return 1
  87. end,
  88. NodeHighlighting = function()
  89. local style = core.settings:get("node_highlighting")
  90. for idx, name in pairs(dd_options.node_highlighting[2]) do
  91. if style == name then return idx end
  92. end
  93. return 1
  94. end,
  95. Filter = function()
  96. if core.settings:get(dd_options.filters[2][3]) == "true" then
  97. return 3
  98. elseif core.settings:get(dd_options.filters[2][3]) == "false" and
  99. core.settings:get(dd_options.filters[2][2]) == "true" then
  100. return 2
  101. end
  102. return 1
  103. end,
  104. Mipmap = function()
  105. if core.settings:get(dd_options.mipmap[2][3]) == "true" then
  106. return 3
  107. elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and
  108. core.settings:get(dd_options.mipmap[2][2]) == "true" then
  109. return 2
  110. end
  111. return 1
  112. end,
  113. Antialiasing = function()
  114. local antialiasing_setting = core.settings:get("fsaa")
  115. for i = 1, #dd_options.antialiasing[2] do
  116. if antialiasing_setting == dd_options.antialiasing[2][i] then
  117. return i
  118. end
  119. end
  120. return 1
  121. end,
  122. ShadowMapping = function()
  123. local shadow_setting = core.settings:get("shadow_levels")
  124. for i = 1, #dd_options.shadow_levels[2] do
  125. if shadow_setting == dd_options.shadow_levels[2][i] then
  126. return i
  127. end
  128. end
  129. return 1
  130. end
  131. }
  132. local function antialiasing_fname_to_name(fname)
  133. for i = 1, #labels.antialiasing do
  134. if fname == labels.antialiasing[i] then
  135. return dd_options.antialiasing[2][i]
  136. end
  137. end
  138. return 0
  139. end
  140. local function formspec(tabview, name, tabdata)
  141. local tab_string =
  142. "box[0,0;3.75,4.5;#999999]" ..
  143. "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
  144. .. dump(core.settings:get_bool("smooth_lighting")) .. "]" ..
  145. "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";"
  146. .. dump(core.settings:get_bool("enable_particles")) .. "]" ..
  147. "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
  148. .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" ..
  149. "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
  150. .. dump(core.settings:get_bool("opaque_water")) .. "]" ..
  151. "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
  152. .. dump(core.settings:get_bool("connected_glass")) .. "]" ..
  153. "dropdown[0.25,2.8;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
  154. .. getSettingIndex.NodeHighlighting() .. "]" ..
  155. "dropdown[0.25,3.6;3.5;dd_leaves_style;" .. dd_options.leaves[1] .. ";"
  156. .. getSettingIndex.Leaves() .. "]" ..
  157. "box[4,0;3.75,4.9;#999999]" ..
  158. "label[4.25,0.1;" .. fgettext("Texturing:") .. "]" ..
  159. "dropdown[4.25,0.55;3.5;dd_filters;" .. dd_options.filters[1] .. ";"
  160. .. getSettingIndex.Filter() .. "]" ..
  161. "dropdown[4.25,1.35;3.5;dd_mipmap;" .. dd_options.mipmap[1] .. ";"
  162. .. getSettingIndex.Mipmap() .. "]" ..
  163. "label[4.25,2.15;" .. fgettext("Antialiasing:") .. "]" ..
  164. "dropdown[4.25,2.6;3.5;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";"
  165. .. getSettingIndex.Antialiasing() .. "]" ..
  166. "box[8,0;3.75,4.5;#999999]"
  167. local video_driver = core.settings:get("video_driver")
  168. local shaders_enabled = core.settings:get_bool("enable_shaders")
  169. if video_driver == "opengl" then
  170. tab_string = tab_string ..
  171. "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders") .. ";"
  172. .. tostring(shaders_enabled) .. "]"
  173. elseif video_driver == "ogles2" then
  174. tab_string = tab_string ..
  175. "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders (experimental)") .. ";"
  176. .. tostring(shaders_enabled) .. "]"
  177. else
  178. core.settings:set_bool("enable_shaders", false)
  179. shaders_enabled = false
  180. tab_string = tab_string ..
  181. "label[8.38,0.2;" .. core.colorize("#888888",
  182. fgettext("Shaders (unavailable)")) .. "]"
  183. end
  184. tab_string = tab_string ..
  185. "button[8,4.75;3.95,1;btn_change_keys;"
  186. .. fgettext("Change Keys") .. "]"
  187. tab_string = tab_string ..
  188. "button[0,4.75;3.95,1;btn_advanced_settings;"
  189. .. fgettext("All Settings") .. "]"
  190. if core.settings:get("touchscreen_threshold") ~= nil then
  191. tab_string = tab_string ..
  192. "label[4.25,3.5;" .. fgettext("Touch threshold (px):") .. "]" ..
  193. "dropdown[4.25,3.95;3.5;dd_touchthreshold;0,10,20,30,40,50;" ..
  194. ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) ..
  195. "]"
  196. else
  197. tab_string = tab_string ..
  198. "label[4.25,3.65;" .. fgettext("Screen:") .. "]" ..
  199. "checkbox[4.25,3.9;cb_autosave_screensize;" .. fgettext("Autosave Screen Size") .. ";"
  200. .. dump(core.settings:get_bool("autosave_screensize")) .. "]"
  201. end
  202. if shaders_enabled then
  203. tab_string = tab_string ..
  204. "checkbox[8.25,0.5;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
  205. .. dump(core.settings:get_bool("tone_mapping")) .. "]" ..
  206. "checkbox[8.25,1;cb_waving_water;" .. fgettext("Waving Liquids") .. ";"
  207. .. dump(core.settings:get_bool("enable_waving_water")) .. "]" ..
  208. "checkbox[8.25,1.5;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
  209. .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
  210. "checkbox[8.25,2;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
  211. .. dump(core.settings:get_bool("enable_waving_plants")) .. "]"..
  212. "label[8.25,2.8;" .. fgettext("Dynamic shadows:") .. "]" ..
  213. "label[8.25,3.2;" .. fgettext("(game support required)") .. "]" ..
  214. "dropdown[8.25,3.7;3.5;dd_shadows;" .. dd_options.shadow_levels[1] .. ";"
  215. .. getSettingIndex.ShadowMapping() .. "]"
  216. else
  217. tab_string = tab_string ..
  218. "label[8.38,0.7;" .. core.colorize("#888888",
  219. fgettext("Tone Mapping")) .. "]" ..
  220. "label[8.38,1.2;" .. core.colorize("#888888",
  221. fgettext("Waving Liquids")) .. "]" ..
  222. "label[8.38,1.7;" .. core.colorize("#888888",
  223. fgettext("Waving Leaves")) .. "]" ..
  224. "label[8.38,2.2;" .. core.colorize("#888888",
  225. fgettext("Waving Plants")) .. "]"..
  226. "label[8.38,2.7;" .. core.colorize("#888888",
  227. fgettext("Dynamic shadows")) .. "]"
  228. end
  229. return tab_string
  230. end
  231. --------------------------------------------------------------------------------
  232. local function handle_settings_buttons(this, fields, tabname, tabdata)
  233. if fields["btn_advanced_settings"] ~= nil then
  234. local adv_settings_dlg = create_adv_settings_dlg()
  235. adv_settings_dlg:set_parent(this)
  236. this:hide()
  237. adv_settings_dlg:show()
  238. --mm_game_theme.update("singleplayer", current_game())
  239. return true
  240. end
  241. if fields["cb_smooth_lighting"] then
  242. core.settings:set("smooth_lighting", fields["cb_smooth_lighting"])
  243. return true
  244. end
  245. if fields["cb_particles"] then
  246. core.settings:set("enable_particles", fields["cb_particles"])
  247. return true
  248. end
  249. if fields["cb_3d_clouds"] then
  250. core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"])
  251. return true
  252. end
  253. if fields["cb_opaque_water"] then
  254. core.settings:set("opaque_water", fields["cb_opaque_water"])
  255. return true
  256. end
  257. if fields["cb_connected_glass"] then
  258. core.settings:set("connected_glass", fields["cb_connected_glass"])
  259. return true
  260. end
  261. if fields["cb_autosave_screensize"] then
  262. core.settings:set("autosave_screensize", fields["cb_autosave_screensize"])
  263. return true
  264. end
  265. if fields["cb_shaders"] then
  266. core.settings:set("enable_shaders", fields["cb_shaders"])
  267. return true
  268. end
  269. if fields["cb_tonemapping"] then
  270. core.settings:set("tone_mapping", fields["cb_tonemapping"])
  271. return true
  272. end
  273. if fields["cb_waving_water"] then
  274. core.settings:set("enable_waving_water", fields["cb_waving_water"])
  275. return true
  276. end
  277. if fields["cb_waving_leaves"] then
  278. core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"])
  279. end
  280. if fields["cb_waving_plants"] then
  281. core.settings:set("enable_waving_plants", fields["cb_waving_plants"])
  282. return true
  283. end
  284. if fields["btn_change_keys"] then
  285. core.show_keys_menu()
  286. return true
  287. end
  288. if fields["cb_touchscreen_target"] then
  289. core.settings:set("touchtarget", fields["cb_touchscreen_target"])
  290. return true
  291. end
  292. --Note dropdowns have to be handled LAST!
  293. local ddhandled = false
  294. for i = 1, #labels.leaves do
  295. if fields["dd_leaves_style"] == labels.leaves[i] then
  296. core.settings:set("leaves_style", dd_options.leaves[2][i])
  297. ddhandled = true
  298. end
  299. end
  300. for i = 1, #labels.node_highlighting do
  301. if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
  302. core.settings:set("node_highlighting", dd_options.node_highlighting[2][i])
  303. ddhandled = true
  304. end
  305. end
  306. if fields["dd_filters"] == labels.filters[1] then
  307. core.settings:set("bilinear_filter", "false")
  308. core.settings:set("trilinear_filter", "false")
  309. ddhandled = true
  310. elseif fields["dd_filters"] == labels.filters[2] then
  311. core.settings:set("bilinear_filter", "true")
  312. core.settings:set("trilinear_filter", "false")
  313. ddhandled = true
  314. elseif fields["dd_filters"] == labels.filters[3] then
  315. core.settings:set("bilinear_filter", "false")
  316. core.settings:set("trilinear_filter", "true")
  317. ddhandled = true
  318. end
  319. if fields["dd_mipmap"] == labels.mipmap[1] then
  320. core.settings:set("mip_map", "false")
  321. core.settings:set("anisotropic_filter", "false")
  322. ddhandled = true
  323. elseif fields["dd_mipmap"] == labels.mipmap[2] then
  324. core.settings:set("mip_map", "true")
  325. core.settings:set("anisotropic_filter", "false")
  326. ddhandled = true
  327. elseif fields["dd_mipmap"] == labels.mipmap[3] then
  328. core.settings:set("mip_map", "true")
  329. core.settings:set("anisotropic_filter", "true")
  330. ddhandled = true
  331. end
  332. if fields["dd_antialiasing"] then
  333. core.settings:set("fsaa",
  334. antialiasing_fname_to_name(fields["dd_antialiasing"]))
  335. ddhandled = true
  336. end
  337. if fields["dd_touchthreshold"] then
  338. core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"])
  339. ddhandled = true
  340. end
  341. for i = 1, #labels.shadow_levels do
  342. if fields["dd_shadows"] == labels.shadow_levels[i] then
  343. core.settings:set("shadow_levels", dd_options.shadow_levels[2][i])
  344. ddhandled = true
  345. end
  346. end
  347. if fields["dd_shadows"] == labels.shadow_levels[1] then
  348. core.settings:set("enable_dynamic_shadows", "false")
  349. else
  350. local shadow_presets = {
  351. [2] = { 62, 512, "true", 0, "false" },
  352. [3] = { 93, 1024, "true", 0, "false" },
  353. [4] = { 140, 2048, "true", 1, "false" },
  354. [5] = { 210, 4096, "true", 2, "true" },
  355. [6] = { 300, 8192, "true", 2, "true" },
  356. }
  357. local s = shadow_presets[table.indexof(labels.shadow_levels, fields["dd_shadows"])]
  358. if s then
  359. core.settings:set("enable_dynamic_shadows", "true")
  360. core.settings:set("shadow_map_max_distance", s[1])
  361. core.settings:set("shadow_map_texture_size", s[2])
  362. core.settings:set("shadow_map_texture_32bit", s[3])
  363. core.settings:set("shadow_filters", s[4])
  364. core.settings:set("shadow_map_color", s[5])
  365. end
  366. end
  367. return ddhandled
  368. end
  369. return {
  370. name = "settings",
  371. caption = fgettext("Settings"),
  372. cbf_formspec = formspec,
  373. cbf_button_handler = handle_settings_buttons
  374. }