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