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