]> git.lizzy.rs Git - minetest.git/blob - builtin/mainmenu/init.lua
Translated using Weblate (Malay (Jawi))
[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  = "#6389FF"
20 mt_color_green = "#72FF63"
21 mt_color_dark_green = "#25C191"
22
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
28
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")
38
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")
47 end
48
49 local tabs = {}
50
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")
56 else
57         tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
58         tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
59 end
60
61 --------------------------------------------------------------------------------
62 local function main_event_handler(tabview, event)
63         if event == "MenuQuit" then
64                 core.close()
65         end
66         return true
67 end
68
69 --------------------------------------------------------------------------------
70 local function init_globals()
71         -- Init gamedata
72         gamedata.worldindex = 0
73
74         if menustyle == "simple" then
75                 local world_list = core.get_worlds()
76                 local world_index
77
78                 local found_singleplayerworld = false
79                 for i, world in ipairs(world_list) do
80                         if world.name == "singleplayerworld" then
81                                 found_singleplayerworld = true
82                                 world_index = i
83                                 break
84                         end
85                 end
86
87                 if not found_singleplayerworld then
88                         core.create_world("singleplayerworld", 1)
89
90                         world_list = core.get_worlds()
91
92                         for i, world in ipairs(world_list) do
93                                 if world.name == "singleplayerworld" then
94                                         world_index = i
95                                         break
96                                 end
97                         end
98                 end
99
100                 gamedata.worldindex = world_index
101         else
102                 menudata.worldlist = filterlist.create(
103                         core.get_worlds,
104                         compare_worlds,
105                         -- Unique id comparison function
106                         function(element, uid)
107                                 return element.name == uid
108                         end,
109                         -- Filter function
110                         function(element, gameid)
111                                 return element.gameid == gameid
112                         end
113                 )
114
115                 menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
116                 menudata.worldlist:set_sortmode("alphabetic")
117
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)
121                 end
122
123                 mm_texture.init()
124         end
125
126         -- Create main tabview
127         local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0})
128
129         if menustyle == "simple" then
130                 tv_main:add(tabs.simple_main)
131         else
132                 tv_main:set_autosave_tab(true)
133                 tv_main:add(tabs.local_game)
134                 tv_main:add(tabs.play_online)
135         end
136
137         tv_main:add(tabs.content)
138         tv_main:add(tabs.settings)
139         tv_main:add(tabs.credits)
140
141         tv_main:set_global_event_handler(main_event_handler)
142         tv_main:set_fixed_size(false)
143
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)
148                 end
149         end
150         ui.set_default("maintab")
151         tv_main:show()
152
153         ui.update()
154
155         core.sound_play("main_menu", true)
156 end
157
158 init_globals()