dlg_reinstall_mtg.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. --Minetest
  2. --Copyright (C) 2023 Gregor Parzefall
  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. ---- IMPORTANT ----
  18. -- This whole file can be removed after a while.
  19. -- It was only directly useful for upgrades from 5.7.0 to 5.8.0, but
  20. -- maybe some odd fellow directly upgrades from 5.6.1 to 5.9.0 in the future...
  21. -- see <https://github.com/minetest/minetest/pull/13850> in case it's not obvious
  22. ---- ----
  23. local SETTING_NAME = "no_mtg_notification"
  24. function check_reinstall_mtg()
  25. -- used to be in minetest.conf
  26. if core.settings:get_bool(SETTING_NAME) then
  27. cache_settings:set_bool(SETTING_NAME, true)
  28. core.settings:remove(SETTING_NAME)
  29. end
  30. if cache_settings:get_bool(SETTING_NAME) then
  31. return
  32. end
  33. local games = core.get_games()
  34. for _, game in ipairs(games) do
  35. if game.id == "minetest" then
  36. cache_settings:set_bool(SETTING_NAME, true)
  37. return
  38. end
  39. end
  40. local mtg_world_found = false
  41. local worlds = core.get_worlds()
  42. for _, world in ipairs(worlds) do
  43. if world.gameid == "minetest" then
  44. mtg_world_found = true
  45. break
  46. end
  47. end
  48. if not mtg_world_found then
  49. cache_settings:set_bool(SETTING_NAME, true)
  50. return
  51. end
  52. local maintab = ui.find_by_name("maintab")
  53. local dlg = create_reinstall_mtg_dlg()
  54. dlg:set_parent(maintab)
  55. maintab:hide()
  56. dlg:show()
  57. ui.update()
  58. end
  59. local function get_formspec(dialogdata)
  60. local markup = table.concat({
  61. "<big>", fgettext("Minetest Game is no longer installed by default"), "</big>\n",
  62. fgettext("For a long time, the Minetest engine shipped with a default game called \"Minetest Game\". " ..
  63. "Since Minetest 5.8.0, Minetest ships without a default game."), "\n",
  64. fgettext("If you want to continue playing in your Minetest Game worlds, you need to reinstall Minetest Game."),
  65. })
  66. return table.concat({
  67. "formspec_version[6]",
  68. "size[12.8,7]",
  69. "hypertext[0.375,0.375;12.05,5.2;text;", minetest.formspec_escape(markup), "]",
  70. "container[0.375,5.825]",
  71. "style[dismiss;bgcolor=red]",
  72. "button[0,0;4,0.8;dismiss;", fgettext("Dismiss"), "]",
  73. "button[4.25,0;8,0.8;reinstall;", fgettext("Reinstall Minetest Game"), "]",
  74. "container_end[]",
  75. })
  76. end
  77. local function buttonhandler(this, fields)
  78. if fields.reinstall then
  79. -- Don't set "no_mtg_notification" here so that the dialog will be shown
  80. -- again if downloading MTG fails for whatever reason.
  81. this:delete()
  82. local maintab = ui.find_by_name("maintab")
  83. local dlg = create_contentdb_dlg(nil, "minetest/minetest")
  84. dlg:set_parent(maintab)
  85. maintab:hide()
  86. dlg:show()
  87. return true
  88. end
  89. if fields.dismiss then
  90. cache_settings:set_bool("no_mtg_notification", true)
  91. this:delete()
  92. return true
  93. end
  94. end
  95. local function eventhandler(event)
  96. if event == "DialogShow" then
  97. mm_game_theme.set_engine()
  98. return true
  99. elseif event == "MenuQuit" then
  100. -- Don't allow closing the dialog with ESC, but still allow exiting
  101. -- Minetest.
  102. core.close()
  103. return true
  104. end
  105. return false
  106. end
  107. function create_reinstall_mtg_dlg()
  108. local dlg = dialog_create("dlg_reinstall_mtg", get_formspec,
  109. buttonhandler, eventhandler)
  110. return dlg
  111. end