]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/init.lua
Add register dialog to separate login/register (#12185)
[dragonfireclient.git] / builtin / mainmenu / init.lua
1 --Minetest
2 --Copyright (C) 2014 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 mt_color_grey  = "#AAAAAA"
19 mt_color_blue  = "#6389FF"
20 mt_color_lightblue  = "#99CCFF"
21 mt_color_green = "#72FF63"
22 mt_color_dark_green = "#25C191"
23 mt_color_orange  = "#FF8800"
24
25 local menupath = core.get_mainmenu_path()
26 local basepath = core.get_builtin_path()
27 defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
28                                         DIR_DELIM .. "pack" .. DIR_DELIM
29
30 dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua")
31 dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
32 dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")
33 dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview.lua")
34 dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua")
35 dofile(menupath .. DIR_DELIM .. "async_event.lua")
36 dofile(menupath .. DIR_DELIM .. "common.lua")
37 dofile(menupath .. DIR_DELIM .. "pkgmgr.lua")
38 dofile(menupath .. DIR_DELIM .. "serverlistmgr.lua")
39 dofile(menupath .. DIR_DELIM .. "game_theme.lua")
40
41 dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
42 dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
43 dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua")
44 dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
45 dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
46 dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
47 dofile(menupath .. DIR_DELIM .. "dlg_register.lua")
48 dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
49
50 local tabs = {}
51
52 tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
53 tabs.content  = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
54 tabs.about    = dofile(menupath .. DIR_DELIM .. "tab_about.lua")
55 tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
56 tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
57
58 --------------------------------------------------------------------------------
59 local function main_event_handler(tabview, event)
60         if event == "MenuQuit" then
61                 core.close()
62         end
63         return true
64 end
65
66 --------------------------------------------------------------------------------
67 local function init_globals()
68         -- Init gamedata
69         gamedata.worldindex = 0
70
71         menudata.worldlist = filterlist.create(
72                 core.get_worlds,
73                 compare_worlds,
74                 -- Unique id comparison function
75                 function(element, uid)
76                         return element.name == uid
77                 end,
78                 -- Filter function
79                 function(element, gameid)
80                         return element.gameid == gameid
81                 end
82         )
83
84         menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
85         menudata.worldlist:set_sortmode("alphabetic")
86
87         if not core.settings:get("menu_last_game") then
88                 local default_game = core.settings:get("default_game") or "minetest"
89                 core.settings:set("menu_last_game", default_game)
90         end
91
92         mm_game_theme.init()
93
94         -- Create main tabview
95         local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0})
96
97         tv_main:set_autosave_tab(true)
98         tv_main:add(tabs.local_game)
99         tv_main:add(tabs.play_online)
100
101         tv_main:add(tabs.content)
102         tv_main:add(tabs.settings)
103         tv_main:add(tabs.about)
104
105         tv_main:set_global_event_handler(main_event_handler)
106         tv_main:set_fixed_size(false)
107
108         local last_tab = core.settings:get("maintab_LAST")
109         if last_tab and tv_main.current_tab ~= last_tab then
110                 tv_main:set_tab(last_tab)
111         end
112
113         -- In case the folder of the last selected game has been deleted,
114         -- display "Minetest" as a header
115         if tv_main.current_tab == "local" then
116                 local game = pkgmgr.find_by_gameid(core.settings:get("menu_last_game"))
117                 if game == nil then
118                         mm_game_theme.reset()
119                 end
120         end
121
122         ui.set_default("maintab")
123         tv_main:show()
124
125         ui.update()
126 end
127
128 init_globals()