ab2b8d80cc073ca840cfd45b3bb9dea946c92926
[oweals/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  = "#0000DD"
20 mt_color_green = "#00DD00"
21 mt_color_dark_green = "#003300"
22
23 --for all other colors ask sfan5 to complete his work!
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 .. DIR_DELIM .. "common" .. DIR_DELIM .. "async_event.lua")
31 dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "filterlist.lua")
32 dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
33 dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "dialog.lua")
34 dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "tabview.lua")
35 dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "ui.lua")
36 dofile(menupath .. DIR_DELIM .. "common.lua")
37 dofile(menupath .. DIR_DELIM .. "gamemgr.lua")
38 dofile(menupath .. DIR_DELIM .. "modmgr.lua")
39 dofile(menupath .. DIR_DELIM .. "store.lua")
40 dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
41 dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
42 dofile(menupath .. DIR_DELIM .. "dlg_delete_mod.lua")
43 dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
44 dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
45 dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
46 dofile(menupath .. DIR_DELIM .. "tab_mods.lua")
47 dofile(menupath .. DIR_DELIM .. "tab_multiplayer.lua")
48 dofile(menupath .. DIR_DELIM .. "tab_server.lua")
49 dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
50 dofile(menupath .. DIR_DELIM .. "tab_singleplayer.lua")
51 dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua")
52 dofile(menupath .. DIR_DELIM .. "textures.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                                         function(element,uid)
71                                                 if element.name == uid then
72                                                         return true
73                                                 end
74                                                 return false
75                                         end, --unique id compare fct
76                                         function(element,gameid)
77                                                 if element.gameid == gameid then
78                                                         return true
79                                                 end
80                                                 return false
81                                         end --filter fct
82                                         )
83
84         menudata.worldlist:add_sort_mechanism("alphabetic",sort_worlds_alphabetic)
85         menudata.worldlist:set_sortmode("alphabetic")
86         
87         mm_texture.init()
88         
89         --create main tabview
90         local tv_main = tabview_create("maintab",{x=12,y=5.2},{x=-0.3,y=-0.99})
91         tv_main:set_autosave_tab(true)
92         tv_main:add(tab_singleplayer)
93         tv_main:add(tab_multiplayer)
94         tv_main:add(tab_server)
95         tv_main:add(tab_settings)
96         tv_main:add(tab_texturepacks)
97         tv_main:add(tab_mods)
98         tv_main:add(tab_credits)
99         
100         tv_main:set_global_event_handler(main_event_handler)
101         
102         tv_main:set_tab(core.setting_get("maintab_LAST"))
103         ui.set_default("maintab")
104         tv_main:show()
105
106         --create modstore ui
107         modstore.init({x=12,y=8},4,3)
108
109         ui.update()
110         
111         core.sound_play("main_menu", true)
112 end
113
114 init_globals()