Add progress bar and clouds to loading screen

This commit is contained in:
Zeg9 2013-05-08 15:03:42 +02:00 committed by Sfan5
parent 7b41f54411
commit 0913287578

@ -395,11 +395,15 @@ PointedThing getPointedThing(Client *client, v3f player_position,
/* /*
Draws a screen with a single text on it. Draws a screen with a single text on it.
Text will be removed when the screen is drawn the next time. Text will be removed when the screen is drawn the next time.
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
With drawsmgr, you can for example draw clouds
*/ */
/*gui::IGUIStaticText **/ /*gui::IGUIStaticText **/
void draw_load_screen(const std::wstring &text, void draw_load_screen(const std::wstring &text,
video::IVideoDriver* driver, gui::IGUIFont* font) IrrlichtDevice* device, gui::IGUIFont* font,
int percent=-1, bool drawsmgr=false)
{ {
video::IVideoDriver* driver = device->getVideoDriver();
v2u32 screensize = driver->getScreenSize(); v2u32 screensize = driver->getScreenSize();
const wchar_t *loadingtext = text.c_str(); const wchar_t *loadingtext = text.c_str();
core::vector2d<u32> textsize_u = font->getDimension(loadingtext); core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
@ -411,7 +415,28 @@ void draw_load_screen(const std::wstring &text,
loadingtext, textrect, false, false); loadingtext, textrect, false, false);
guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
driver->beginScene(true, true, video::SColor(255,0,0,0)); if (drawsmgr)
{
driver->beginScene(true, true, video::SColor(255,140,186,250));
scene::ISceneManager* smgr = device->getSceneManager();
smgr->drawAll();
}
else
driver->beginScene(true, true, video::SColor(255,0,0,0));
if (percent >= 0 && percent <= 100) // draw progress bar
{
core::vector2d<s32> barsize(256,32);
core::rect<s32> barrect(center-barsize/2, center+barsize/2);
driver->draw2DRectangle(video::SColor(255,255,255,255),barrect, NULL); // border
driver->draw2DRectangle(video::SColor(255,0,0,0), core::rect<s32> (
barrect.UpperLeftCorner+1,
barrect.LowerRightCorner-1), NULL); // black inside the bar
driver->draw2DRectangle(video::SColor(255,128,128,128), core::rect<s32> (
barrect.UpperLeftCorner+1,
core::vector2d<s32>(
barrect.LowerRightCorner.X-(barsize.X-1)+percent*(barsize.X-2)/100,
barrect.LowerRightCorner.Y-1)), NULL); // the actual progress
}
guienv->drawAll(); guienv->drawAll();
driver->endScene(); driver->endScene();
@ -882,7 +907,7 @@ void the_game(
Draw "Loading" screen Draw "Loading" screen
*/ */
draw_load_screen(L"Loading...", driver, font); draw_load_screen(L"Loading...", device, font);
// Create texture source // Create texture source
IWritableTextureSource *tsrc = createTextureSource(device); IWritableTextureSource *tsrc = createTextureSource(device);
@ -939,7 +964,7 @@ void the_game(
*/ */
if(address == ""){ if(address == ""){
draw_load_screen(L"Creating server...", driver, font); draw_load_screen(L"Creating server...", device, font);
infostream<<"Creating server"<<std::endl; infostream<<"Creating server"<<std::endl;
server = new Server(map_dir, configpath, gamespec, server = new Server(map_dir, configpath, gamespec,
simple_singleplayer_mode); simple_singleplayer_mode);
@ -952,7 +977,7 @@ void the_game(
Create client Create client
*/ */
draw_load_screen(L"Creating client...", driver, font); draw_load_screen(L"Creating client...", device, font);
infostream<<"Creating client"<<std::endl; infostream<<"Creating client"<<std::endl;
MapDrawControl draw_control; MapDrawControl draw_control;
@ -963,7 +988,7 @@ void the_game(
// Client acts as our GameDef // Client acts as our GameDef
IGameDef *gamedef = &client; IGameDef *gamedef = &client;
draw_load_screen(L"Resolving address...", driver, font); draw_load_screen(L"Resolving address...", device, font);
Address connect_address(0,0,0,0, port); Address connect_address(0,0,0,0, port);
try{ try{
if(address == "") if(address == "")
@ -1028,7 +1053,7 @@ void the_game(
ss<<L"Connecting to server... (press Escape to cancel)\n"; ss<<L"Connecting to server... (press Escape to cancel)\n";
std::wstring animation = L"/-\\|"; std::wstring animation = L"/-\\|";
ss<<animation[(int)(time_counter/0.2)%4]; ss<<animation[(int)(time_counter/0.2)%4];
draw_load_screen(ss.str(), driver, font); draw_load_screen(ss.str(), device, font);
// Delay a bit // Delay a bit
sleep_ms(1000*frametime); sleep_ms(1000*frametime);
@ -1059,6 +1084,23 @@ void the_game(
float frametime = 0.033; float frametime = 0.033;
float time_counter = 0.0; float time_counter = 0.0;
input->clear(); input->clear();
scene::ISceneManager* smgr = device->getSceneManager();
Clouds *clouds = 0;
if (g_settings->getBool("menu_clouds"))
{
// add clouds
clouds = new Clouds(smgr->getRootSceneNode(),
smgr, -1, rand(), 100);
clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
// A camera to see the clouds
scene::ICameraSceneNode* camera;
camera = smgr->addCameraSceneNode(0,
v3f(0,0,0), v3f(0, 60, 100));
camera->setFarValue(10000);
}
while(device->run()) while(device->run())
{ {
// Update client and server // Update client and server
@ -1087,21 +1129,30 @@ void the_game(
// Display status // Display status
std::wostringstream ss; std::wostringstream ss;
ss<<L"Waiting content... (press Escape to cancel)\n"; if (!client.itemdefReceived())
ss << L"Item definitions...";
else if (!client.nodedefReceived())
ss << L"Node definitions...";
else
ss << L"Media (" << (int)(client.mediaReceiveProgress()*100+0.5) << L"%)...";
ss<<(client.itemdefReceived()?L"[X]":L"[ ]"); if (clouds != 0)
ss<<L" Item definitions\n"; {
ss<<(client.nodedefReceived()?L"[X]":L"[ ]"); clouds->step(frametime*3);
ss<<L" Node definitions\n"; clouds->render();
ss<<L"["<<(int)(client.mediaReceiveProgress()*100+0.5)<<L"%] "; }
ss<<L" Media\n";
draw_load_screen(ss.str(), driver, font); draw_load_screen(ss.str(), device, font, client.mediaReceiveProgress()*100+0.5, clouds!=0);
// Delay a bit // Delay a bit
sleep_ms(1000*frametime); sleep_ms(1000*frametime);
time_counter += frametime; time_counter += frametime;
} }
if (clouds != 0)
{
smgr->addToDeletionQueue(clouds);
clouds->drop();
}
} }
if(!got_content){ if(!got_content){
@ -3227,7 +3278,7 @@ void the_game(
*/ */
{ {
/*gui::IGUIStaticText *gui_shuttingdowntext = */ /*gui::IGUIStaticText *gui_shuttingdowntext = */
draw_load_screen(L"Shutting down stuff...", driver, font); draw_load_screen(L"Shutting down stuff...", device, font);
/*driver->beginScene(true, true, video::SColor(255,0,0,0)); /*driver->beginScene(true, true, video::SColor(255,0,0,0));
guienv->drawAll(); guienv->drawAll();
driver->endScene(); driver->endScene();