tab_settings.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 formspec(tabview, name, tabdata)
  120. local tab_string =
  121. "box[0,0;3.75,4.5;#999999]" ..
  122. "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
  123. .. dump(core.settings:get_bool("smooth_lighting")) .. "]" ..
  124. "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";"
  125. .. dump(core.settings:get_bool("enable_particles")) .. "]" ..
  126. "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
  127. .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" ..
  128. "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
  129. .. dump(core.settings:get_bool("opaque_water")) .. "]" ..
  130. "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
  131. .. dump(core.settings:get_bool("connected_glass")) .. "]" ..
  132. "dropdown[0.25,2.8;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
  133. .. getSettingIndex.NodeHighlighting() .. "]" ..
  134. "dropdown[0.25,3.6;3.5;dd_leaves_style;" .. dd_options.leaves[1] .. ";"
  135. .. getSettingIndex.Leaves() .. "]" ..
  136. "box[4,0;3.75,4.5;#999999]" ..
  137. "label[4.25,0.1;" .. fgettext("Texturing:") .. "]" ..
  138. "dropdown[4.25,0.55;3.5;dd_filters;" .. dd_options.filters[1] .. ";"
  139. .. getSettingIndex.Filter() .. "]" ..
  140. "dropdown[4.25,1.35;3.5;dd_mipmap;" .. dd_options.mipmap[1] .. ";"
  141. .. getSettingIndex.Mipmap() .. "]" ..
  142. "label[4.25,2.15;" .. fgettext("Antialiasing:") .. "]" ..
  143. "dropdown[4.25,2.6;3.5;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";"
  144. .. getSettingIndex.Antialiasing() .. "]" ..
  145. "label[4.25,3.45;" .. fgettext("Screen:") .. "]" ..
  146. "checkbox[4.25,3.6;cb_autosave_screensize;" .. fgettext("Autosave Screen Size") .. ";"
  147. .. dump(core.settings:get_bool("autosave_screensize")) .. "]" ..
  148. "box[8,0;3.75,4.5;#999999]"
  149. local video_driver = core.settings:get("video_driver")
  150. local shaders_enabled = core.settings:get_bool("enable_shaders")
  151. if video_driver == "opengl" then
  152. tab_string = tab_string ..
  153. "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders") .. ";"
  154. .. tostring(shaders_enabled) .. "]"
  155. elseif video_driver == "ogles2" then
  156. tab_string = tab_string ..
  157. "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders (experimental)") .. ";"
  158. .. tostring(shaders_enabled) .. "]"
  159. else
  160. core.settings:set_bool("enable_shaders", false)
  161. shaders_enabled = false
  162. tab_string = tab_string ..
  163. "label[8.38,0.2;" .. core.colorize("#888888",
  164. fgettext("Shaders (unavailable)")) .. "]"
  165. end
  166. tab_string = tab_string ..
  167. "button[8,4.75;3.95,1;btn_change_keys;"
  168. .. fgettext("Change Keys") .. "]"
  169. tab_string = tab_string ..
  170. "button[0,4.75;3.95,1;btn_advanced_settings;"
  171. .. fgettext("All Settings") .. "]"
  172. if core.settings:get("touchscreen_threshold") ~= nil then
  173. tab_string = tab_string ..
  174. "label[4.3,4.2;" .. fgettext("Touchthreshold: (px)") .. "]" ..
  175. "dropdown[4.25,4.65;3.5;dd_touchthreshold;0,10,20,30,40,50;" ..
  176. ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) ..
  177. "]box[4.0,4.5;3.75,1.0;#999999]"
  178. end
  179. if shaders_enabled then
  180. tab_string = tab_string ..
  181. "checkbox[8.25,0.5;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
  182. .. dump(core.settings:get_bool("tone_mapping")) .. "]" ..
  183. "checkbox[8.25,1;cb_waving_water;" .. fgettext("Waving Liquids") .. ";"
  184. .. dump(core.settings:get_bool("enable_waving_water")) .. "]" ..
  185. "checkbox[8.25,1.5;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
  186. .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
  187. "checkbox[8.25,2;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
  188. .. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
  189. else
  190. tab_string = tab_string ..
  191. "label[8.38,0.7;" .. core.colorize("#888888",
  192. fgettext("Tone Mapping")) .. "]" ..
  193. "label[8.38,1.2;" .. core.colorize("#888888",
  194. fgettext("Waving Liquids")) .. "]" ..
  195. "label[8.38,1.7;" .. core.colorize("#888888",
  196. fgettext("Waving Leaves")) .. "]" ..
  197. "label[8.38,2.2;" .. core.colorize("#888888",
  198. fgettext("Waving Plants")) .. "]"
  199. end
  200. return tab_string
  201. end
  202. --------------------------------------------------------------------------------
  203. local function handle_settings_buttons(this, fields, tabname, tabdata)
  204. if fields["btn_advanced_settings"] ~= nil then
  205. local adv_settings_dlg = create_adv_settings_dlg()
  206. adv_settings_dlg:set_parent(this)
  207. this:hide()
  208. adv_settings_dlg:show()
  209. --mm_texture.update("singleplayer", current_game())
  210. return true
  211. end
  212. if fields["cb_smooth_lighting"] then
  213. core.settings:set("smooth_lighting", fields["cb_smooth_lighting"])
  214. return true
  215. end
  216. if fields["cb_particles"] then
  217. core.settings:set("enable_particles", fields["cb_particles"])
  218. return true
  219. end
  220. if fields["cb_3d_clouds"] then
  221. core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"])
  222. return true
  223. end
  224. if fields["cb_opaque_water"] then
  225. core.settings:set("opaque_water", fields["cb_opaque_water"])
  226. return true
  227. end
  228. if fields["cb_connected_glass"] then
  229. core.settings:set("connected_glass", fields["cb_connected_glass"])
  230. return true
  231. end
  232. if fields["cb_autosave_screensize"] then
  233. core.settings:set("autosave_screensize", fields["cb_autosave_screensize"])
  234. return true
  235. end
  236. if fields["cb_shaders"] then
  237. if (core.settings:get("video_driver") == "direct3d8" or
  238. core.settings:get("video_driver") == "direct3d9") then
  239. core.settings:set("enable_shaders", "false")
  240. gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
  241. else
  242. core.settings:set("enable_shaders", fields["cb_shaders"])
  243. end
  244. return true
  245. end
  246. if fields["cb_tonemapping"] then
  247. core.settings:set("tone_mapping", fields["cb_tonemapping"])
  248. return true
  249. end
  250. if fields["cb_waving_water"] then
  251. core.settings:set("enable_waving_water", fields["cb_waving_water"])
  252. return true
  253. end
  254. if fields["cb_waving_leaves"] then
  255. core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"])
  256. end
  257. if fields["cb_waving_plants"] then
  258. core.settings:set("enable_waving_plants", fields["cb_waving_plants"])
  259. return true
  260. end
  261. if fields["btn_change_keys"] then
  262. core.show_keys_menu()
  263. return true
  264. end
  265. if fields["cb_touchscreen_target"] then
  266. core.settings:set("touchtarget", fields["cb_touchscreen_target"])
  267. return true
  268. end
  269. --Note dropdowns have to be handled LAST!
  270. local ddhandled = false
  271. for i = 1, #labels.leaves do
  272. if fields["dd_leaves_style"] == labels.leaves[i] then
  273. core.settings:set("leaves_style", dd_options.leaves[2][i])
  274. ddhandled = true
  275. end
  276. end
  277. for i = 1, #labels.node_highlighting do
  278. if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
  279. core.settings:set("node_highlighting", dd_options.node_highlighting[2][i])
  280. ddhandled = true
  281. end
  282. end
  283. if fields["dd_filters"] == labels.filters[1] then
  284. core.settings:set("bilinear_filter", "false")
  285. core.settings:set("trilinear_filter", "false")
  286. ddhandled = true
  287. elseif fields["dd_filters"] == labels.filters[2] then
  288. core.settings:set("bilinear_filter", "true")
  289. core.settings:set("trilinear_filter", "false")
  290. ddhandled = true
  291. elseif fields["dd_filters"] == labels.filters[3] then
  292. core.settings:set("bilinear_filter", "false")
  293. core.settings:set("trilinear_filter", "true")
  294. ddhandled = true
  295. end
  296. if fields["dd_mipmap"] == labels.mipmap[1] then
  297. core.settings:set("mip_map", "false")
  298. core.settings:set("anisotropic_filter", "false")
  299. ddhandled = true
  300. elseif fields["dd_mipmap"] == labels.mipmap[2] then
  301. core.settings:set("mip_map", "true")
  302. core.settings:set("anisotropic_filter", "false")
  303. ddhandled = true
  304. elseif fields["dd_mipmap"] == labels.mipmap[3] then
  305. core.settings:set("mip_map", "true")
  306. core.settings:set("anisotropic_filter", "true")
  307. ddhandled = true
  308. end
  309. if fields["dd_antialiasing"] then
  310. core.settings:set("fsaa",
  311. antialiasing_fname_to_name(fields["dd_antialiasing"]))
  312. ddhandled = true
  313. end
  314. if fields["dd_touchthreshold"] then
  315. core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"])
  316. ddhandled = true
  317. end
  318. return ddhandled
  319. end
  320. return {
  321. name = "settings",
  322. caption = fgettext("Settings"),
  323. cbf_formspec = formspec,
  324. cbf_button_handler = handle_settings_buttons
  325. }