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")
27 local game, gameidx = nil , 0
29 game, gameidx = pkgmgr.find_by_gameid(gameid)
31 if gameidx == nil then
36 local game_by_gameidx = core.get_game(gameidx)
37 if game_by_gameidx ~= nil then
38 local gamepath = game_by_gameidx.path
39 local gameconfig = Settings(gamepath.."/game.conf")
41 local disallowed_mapgens = (gameconfig:get("disallowed_mapgens") or ""):split()
42 for key, value in pairs(disallowed_mapgens) do
43 disallowed_mapgens[key] = value:trim()
46 if disallowed_mapgens then
47 for i = #mapgens, 1, -1 do
48 if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
49 table.remove(mapgens, i)
58 for k,v in pairs(mapgens) do
59 if current_mg == v then
63 mglist = mglist .. v .. ","
65 mglist = mglist:sub(1, -2)
67 current_seed = core.formspec_escape(current_seed)
69 "size[11.5,6.5,true]" ..
70 "label[2,0;" .. fgettext("World name") .. "]"..
71 "field[4.5,0.4;6,0.5;te_world_name;;" .. minetest.formspec_escape(worldname) .. "]" ..
73 "label[2,1;" .. fgettext("Seed") .. "]"..
74 "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
76 "label[2,2;" .. fgettext("Mapgen") .. "]"..
77 "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
79 "label[2,3;" .. fgettext("Game") .. "]"..
80 "textlist[4.2,3;5.8,2.3;games;" .. pkgmgr.gamelist() ..
81 ";" .. gameidx .. ";true]" ..
83 "button[3.25,6;2.5,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
84 "button[5.75,6;2.5,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
86 if #pkgmgr.games == 0 then
87 retval = retval .. "box[2,4;8,1;#ff8800]label[2.25,4;" ..
88 fgettext("You have no games installed.") .. "]label[2.25,4.4;" ..
89 fgettext("Download one from minetest.net") .. "]"
90 elseif #pkgmgr.games == 1 and pkgmgr.games[1].id == "minimal" then
91 retval = retval .. "box[1.75,4;8.7,1;#ff8800]label[2,4;" ..
92 fgettext("Warning: The minimal development test is meant for developers.") .. "]label[2,4.4;" ..
93 fgettext("Download a game, such as Minetest Game, from minetest.net") .. "]"
100 local function create_world_buttonhandler(this, fields)
102 if fields["world_create_confirm"] or
103 fields["key_enter"] then
105 local worldname = fields["te_world_name"]
106 local gameindex = core.get_textlist_index("games")
108 if gameindex ~= nil then
109 if worldname == "" then
110 local random_number = math.random(10000, 99999)
111 local random_world_name = "Unnamed" .. random_number
112 worldname = random_world_name
116 core.settings:set("fixed_map_seed", fields["te_seed"])
118 if not menudata.worldlist:uid_exists_raw(worldname) then
119 core.settings:set("mg_name",fields["dd_mapgen"])
120 message = core.create_world(worldname,gameindex)
122 message = fgettext("A world named \"$1\" already exists", worldname)
125 if message ~= nil then
126 gamedata.errormessage = message
128 core.settings:set("menu_last_game",pkgmgr.games[gameindex].id)
129 if this.data.update_worldlist_filter then
130 menudata.worldlist:set_filtercriteria(pkgmgr.games[gameindex].id)
131 mm_texture.update("singleplayer", pkgmgr.games[gameindex].id)
133 menudata.worldlist:refresh()
134 core.settings:set("mainmenu_last_selected_world",
135 menudata.worldlist:raw_index_by_uid(worldname))
138 gamedata.errormessage = fgettext("No game selected")
144 worldname = fields.te_world_name
146 if fields["games"] then
147 local gameindex = core.get_textlist_index("games")
148 core.settings:set("menu_last_game", pkgmgr.games[gameindex].id)
152 if fields["world_create_cancel"] then
161 function create_create_world_dlg(update_worldlistfilter)
163 local retval = dialog_create("sp_create_world",
164 create_world_formspec,
165 create_world_buttonhandler,
167 retval.update_worldlist_filter = update_worldlistfilter