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