2 --Copyright (C) 2014 sapier
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.
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.
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.
18 mt_color_grey = "#AAAAAA"
19 mt_color_blue = "#6389FF"
20 mt_color_green = "#72FF63"
21 mt_color_dark_green = "#25C191"
23 local menupath = core.get_mainmenu_path()
24 local basepath = core.get_builtin_path()
25 local menustyle = core.settings:get("main_menu_style")
26 defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
27 DIR_DELIM .. "pack" .. DIR_DELIM
29 dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua")
30 dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
31 dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")
32 dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview.lua")
33 dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua")
34 dofile(menupath .. DIR_DELIM .. "async_event.lua")
35 dofile(menupath .. DIR_DELIM .. "common.lua")
36 dofile(menupath .. DIR_DELIM .. "pkgmgr.lua")
37 dofile(menupath .. DIR_DELIM .. "textures.lua")
39 dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
40 dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
41 dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua")
42 if menustyle ~= "simple" then
43 dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
44 dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
45 dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
46 dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
51 tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
52 tabs.content = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
53 tabs.credits = dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
54 if menustyle == "simple" then
55 tabs.simple_main = dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua")
57 tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
58 tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
61 --------------------------------------------------------------------------------
62 local function main_event_handler(tabview, event)
63 if event == "MenuQuit" then
69 --------------------------------------------------------------------------------
70 local function init_globals()
72 gamedata.worldindex = 0
74 if menustyle == "simple" then
75 local world_list = core.get_worlds()
78 local found_singleplayerworld = false
79 for i, world in ipairs(world_list) do
80 if world.name == "singleplayerworld" then
81 found_singleplayerworld = true
87 if not found_singleplayerworld then
88 core.create_world("singleplayerworld", 1)
90 world_list = core.get_worlds()
92 for i, world in ipairs(world_list) do
93 if world.name == "singleplayerworld" then
100 gamedata.worldindex = world_index
102 menudata.worldlist = filterlist.create(
105 -- Unique id comparison function
106 function(element, uid)
107 return element.name == uid
110 function(element, gameid)
111 return element.gameid == gameid
115 menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
116 menudata.worldlist:set_sortmode("alphabetic")
118 if not core.settings:get("menu_last_game") then
119 local default_game = core.settings:get("default_game") or "minetest"
120 core.settings:set("menu_last_game", default_game)
126 -- Create main tabview
127 local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0})
129 if menustyle == "simple" then
130 tv_main:add(tabs.simple_main)
132 tv_main:set_autosave_tab(true)
133 tv_main:add(tabs.local_game)
134 tv_main:add(tabs.play_online)
137 tv_main:add(tabs.content)
138 tv_main:add(tabs.settings)
139 tv_main:add(tabs.credits)
141 tv_main:set_global_event_handler(main_event_handler)
142 tv_main:set_fixed_size(false)
144 if menustyle ~= "simple" then
145 local last_tab = core.settings:get("maintab_LAST")
146 if last_tab and tv_main.current_tab ~= last_tab then
147 tv_main:set_tab(last_tab)
150 ui.set_default("maintab")
155 core.sound_play("main_menu", true)