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