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