]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/init.lua
Settingtypes.txt: Various language improvements, document stable mapgens (#7801)
[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 --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 local menustyle = core.settings:get("main_menu_style")
28 if menustyle == "auto" then
29         menustyle = PLATFORM == "Android" and "simple" or "full"
30 end
31 defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
32                                         DIR_DELIM .. "pack" .. DIR_DELIM
33
34 dofile(basepath .. "common" .. DIR_DELIM .. "async_event.lua")
35 dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua")
36 dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
37 dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")
38 dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview.lua")
39 dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua")
40 dofile(menupath .. DIR_DELIM .. "common.lua")
41 dofile(menupath .. DIR_DELIM .. "pkgmgr.lua")
42 dofile(menupath .. DIR_DELIM .. "textures.lua")
43
44 dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
45 dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
46 dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua")
47 if menustyle ~= "simple" then
48         dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
49         dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
50         dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
51         dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
52 end
53
54 local tabs = {}
55
56 tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
57 tabs.content  = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
58 tabs.credits  = dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
59 if menustyle == "simple" then
60         tabs.simple_main = dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua")
61 else
62         tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
63         tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
64 end
65
66 --------------------------------------------------------------------------------
67 local function main_event_handler(tabview, event)
68         if event == "MenuQuit" then
69                 core.close()
70         end
71         return true
72 end
73
74 --------------------------------------------------------------------------------
75 local function init_globals()
76         -- Init gamedata
77         gamedata.worldindex = 0
78
79         if menustyle == "simple" then
80                 local world_list = core.get_worlds()
81                 local world_index
82
83                 local found_singleplayerworld = false
84                 for i, world in ipairs(world_list) do
85                         if world.name == "singleplayerworld" then
86                                 found_singleplayerworld = true
87                                 world_index = i
88                                 break
89                         end
90                 end
91
92                 if not found_singleplayerworld then
93                         core.create_world("singleplayerworld", 1)
94
95                         world_list = core.get_worlds()
96
97                         for i, world in ipairs(world_list) do
98                                 if world.name == "singleplayerworld" then
99                                         world_index = i
100                                         break
101                                 end
102                         end
103                 end
104
105                 gamedata.worldindex = world_index
106         else
107                 menudata.worldlist = filterlist.create(
108                         core.get_worlds,
109                         compare_worlds,
110                         -- Unique id comparison function
111                         function(element, uid)
112                                 return element.name == uid
113                         end,
114                         -- Filter function
115                         function(element, gameid)
116                                 return element.gameid == gameid
117                         end
118                 )
119
120                 menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
121                 menudata.worldlist:set_sortmode("alphabetic")
122
123                 if not core.settings:get("menu_last_game") then
124                         local default_game = core.settings:get("default_game") or "minetest"
125                         core.settings:set("menu_last_game", default_game)
126                 end
127
128                 mm_texture.init()
129         end
130
131         -- Create main tabview
132         local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0})
133
134         if menustyle == "simple" then
135                 tv_main:add(tabs.simple_main)
136         else
137                 tv_main:set_autosave_tab(true)
138                 tv_main:add(tabs.local_game)
139                 tv_main:add(tabs.play_online)
140         end
141
142         tv_main:add(tabs.content)
143         tv_main:add(tabs.settings)
144         tv_main:add(tabs.credits)
145
146         tv_main:set_global_event_handler(main_event_handler)
147         tv_main:set_fixed_size(false)
148
149         if menustyle ~= "simple" then
150                 tv_main:set_tab(core.settings:get("maintab_LAST"))
151         end
152         ui.set_default("maintab")
153         tv_main:show()
154
155         ui.update()
156
157         core.sound_play("main_menu", true)
158 end
159
160 init_globals()