- /*
- Create device and exit if creation failed
- */
-
- MyEventReceiver receiver;
-
- IrrlichtDevice *device;
- device = createDevice(driverType,
- core::dimension2d<u32>(screenW, screenH),
- 16, fullscreen, false, false, &receiver);
-
- if (device == 0)
- return 1; // could not create selected driver.
-
- /*
- Continue initialization
- */
-
- video::IVideoDriver* driver = device->getVideoDriver();
-
- // Disable mipmaps (because some of them look ugly)
- driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
-
- /*
- This changes the minimum allowed number of vertices in a VBO.
- Default is 500.
- */
- //driver->setMinHardwareBufferVertexCount(50);
-
- // Create time getter
- g_timegetter = new IrrlichtTimeGetter(device);
-
- // Create game callback for menus
- g_gamecallback = new MainGameCallback(device);
-
- /*
- Speed tests (done after irrlicht is loaded to get timer)
- */
- if(cmd_args.getFlag("speedtests"))
- {
- dstream<<"Running speed tests"<<std::endl;
- SpeedTests();
- return 0;
- }
-
- device->setResizable(true);
-
- bool random_input = g_settings->getBool("random_input")
- || cmd_args.getFlag("random-input");
- InputHandler *input = NULL;
- if(random_input)
- input = new RandomInputHandler();
- else
- input = new RealInputHandler(device, &receiver);
-
- scene::ISceneManager* smgr = device->getSceneManager();
-
- guienv = device->getGUIEnvironment();
- gui::IGUISkin* skin = guienv->getSkin();
- gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());
- if(font)
- skin->setFont(font);
- else
- errorstream<<"WARNING: Font file was not found."
- " Using default font."<<std::endl;
- // If font was not found, this will get us one
- font = skin->getFont();
- assert(font);
-
- u32 text_height = font->getDimension(L"Hello, world!").Height;
- infostream<<"text_height="<<text_height<<std::endl;
-
- //skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
- skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255));
- //skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(0,0,0,0));
- //skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(0,0,0,0));
- skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));
- skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
- skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255,70,100,50));
- skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255,255,255,255));
-
- /*
- 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
- device->setWindowCaption(L"Minetest [Main Menu]");
-
- // 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;
-
- /*
- 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 = narrow_to_wide(address);
- menudata.name = narrow_to_wide(playername);
- menudata.port = narrow_to_wide(itos(port));
- if(cmd_args.exists("password"))
- menudata.password = narrow_to_wide(cmd_args.get("password"));
- menudata.fancy_trees = g_settings->getBool("new_style_leaves");
- menudata.smooth_lighting = g_settings->getBool("smooth_lighting");
- menudata.clouds_3d = g_settings->getBool("enable_3d_clouds");
- menudata.opaque_water = g_settings->getBool("opaque_water");
- menudata.creative_mode = g_settings->getBool("creative_mode");
- menudata.enable_damage = g_settings->getBool("enable_damage");
- // Get world listing for the menu
- std::vector<WorldSpec> worldspecs = getAvailableWorlds();
- for(std::vector<WorldSpec>::const_iterator i = worldspecs.begin();
- i != worldspecs.end(); i++)
- menudata.worlds.push_back(narrow_to_wide(
- i->name + " [" + i->gameid + "]"));
- // Select if there is only one
- if(worldspecs.size() == 1)
- menudata.selected_world = 0;
- else
- menudata.selected_world = -1;
- // If a world was commanded, append and select it
- if(commanded_world != ""){
- std::string gameid = getWorldGameId(commanded_world, true);
- if(gameid == "")
- gameid = g_settings->get("default_game");
- WorldSpec spec(commanded_world, "[commanded world]", gameid);
- worldspecs.push_back(spec);
- menudata.worlds.push_back(narrow_to_wide(spec.name)
- +L" ["+narrow_to_wide(spec.gameid)+L"]");
- menudata.selected_world = menudata.worlds.size()-1;
- }
-
- if(skip_main_menu == false)
- {
- GUIMainMenu *menu =
- new GUIMainMenu(guienv, guiroot, -1,
- &g_menumgr, &menudata, g_gamecallback);
- menu->allowFocusRemoval(true);
-
- if(error_message != L"")
- {
- verbosestream<<"error_message = "
- <<wide_to_narrow(error_message)<<std::endl;
-
- GUIMessageMenu *menu2 =
- new GUIMessageMenu(guienv, guiroot, -1,
- &g_menumgr, error_message.c_str());
- menu2->drop();
- error_message = L"";
- }
-
- video::IVideoDriver* driver = device->getVideoDriver();
-
- infostream<<"Created main menu"<<std::endl;
-
- while(device->run() && kill == false)
- {
- if(menu->getStatus() == true)
- break;
-
- //driver->beginScene(true, true, video::SColor(255,0,0,0));
- driver->beginScene(true, true, video::SColor(255,128,128,128));
-
- drawMenuBackground(driver);
-
- guienv->drawAll();
-
- driver->endScene();
-
- // On some computers framerate doesn't seem to be
- // automatically limited
- sleep_ms(25);
- }
-
- // Break out of menu-game loop to shut down cleanly
- if(device->run() == false || kill == true)
- break;
-
- infostream<<"Dropping main menu"<<std::endl;
-
- menu->drop();
- }
-
- // Set world path to selected one
- if(menudata.selected_world != -1){
- worldspec = worldspecs[menudata.selected_world];
- infostream<<"Selected world: "<<worldspec.name
- <<" ["<<worldspec.path<<"]"<<std::endl;
- }
-
- // Delete map if requested
- if(menudata.delete_world)
- {
- if(menudata.selected_world == -1){
- error_message = L"Cannot delete world: "
- L"no world selected";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- /*bool r = fs::RecursiveDeleteContent(worldspec.path);
- if(r == false){
- error_message = L"World delete failed";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- }*/
- // TODO: Some kind of a yes/no dialog is needed.
- error_message = L"This doesn't do anything currently.";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
-
- playername = wide_to_narrow(menudata.name);
- password = translatePassword(playername, menudata.password);
- //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
-
- address = wide_to_narrow(menudata.address);
- int newport = stoi(wide_to_narrow(menudata.port));
- if(newport != 0)
- port = newport;
- // Save settings
- g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
- g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
- g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));
- g_settings->set("opaque_water", itos(menudata.opaque_water));
- g_settings->set("creative_mode", itos(menudata.creative_mode));
- g_settings->set("enable_damage", itos(menudata.enable_damage));
- g_settings->set("name", playername);
- g_settings->set("address", address);
- g_settings->set("port", itos(port));
- // Update configuration file
- if(configpath != "")
- g_settings->updateConfigFile(configpath.c_str());
-
- // If local game
- if(address == "")
- {
- if(menudata.selected_world == -1){
- error_message = L"No world selected and no address "
- L"provided. Nothing to do.";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- // Load gamespec for required game
- gamespec = findSubgame(worldspec.gameid);
- if(!gamespec.isValid() && !commanded_gamespec.isValid()){
- error_message = L"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 = L"Invalid gamespec. (world_gameid="
- +narrow_to_wide(worldspec.gameid)+L")";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- }
-
- // Continue to game
- break;