Skip to content

Commit a225efa

Browse files
committedJul 3, 2013
Lua main menu: Fix crash on init lua error, mapgen dropdown index, and new worlds not saving index
1 parent ad4c065 commit a225efa

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed
 

‎builtin/mainmenu.lua

+22-10
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,30 @@ end
437437

438438
--------------------------------------------------------------------------------
439439
function tabbuilder.dialog_create_world()
440+
local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
441+
442+
local current_mg = engine.setting_get("mg_name")
443+
444+
local mglist = ""
445+
local selindex = 1
446+
local i = 1
447+
for k,v in pairs(mapgens) do
448+
if current_mg == v then
449+
selindex = i
450+
end
451+
i = i + 1
452+
mglist = mglist .. v .. ","
453+
end
454+
mglist = mglist:sub(1, -2)
455+
440456
local retval =
441457
"label[2,0;World name]"..
442458
"label[2,1;Mapgen]"..
443459
"field[4.5,0.4;6,0.5;te_world_name;;]" ..
444460
"label[2,2;Game]"..
445461
"button[5,4.5;2.6,0.5;world_create_confirm;Create]" ..
446462
"button[7.5,4.5;2.8,0.5;world_create_cancel;Cancel]" ..
447-
"dropdown[4.2,1;6.3;dd_mapgen;v6,v7,indev,singlenode,math;1]" .. --TODO read from minetest
463+
"dropdown[4.2,1;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
448464
"textlist[4.2,1.9;5.8,2.3;games;" ..
449465
gamemgr.gamelist() ..
450466
";" .. menu.last_game .. ";true]"
@@ -534,16 +550,12 @@ function tabbuilder.handle_create_world_buttons(fields)
534550
for i=1,#worldlist,1 do
535551
if worldlist[i].name == worldname then
536552
index = i
537-
print("found new world index: " .. index)
538553
break
539554
end
540555
end
541-
542-
if tabbuilder.current_tab == "singleplayer" then
543-
engine.setting_set("main_menu_singleplayer_world_idx",index)
544-
else
545-
menu.last_world = index
546-
end
556+
557+
engine.setting_set("main_menu_singleplayer_world_idx", index)
558+
menu.last_world = index
547559
end
548560
else
549561
gamedata.errormessage = "No worldname given or no game selected"
@@ -805,7 +817,7 @@ function tabbuilder.handle_singleplayer_buttons(fields)
805817
if selected > 0 then
806818
gamedata.selected_world = menu.filtered_index_to_plain(selected)
807819
gamedata.singleplayer = true
808-
820+
809821
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
810822
engine.setting_set("main_menu_singleplayer_world_idx",selected)
811823

@@ -1023,7 +1035,7 @@ end
10231035
--------------------------------------------------------------------------------
10241036
function tabbuilder.tab_singleplayer()
10251037
local index = engine.setting_get("main_menu_singleplayer_world_idx")
1026-
1038+
10271039
if index == nil then
10281040
index = 0
10291041
end

‎src/guiEngine.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ GUIEngine::~GUIEngine()
299299
{
300300
video::IVideoDriver* driver = m_device->getVideoDriver();
301301
assert(driver != 0);
302+
303+
//TODO: clean up m_menu here
302304

303305
lua_close(m_engineluastack);
304306

@@ -309,8 +311,9 @@ GUIEngine::~GUIEngine()
309311
if (m_textures[i] != 0)
310312
driver->removeTexture(m_textures[i]);
311313
}
312-
313-
m_cloud.clouds->drop();
314+
315+
if (m_cloud.clouds)
316+
m_cloud.clouds->drop();
314317
}
315318

316319
/******************************************************************************/

0 commit comments

Comments
 (0)
Please sign in to comment.