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.
20 local function create_world_formspec(dialogdata)
21 local mapgens = core.get_mapgen_names()
23 local current_seed = core.settings:get("fixed_map_seed") or ""
24 local current_mg = core.settings:get("mg_name")
25 local gameid = core.settings:get("menu_last_game")
30 _, gameidx = pkgmgr.find_by_gameid(gameid)
32 if gameidx == nil then
37 local game_by_gameidx = core.get_game(gameidx)
38 if game_by_gameidx ~= nil then
39 local gamepath = game_by_gameidx.path
40 local gameconfig = Settings(gamepath.."/game.conf")
42 local disallowed_mapgens = (gameconfig:get("disallowed_mapgens") or ""):split()
43 for key, value in pairs(disallowed_mapgens) do
44 disallowed_mapgens[key] = value:trim()
47 if disallowed_mapgens then
48 for i = #mapgens, 1, -1 do
49 if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
50 table.remove(mapgens, i)
59 for k,v in pairs(mapgens) do
60 if current_mg == v then
64 mglist = mglist .. v .. ","
66 mglist = mglist:sub(1, -2)
68 current_seed = core.formspec_escape(current_seed)
70 "size[11.5,6.5,true]" ..
71 "label[2,0;" .. fgettext("World name") .. "]"..
72 "field[4.5,0.4;6,0.5;te_world_name;;" .. minetest.formspec_escape(worldname) .. "]" ..
74 "label[2,1;" .. fgettext("Seed") .. "]"..
75 "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
77 "label[2,2;" .. fgettext("Mapgen") .. "]"..
78 "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
80 "label[2,3;" .. fgettext("Game") .. "]"..
81 "textlist[4.2,3;5.8,2.3;games;" .. pkgmgr.gamelist() ..
82 ";" .. gameidx .. ";true]" ..
84 "button[3.25,6;2.5,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
85 "button[5.75,6;2.5,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
87 if #pkgmgr.games == 0 then
88 retval = retval .. "box[2,4;8,1;#ff8800]label[2.25,4;" ..
89 fgettext("You have no games installed.") .. "]label[2.25,4.4;" ..
90 fgettext("Download one from minetest.net") .. "]"
91 elseif #pkgmgr.games == 1 and pkgmgr.games[1].id == "minimal" then
92 retval = retval .. "box[1.75,4;8.7,1;#ff8800]label[2,4;" ..
93 fgettext("Warning: The minimal development test is meant for developers.") .. "]label[2,4.4;" ..
94 fgettext("Download a game, such as Minetest Game, from minetest.net") .. "]"
101 local function create_world_buttonhandler(this, fields)
103 if fields["world_create_confirm"] or
104 fields["key_enter"] then
106 local worldname = fields["te_world_name"]
107 local gameindex = core.get_textlist_index("games")
109 if gameindex ~= nil then
110 if worldname == "" then
111 local random_number = math.random(10000, 99999)
112 local random_world_name = "Unnamed" .. random_number
113 worldname = random_world_name
116 core.settings:set("fixed_map_seed", fields["te_seed"])
119 if not menudata.worldlist:uid_exists_raw(worldname) then
120 core.settings:set("mg_name",fields["dd_mapgen"])
121 message = core.create_world(worldname,gameindex)
123 message = fgettext("A world named \"$1\" already exists", worldname)
126 if message ~= nil then
127 gamedata.errormessage = message
129 core.settings:set("menu_last_game",pkgmgr.games[gameindex].id)
130 if this.data.update_worldlist_filter then
131 menudata.worldlist:set_filtercriteria(pkgmgr.games[gameindex].id)
132 mm_texture.update("singleplayer", pkgmgr.games[gameindex].id)
134 menudata.worldlist:refresh()
135 core.settings:set("mainmenu_last_selected_world",
136 menudata.worldlist:raw_index_by_uid(worldname))
139 gamedata.errormessage = fgettext("No game selected")
145 worldname = fields.te_world_name
147 if fields["games"] then
148 local gameindex = core.get_textlist_index("games")
149 core.settings:set("menu_last_game", pkgmgr.games[gameindex].id)
153 if fields["world_create_cancel"] then
162 function create_create_world_dlg(update_worldlistfilter)
164 local retval = dialog_create("sp_create_world",
165 create_world_formspec,
166 create_world_buttonhandler,
168 retval.update_worldlist_filter = update_worldlistfilter