pretty loading screen

This commit is contained in:
darkrose 2014-09-19 21:38:06 +10:00
parent 617302de75
commit fd2870bc0c
6 changed files with 90 additions and 59 deletions

View File

@ -186,13 +186,6 @@ void content_mapnode_init(bool repeat)
bool opaque_water = g_settings->getBool("opaque_water");
#endif
content_mapnode_circuit(repeat);
content_mapnode_farm(repeat);
content_mapnode_furniture(repeat);
content_mapnode_door(repeat);
content_mapnode_stair(repeat);
content_mapnode_slab(repeat);
content_t i;
ContentFeatures *f = NULL;

View File

@ -44,6 +44,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h"
#include "path.h"
#include "sound.h"
#ifndef SERVER
#include "main.h"
#endif
/*
TODO: Move content-aware stuff to separate file by adding properties
@ -663,31 +666,42 @@ void update_skybox(video::IVideoDriver* driver,
}
/*
Draws a screen with a single text on it.
Draws a screen with logo and text on it.
Text will be removed when the screen is drawn the next time.
*/
/*gui::IGUIStaticText **/
void draw_load_screen(const std::wstring &text,
video::IVideoDriver* driver, gui::IGUIFont* font)
void drawLoadingScreen(video::IVideoDriver* driver, const char* msg)
{
v2u32 screensize = driver->getScreenSize();
const wchar_t *loadingtext = text.c_str();
core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
core::rect<s32> textrect(center - textsize/2, center + textsize/2);
gui::IGUIStaticText *guitext = guienv->addStaticText(
loadingtext, textrect, false, false);
guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
if (driver == NULL)
return;
core::dimension2d<u32> screensize = driver->getScreenSize();
s32 x = (screensize.Width/2);
s32 y = (screensize.Height/2);
driver->beginScene(true, true, video::SColor(255,0,0,0));
guienv->drawAll();
video::ITexture *logotexture = driver->getTexture(getTexturePath("menulogo.png").c_str());
if (logotexture) {
core::rect<s32> rect(x-100,y-90,x+100,y+110);
driver->draw2DImage(logotexture, rect,
core::rect<s32>(core::position2d<s32>(0,0),
core::dimension2di(logotexture->getSize())),
NULL, NULL, true);
}
if (guienv) {
std::wstring m;
if (msg) {
m = narrow_to_wide(msg);
}else{
m = L"Loading";
}
core::dimension2d<u32> textsize = guienv->getSkin()->getFont()->getDimension(m.c_str());
core::rect<s32> rect(x-(textsize.Width/2), y+100, x+textsize.Width, y+100+textsize.Height);
gui::IGUIStaticText *guitext = guienv->addStaticText(m.c_str(),rect);
guienv->drawAll();
guitext->remove();
}
driver->endScene();
guitext->remove();
//return guitext;
}
/* Profiler display */
@ -754,7 +768,8 @@ void the_game(
/*
Draw "Loading" screen
*/
draw_load_screen(L"Loading...", driver, font);
//draw_load_screen(L"Loading...", driver, font);
drawLoadingScreen(driver,"Loading...");
/*
Create server.
@ -762,7 +777,8 @@ void the_game(
*/
SharedPtr<Server> server;
if(address == ""){
draw_load_screen(L"Creating server...", driver, font);
//draw_load_screen(L"Creating server...", driver, font);
drawLoadingScreen(driver,"Creating server...");
infostream<<"Creating server"<<std::endl;
server = new Server(map_dir, configpath);
server->start(port);
@ -772,12 +788,13 @@ void the_game(
Create client
*/
draw_load_screen(L"Creating client...", driver, font);
//draw_load_screen(L"Creating client...", driver, font);
drawLoadingScreen(driver,"Creating client...");
infostream<<"Creating client"<<std::endl;
MapDrawControl draw_control;
Client client(device, playername.c_str(), password, draw_control, sound);
draw_load_screen(L"Resolving address...", driver, font);
drawLoadingScreen(driver,"Resolving address...");
Address connect_address(0,0,0,0, port);
try{
if(address == "")
@ -822,11 +839,12 @@ void the_game(
break;
}
std::wostringstream ss;
ss<<L"Connecting to server... (timeout in ";
std::ostringstream ss;
ss<<"Connecting to server... (timeout in ";
ss<<(int)(10.0 - time_counter + 1.0);
ss<<L" seconds)";
draw_load_screen(ss.str(), driver, font);
ss<<" seconds)";
//draw_load_screen(ss.str(), driver, font);
drawLoadingScreen(driver,ss.str().c_str());
// Update client and server
client.step(0.1);
@ -2440,7 +2458,7 @@ void the_game(
generator and other stuff quits
*/
{
draw_load_screen(L"Shutting down stuff...", driver, font);
drawLoadingScreen(driver,"Shutting down...");
}
}

View File

@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "keycode.h"
void drawLoadingScreen(video::IVideoDriver* driver, const char* msg);
class KeyList : protected core::list<KeyPress>
{
typedef core::list<KeyPress> super;

View File

@ -686,27 +686,6 @@ void drawMenuBackground(video::IVideoDriver* driver)
NULL, NULL, true);
}
}
//video::ITexture *logotexture =
//driver->getTexture(getTexturePath("menulogo.png").c_str());
//if(logotexture)
//{
//v2s32 logosize(logotexture->getOriginalSize().Width,
//logotexture->getOriginalSize().Height);
//video::SColor bgcolor(255,50,50,50);
//core::rect<s32> bgrect(0, screensize.Height-logosize.Y-20,
//screensize.Width, screensize.Height);
//driver->draw2DRectangle(bgcolor, bgrect, NULL);
//core::rect<s32> rect(0,0,logosize.X,logosize.Y);
//rect += v2s32(screensize.Width/2,screensize.Height-10-logosize.Y);
//rect -= v2s32(logosize.X/2, 0);
//driver->draw2DImage(logotexture, rect,
//core::rect<s32>(core::position2d<s32>(0,0),
//core::dimension2di(logotexture->getSize())),
//NULL, NULL, true);
//}
}
class StderrLogOutput: public ILogOutput
@ -915,7 +894,7 @@ int main(int argc, char *argv[])
content_craftitem_init();
content_toolitem_init();
// Initial call with g_texturesource not set.
init_mapnode();
init_mapnode(NULL);
// Must be called before g_texturesource is created
// (for texture atlas making)
init_mineral();
@ -1091,6 +1070,8 @@ int main(int argc, char *argv[])
// Create texture source
g_texturesource = new TextureSource(device);
drawLoadingScreen(driver,NULL);
/*
Speed tests (done after irrlicht is loaded to get timer)
*/
@ -1124,6 +1105,7 @@ int main(int argc, char *argv[])
// If font was not found, this will get us one
font = skin->getFont();
assert(font);
drawLoadingScreen(driver,"Setting Up UI");
u32 text_height = font->getDimension(L"Hello, world!").Height;
infostream<<"text_height="<<text_height<<std::endl;
@ -1146,7 +1128,8 @@ int main(int argc, char *argv[])
Preload some textures and stuff
*/
init_mapnode(); // Second call with g_texturesource set
drawLoadingScreen(driver,"Loading MapNodes");
init_mapnode(driver); // Second call with g_texturesource set
/*
GUI stuff
@ -1330,7 +1313,7 @@ int main(int argc, char *argv[])
break;
// Initialize mapnode again to enable changed graphics settings
init_mapnode();
init_mapnode(driver);
/*
Run game

View File

@ -198,7 +198,13 @@ ContentFeatures & content_features(MapNode &n)
/*
See mapnode.h for description.
*/
#ifndef SERVER
#include "common_irrlicht.h"
#include "game.h"
void init_mapnode(video::IVideoDriver* driver)
#else
void init_mapnode()
#endif
{
bool repeat = false;
if (g_texturesource == NULL) {
@ -263,7 +269,31 @@ void init_mapnode()
/*
Initialize mapnode content
*/
#ifndef SERVER
drawLoadingScreen(driver,"Loading Base MapNodes");
#endif
content_mapnode_init(repeat);
#ifndef SERVER
drawLoadingScreen(driver,"Loading Circuit MapNodes");
#endif
content_mapnode_circuit(repeat);
#ifndef SERVER
drawLoadingScreen(driver,"Loading Farming MapNodes");
#endif
content_mapnode_farm(repeat);
#ifndef SERVER
drawLoadingScreen(driver,"Loading Decorative MapNodes");
#endif
content_mapnode_furniture(repeat);
#ifndef SERVER
drawLoadingScreen(driver,"Loading Interactive MapNodes");
#endif
content_mapnode_door(repeat);
#ifndef SERVER
drawLoadingScreen(driver,"Loading Special MapNodes");
#endif
content_mapnode_stair(repeat);
content_mapnode_slab(repeat);
}
/*

View File

@ -54,7 +54,12 @@ typedef u16 content_t;
Server only calls this once with g_texturesource=NULL.
*/
#ifndef SERVER
#include "common_irrlicht.h"
void init_mapnode(video::IVideoDriver* driver);
#else
void init_mapnode();
#endif
/*
Ignored node.