Skip to content

Commit 2e89209

Browse files
committedNov 5, 2013
Add seed entry to world creation dialog
1 parent e46c527 commit 2e89209

File tree

1 file changed

+87
-89
lines changed

1 file changed

+87
-89
lines changed
 

‎builtin/mainmenu.lua

+87-89
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,22 @@ function init_globals()
142142

143143
filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
144144
filterlist.set_sortmode(worldlist,"alphabetic")
145-
146145
end
147146

148147
--------------------------------------------------------------------------------
149148
function update_menu()
150149

151-
local formspec = "size[12,5.2]"
150+
local formspec
152151

153152
-- handle errors
154153
if gamedata.errormessage ~= nil then
155-
formspec = formspec ..
154+
formspec = "size[12,5.2]" ..
156155
"field[1,2;10,2;;ERROR: " ..
157156
gamedata.errormessage ..
158157
";]"..
159158
"button[4.5,4.2;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
160159
else
161-
formspec = formspec .. tabbuilder.gettab()
160+
formspec = tabbuilder.gettab()
162161
end
163162

164163
engine.update_formspec(formspec)
@@ -279,7 +278,8 @@ end
279278
function tabbuilder.dialog_create_world()
280279
local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
281280

282-
local current_mg = engine.setting_get("mg_name")
281+
local current_seed = engine.setting_get("fixed_map_seed") or ""
282+
local current_mg = engine.setting_get("mg_name")
283283

284284
local mglist = ""
285285
local selindex = 1
@@ -295,15 +295,20 @@ function tabbuilder.dialog_create_world()
295295

296296
local retval =
297297
"label[2,0;" .. fgettext("World name") .. "]"..
298-
"label[2,1;" .. fgettext("Mapgen") .. "]"..
299298
"field[4.5,0.4;6,0.5;te_world_name;;]" ..
300-
"label[2,2;" .. fgettext("Game") .. "]"..
301-
"button[5,4.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
302-
"button[7.5,4.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]" ..
303-
"dropdown[4.2,1;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
304-
"textlist[4.2,1.9;5.8,2.3;games;" ..
305-
gamemgr.gamelist() ..
306-
";" .. menu.last_game .. ";true]"
299+
300+
"label[2,1;" .. fgettext("Seed") .. "]"..
301+
"field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
302+
303+
"label[2,2;" .. fgettext("Mapgen") .. "]"..
304+
"dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
305+
306+
"label[2,3;" .. fgettext("Game") .. "]"..
307+
"textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
308+
";" .. menu.last_game .. ";true]" ..
309+
310+
"button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
311+
"button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
307312

308313
return retval
309314
end
@@ -317,43 +322,18 @@ function tabbuilder.dialog_delete_world()
317322
end
318323

319324
--------------------------------------------------------------------------------
325+
320326
function tabbuilder.gettab()
321-
local retval = ""
322-
327+
local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
328+
local retval = "size[" .. tsize.width .. "," .. tsize.height .. "]"
329+
323330
if tabbuilder.show_buttons then
324331
retval = retval .. tabbuilder.tab_header()
325332
end
326333

327-
if tabbuilder.current_tab == "singleplayer" then
328-
retval = retval .. tabbuilder.tab_singleplayer()
329-
end
330-
331-
if tabbuilder.current_tab == "multiplayer" then
332-
retval = retval .. tabbuilder.tab_multiplayer()
333-
end
334-
335-
if tabbuilder.current_tab == "server" then
336-
retval = retval .. tabbuilder.tab_server()
337-
end
338-
339-
if tabbuilder.current_tab == "settings" then
340-
retval = retval .. tabbuilder.tab_settings()
341-
end
342-
343-
if tabbuilder.current_tab == "texture_packs" then
344-
retval = retval .. tabbuilder.tab_texture_packs()
345-
end
346-
347-
if tabbuilder.current_tab == "credits" then
348-
retval = retval .. tabbuilder.tab_credits()
349-
end
350-
351-
if tabbuilder.current_tab == "dialog_create_world" then
352-
retval = retval .. tabbuilder.dialog_create_world()
353-
end
354-
355-
if tabbuilder.current_tab == "dialog_delete_world" then
356-
retval = retval .. tabbuilder.dialog_delete_world()
334+
local buildfunc = tabbuilder.tabfuncs[tabbuilder.current_tab]
335+
if buildfunc ~= nil then
336+
retval = retval .. buildfunc()
357337
end
358338

359339
retval = retval .. modmgr.gettab(tabbuilder.current_tab)
@@ -383,6 +363,8 @@ function tabbuilder.handle_create_world_buttons(fields)
383363
else
384364
message = fgettext("A world named \"$1\" already exists", worldname)
385365
end
366+
367+
engine.setting_set("fixed_map_seed", fields["te_seed"])
386368

387369
if message ~= nil then
388370
gamedata.errormessage = message
@@ -824,50 +806,6 @@ function tabbuilder.handle_tab_buttons(fields)
824806
tabbuilder.old_tab = tabbuilder.current_tab
825807
end
826808

827-
--------------------------------------------------------------------------------
828-
function tabbuilder.init()
829-
tabbuilder.current_tab = engine.setting_get("main_menu_tab")
830-
831-
if tabbuilder.current_tab == nil or
832-
tabbuilder.current_tab == "" then
833-
tabbuilder.current_tab = "singleplayer"
834-
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
835-
end
836-
837-
--initialize tab buttons
838-
tabbuilder.last_tab = nil
839-
tabbuilder.show_buttons = true
840-
841-
tabbuilder.current_buttons = {}
842-
table.insert(tabbuilder.current_buttons,{name="singleplayer", caption=fgettext("Singleplayer")})
843-
table.insert(tabbuilder.current_buttons,{name="multiplayer", caption=fgettext("Client")})
844-
table.insert(tabbuilder.current_buttons,{name="server", caption=fgettext("Server")})
845-
table.insert(tabbuilder.current_buttons,{name="settings", caption=fgettext("Settings")})
846-
table.insert(tabbuilder.current_buttons,{name="texture_packs", caption=fgettext("Texture Packs")})
847-
848-
if engine.setting_getbool("main_menu_game_mgr") then
849-
table.insert(tabbuilder.current_buttons,{name="game_mgr", caption=fgettext("Games")})
850-
end
851-
852-
if engine.setting_getbool("main_menu_mod_mgr") then
853-
table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption=fgettext("Mods")})
854-
end
855-
table.insert(tabbuilder.current_buttons,{name="credits", caption=fgettext("Credits")})
856-
857-
858-
for i=1,#tabbuilder.current_buttons,1 do
859-
if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
860-
tabbuilder.last_tab_index = i
861-
end
862-
end
863-
864-
if tabbuilder.current_tab ~= "singleplayer" then
865-
menu.update_gametype(true)
866-
else
867-
menu.update_gametype()
868-
end
869-
end
870-
871809
--------------------------------------------------------------------------------
872810
function tabbuilder.tab_multiplayer()
873811

@@ -1091,6 +1029,66 @@ function tabbuilder.tab_credits()
10911029
";0;true]"
10921030
end
10931031

1032+
--------------------------------------------------------------------------------
1033+
function tabbuilder.init()
1034+
tabbuilder.tabfuncs = {
1035+
singleplayer = tabbuilder.tab_singleplayer,
1036+
multiplayer = tabbuilder.tab_multiplayer,
1037+
server = tabbuilder.tab_server,
1038+
settings = tabbuilder.tab_settings,
1039+
texture_packs = tabbuilder.tab_texture_packs,
1040+
credits = tabbuilder.tab_credits,
1041+
dialog_create_world = tabbuilder.dialog_create_world,
1042+
dialog_delete_world = tabbuilder.dialog_delete_world
1043+
}
1044+
1045+
tabbuilder.tabsizes = {
1046+
dialog_create_world = {width=12, height=7},
1047+
dialog_delete_world = {width=12, height=5.2}
1048+
}
1049+
1050+
tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1051+
1052+
if tabbuilder.current_tab == nil or
1053+
tabbuilder.current_tab == "" then
1054+
tabbuilder.current_tab = "singleplayer"
1055+
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1056+
end
1057+
1058+
--initialize tab buttons
1059+
tabbuilder.last_tab = nil
1060+
tabbuilder.show_buttons = true
1061+
1062+
tabbuilder.current_buttons = {}
1063+
table.insert(tabbuilder.current_buttons,{name="singleplayer", caption=fgettext("Singleplayer")})
1064+
table.insert(tabbuilder.current_buttons,{name="multiplayer", caption=fgettext("Client")})
1065+
table.insert(tabbuilder.current_buttons,{name="server", caption=fgettext("Server")})
1066+
table.insert(tabbuilder.current_buttons,{name="settings", caption=fgettext("Settings")})
1067+
table.insert(tabbuilder.current_buttons,{name="texture_packs", caption=fgettext("Texture Packs")})
1068+
1069+
if engine.setting_getbool("main_menu_game_mgr") then
1070+
table.insert(tabbuilder.current_buttons,{name="game_mgr", caption=fgettext("Games")})
1071+
end
1072+
1073+
if engine.setting_getbool("main_menu_mod_mgr") then
1074+
table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption=fgettext("Mods")})
1075+
end
1076+
table.insert(tabbuilder.current_buttons,{name="credits", caption=fgettext("Credits")})
1077+
1078+
1079+
for i=1,#tabbuilder.current_buttons,1 do
1080+
if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1081+
tabbuilder.last_tab_index = i
1082+
end
1083+
end
1084+
1085+
if tabbuilder.current_tab ~= "singleplayer" then
1086+
menu.update_gametype(true)
1087+
else
1088+
menu.update_gametype()
1089+
end
1090+
end
1091+
10941092
--------------------------------------------------------------------------------
10951093
function tabbuilder.checkretval(retval)
10961094

0 commit comments

Comments
 (0)
Please sign in to comment.