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