dlg_reinstall_mtg.lua 3.2 KB

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