- // Create the menu clouds
- if (!g_menucloudsmgr)
- g_menucloudsmgr = smgr->createNewSceneManager();
- if (!g_menuclouds)
- g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
- g_menucloudsmgr, -1, rand(), 100);
- g_menuclouds->update(v2f(0, 0), video::SColor(255,200,200,255));
- scene::ICameraSceneNode* camera;
- camera = g_menucloudsmgr->addCameraSceneNode(0,
- v3f(0,0,0), v3f(0, 60, 100));
- camera->setFarValue(10000);
-
- /*
- GUI stuff
- */
-
- ChatBackend chat_backend;
-
- /*
- If an error occurs, this is set to something and the
- menu-game loop is restarted. It is then displayed before
- the menu.
- */
- std::wstring error_message = L"";
-
- // The password entered during the menu screen,
- std::string password;
-
- bool first_loop = true;
-
- /*
- Menu-game loop
- */
- while(device->run() && kill == false)
- {
- // Set the window caption
- wchar_t* text = wgettext("Main Menu");
- device->setWindowCaption((std::wstring(L"Minetest [")+text+L"]").c_str());
- delete[] text;
-
- // This is used for catching disconnects
- try
- {
-
- /*
- Clear everything from the GUIEnvironment
- */
- guienv->clear();
-
- /*
- We need some kind of a root node to be able to add
- custom gui elements directly on the screen.
- Otherwise they won't be automatically drawn.
- */
- guiroot = guienv->addStaticText(L"",
- core::rect<s32>(0, 0, 10000, 10000));
-
- SubgameSpec gamespec;
- WorldSpec worldspec;
- bool simple_singleplayer_mode = false;
-
- // These are set up based on the menu and other things
- std::string current_playername = "inv£lid";
- std::string current_password = "";
- std::string current_address = "does-not-exist";
- int current_port = 0;
-
- /*
- Out-of-game menu loop.
-
- Loop quits when menu returns proper parameters.
- */
- while(kill == false)
- {
- // If skip_main_menu, only go through here once
- if(skip_main_menu && !first_loop){
- kill = true;
- break;
- }
- first_loop = false;
-
- // Cursor can be non-visible when coming from the game
- device->getCursorControl()->setVisible(true);
- // Some stuff are left to scene manager when coming from the game
- // (map at least?)
- smgr->clear();
-
- // Initialize menu data
- MainMenuData menudata;
- menudata.address = address;
- menudata.name = playername;
- menudata.port = itos(port);
- menudata.errormessage = wide_to_narrow(error_message);
- error_message = L"";
- if(cmd_args.exists("password"))
- menudata.password = cmd_args.get("password");
-
- driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
-
- menudata.enable_public = g_settings->getBool("server_announce");
-
- std::vector<WorldSpec> worldspecs = getAvailableWorlds();
-
- // If a world was commanded, append and select it
- if(commanded_world != ""){
-
- std::string gameid = getWorldGameId(commanded_world, true);
- std::string name = _("[--world parameter]");
- if(gameid == ""){
- gameid = g_settings->get("default_game");
- name += " [new]";
- }
- //TODO find within worldspecs and set config
- }
-
- if(skip_main_menu == false)
- {
- video::IVideoDriver* driver = device->getVideoDriver();
-
- infostream<<"Waiting for other menus"<<std::endl;
- while(device->run() && kill == false)
- {
- if(noMenuActive())
- break;
- driver->beginScene(true, true,
- video::SColor(255,128,128,128));
- guienv->drawAll();
- driver->endScene();
- // On some computers framerate doesn't seem to be
- // automatically limited
- sleep_ms(25);
- }
- infostream<<"Waited for other menus"<<std::endl;
-
- GUIEngine* temp = new GUIEngine(device, guiroot, &g_menumgr,smgr,&menudata,kill);
-
- delete temp;
- //once finished you'll never end up here
- smgr->clear();
- }
-
- if(menudata.errormessage != ""){
- error_message = narrow_to_wide(menudata.errormessage);
- continue;
- }
-
- //update worldspecs (necessary as new world may have been created)
- worldspecs = getAvailableWorlds();
-
- if (menudata.name == "")
- menudata.name = std::string("Guest") + itos(myrand_range(1000,9999));
- else
- playername = menudata.name;
-
- password = translatePassword(playername, narrow_to_wide(menudata.password));
- //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
-
- address = menudata.address;
- int newport = stoi(menudata.port);
- if(newport != 0)
- port = newport;
-
- simple_singleplayer_mode = menudata.simple_singleplayer_mode;
-
- // Save settings
- g_settings->set("name", playername);
- g_settings->set("address", address);
- g_settings->set("port", itos(port));
-
- if((menudata.selected_world >= 0) &&
- (menudata.selected_world < worldspecs.size()))
- g_settings->set("selected_world_path",
- worldspecs[menudata.selected_world].path);
-
- // Break out of menu-game loop to shut down cleanly
- if(device->run() == false || kill == true)
- break;
-
- current_playername = playername;
- current_password = password;
- current_address = address;
- current_port = port;
-
- // If using simple singleplayer mode, override
- if(simple_singleplayer_mode){
- current_playername = "singleplayer";
- current_password = "";
- current_address = "";
- current_port = myrand_range(49152, 65535);
- }
- else if (address != "")
- {
- ServerListSpec server;
- server["name"] = menudata.servername;
- server["address"] = menudata.address;
- server["port"] = menudata.port;
- server["description"] = menudata.serverdescription;
- ServerList::insert(server);
- }
-
- // Set world path to selected one
- if ((menudata.selected_world >= 0) &&
- (menudata.selected_world < worldspecs.size())) {
- worldspec = worldspecs[menudata.selected_world];
- infostream<<"Selected world: "<<worldspec.name
- <<" ["<<worldspec.path<<"]"<<std::endl;
- }
-
- // If local game
- if(current_address == "")
- {
- if(menudata.selected_world == -1){
- error_message = wgettext("No world selected and no address "
- "provided. Nothing to do.");
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- // Load gamespec for required game
- gamespec = findWorldSubgame(worldspec.path);
- if(!gamespec.isValid() && !commanded_gamespec.isValid()){
- error_message = wgettext("Could not find or load game \"")
- + narrow_to_wide(worldspec.gameid) + L"\"";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- if(commanded_gamespec.isValid() &&
- commanded_gamespec.id != worldspec.gameid){
- errorstream<<"WARNING: Overriding gamespec from \""
- <<worldspec.gameid<<"\" to \""
- <<commanded_gamespec.id<<"\""<<std::endl;
- gamespec = commanded_gamespec;
- }
-
- if(!gamespec.isValid()){
- error_message = wgettext("Invalid gamespec.");
- error_message += L" (world_gameid="
- +narrow_to_wide(worldspec.gameid)+L")";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- }
-
- // Continue to game
- break;
- }