tab_about.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. --Luanti
  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. local function prepare_credits(dest, source)
  18. local string = table.concat(source, "\n") .. "\n"
  19. string = core.hypertext_escape(string)
  20. string = string:gsub("%[.-%]", "<gray>%1</gray>")
  21. table.insert(dest, string)
  22. end
  23. local function get_credits()
  24. local f = assert(io.open(core.get_mainmenu_path() .. "/credits.json"))
  25. local json = core.parse_json(f:read("*all"))
  26. f:close()
  27. return json
  28. end
  29. local function get_renderer_info()
  30. local ret = {}
  31. -- OpenGL version, stripped to just the important part
  32. local s1 = core.get_active_renderer()
  33. if s1:sub(1, 7) == "OpenGL " then
  34. s1 = s1:sub(8)
  35. end
  36. local m = s1:match("^[%d.]+")
  37. if not m then
  38. m = s1:match("^ES [%d.]+")
  39. end
  40. ret[#ret+1] = m or s1
  41. -- video driver
  42. ret[#ret+1] = core.get_active_driver():lower()
  43. -- irrlicht device
  44. ret[#ret+1] = core.get_active_irrlicht_device():upper()
  45. return table.concat(ret, " / ")
  46. end
  47. return {
  48. name = "about",
  49. caption = fgettext("About"),
  50. cbf_formspec = function(tabview, name, tabdata)
  51. local logofile = defaulttexturedir .. "logo.png"
  52. local version = core.get_version()
  53. local hypertext = {
  54. "<tag name=heading color=#ff0>",
  55. "<tag name=gray color=#aaa>",
  56. }
  57. local credits = get_credits()
  58. table.insert_all(hypertext, {
  59. "<heading>", fgettext_ne("Core Developers"), "</heading>\n",
  60. })
  61. prepare_credits(hypertext, credits.core_developers)
  62. table.insert_all(hypertext, {
  63. "\n",
  64. "<heading>", fgettext_ne("Core Team"), "</heading>\n",
  65. })
  66. prepare_credits(hypertext, credits.core_team)
  67. table.insert_all(hypertext, {
  68. "\n",
  69. "<heading>", fgettext_ne("Active Contributors"), "</heading>\n",
  70. })
  71. prepare_credits(hypertext, credits.contributors)
  72. table.insert_all(hypertext, {
  73. "\n",
  74. "<heading>", fgettext_ne("Previous Core Developers"), "</heading>\n",
  75. })
  76. prepare_credits(hypertext, credits.previous_core_developers)
  77. table.insert_all(hypertext, {
  78. "\n",
  79. "<heading>", fgettext_ne("Previous Contributors"), "</heading>\n",
  80. })
  81. prepare_credits(hypertext, credits.previous_contributors)
  82. hypertext = table.concat(hypertext):sub(1, -2)
  83. local fs = "image[1.5,0.6;2.5,2.5;" .. core.formspec_escape(logofile) .. "]" ..
  84. "style[label_button;border=false]" ..
  85. "button[0.1,3.4;5.3,0.5;label_button;" ..
  86. core.formspec_escape(version.project .. " " .. version.string) .. "]" ..
  87. "button_url[1.5,4.1;2.5,0.8;homepage;luanti.org;https://www.luanti.org/]" ..
  88. "hypertext[5.5,0.25;9.75,6.6;credits;" .. core.formspec_escape(hypertext) .. "]"
  89. local active_renderer_info = fgettext("Active renderer:") .. "\n" ..
  90. core.formspec_escape(get_renderer_info())
  91. fs = fs .. "style[label_button2;border=false]" ..
  92. "button[0.1,6;5.3,1;label_button2;" .. active_renderer_info .. "]"..
  93. "tooltip[label_button2;" .. active_renderer_info .. "]"
  94. if PLATFORM == "Android" then
  95. fs = fs .. "button[0.5,5.1;4.5,0.8;share_debug;" .. fgettext("Share debug log") .. "]"
  96. else
  97. fs = fs .. "tooltip[userdata;" ..
  98. fgettext("Opens the directory that contains user-provided worlds, games, mods,\n" ..
  99. "and texture packs in a file manager / explorer.") .. "]"
  100. fs = fs .. "button[0.5,5.1;4.5,0.8;userdata;" .. fgettext("Open User Data Directory") .. "]"
  101. end
  102. return fs
  103. end,
  104. cbf_button_handler = function(this, fields, name, tabdata)
  105. if fields.share_debug then
  106. local path = core.get_user_path() .. DIR_DELIM .. "debug.txt"
  107. core.share_file(path)
  108. end
  109. if fields.userdata then
  110. core.open_dir(core.get_user_path())
  111. end
  112. end,
  113. on_change = function(type)
  114. if type == "ENTER" then
  115. mm_game_theme.set_engine()
  116. end
  117. end,
  118. }