Made Progress Bars working

master
sfan5 2012-05-07 19:25:11 +02:00
parent 540f50aa53
commit 4228d5f7ee
4 changed files with 16 additions and 20 deletions

View File

@ -277,6 +277,7 @@ set(minetest_SRCS
filecache.cpp filecache.cpp
tile.cpp tile.cpp
game.cpp game.cpp
IProgressBar.cpp
) )
# Server sources # Server sources

View File

@ -1,11 +1,10 @@
#include "IProgressBar.h" #include "IProgressBar.h"
IProgressBar::IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& rectangle,s32 id,IGUIElement * parent, IGUIFont * font) : IGUIElement(EGUIET_ELEMENT,guienv,parent,id,rectangle) IProgressBar::IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& rectangle,s32 id,IGUIElement * parent) : IGUIElement(EGUIET_ELEMENT,guienv,parent,id,rectangle)
{ {
total = rectangle.LowerRightCorner.X - rectangle.UpperLeftCorner.X; total = rectangle.LowerRightCorner.X - rectangle.UpperLeftCorner.X;
gui = guienv; gui = guienv;
bar = rectangle; bar = rectangle;
textfont = font;
if(parent == 0) if(parent == 0)
guienv->getRootGUIElement()->addChild(this); //Ensure that draw method is called guienv->getRootGUIElement()->addChild(this); //Ensure that draw method is called
@ -14,17 +13,12 @@ IProgressBar::IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& recta
emptycolor.set(255,0,0,0); emptycolor.set(255,0,0,0);
border = bar; border = bar;
this->setProgress(0); this->setProgress(0);
this->setText("");
} }
void IProgressBar::setColors(irr::video::SColor progress,irr::video::SColor filling) void IProgressBar::setColors(irr::video::SColor progress,irr::video::SColor filling)
{ {
fillcolor = progress; fillcolor = progress;
emptycolor = filling; emptycolor = filling;
} }
void setText(std::string s)
{
text = s;
}
void IProgressBar::addBorder(irr::s32 size,irr::video::SColor color) void IProgressBar::addBorder(irr::s32 size,irr::video::SColor color)
{ {
bordercolor = color; bordercolor = color;
@ -54,5 +48,4 @@ void IProgressBar::draw()
vdriver->draw2DRectangle(bordercolor,border); vdriver->draw2DRectangle(bordercolor,border);
vdriver->draw2DRectangle(fillcolor,tofill); vdriver->draw2DRectangle(fillcolor,tofill);
vdriver->draw2DRectangle(emptycolor,empty); vdriver->draw2DRectangle(emptycolor,empty);
textfont->draw(text, position, video::SColor color, false, true, bar)
} }

View File

@ -1,6 +1,7 @@
#ifndef IPROGRESSBAR_HEADER #ifndef IPROGRESSBAR_HEADER
#define IPROGRESSBAR_HEADER #define IPROGRESSBAR_HEADER
#include "common_irrlicht.h" #include "common_irrlicht.h"
#include <string>
using namespace irr; using namespace irr;
using namespace core; using namespace core;
@ -10,7 +11,7 @@ class IProgressBar : public IGUIElement
{ {
public: public:
IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& rectangle,s32 id=-1,IGUIElement * parent=0, IGUIFont * font=0); IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& rectangle,s32 id=-1,IGUIElement * parent=0);
/*Set percentage in positive percentual (0~100). Please note that a call to this function with others values, will set the progress bar to 0.*/ /*Set percentage in positive percentual (0~100). Please note that a call to this function with others values, will set the progress bar to 0.*/
@ -21,9 +22,6 @@ public:
/*Allow you to add a "border" into your bar. You MUST specify the size (of course in pixel) of the border. You can also pass a color parameter (Black by default)*/ /*Allow you to add a "border" into your bar. You MUST specify the size (of course in pixel) of the border. You can also pass a color parameter (Black by default)*/
void addBorder(irr::s32 size,irr::video::SColor color = irr::video::SColor(255,0,0,0)); void addBorder(irr::s32 size,irr::video::SColor color = irr::video::SColor(255,0,0,0));
/*Set the Text of the Progress Bar*/
void setText(std::string s);
virtual void draw(); virtual void draw();
@ -36,13 +34,11 @@ private:
rect<s32> border; //Border rect<s32> border; //Border
rect<s32> tofill; //Percentage indicator rect<s32> tofill; //Percentage indicator
rect<s32> empty; //"Empty" indicator rect<s32> empty; //"Empty" indicator
std::string text; // Text in the Progress Bar
irr::video::SColor fillcolor; irr::video::SColor fillcolor;
irr::video::SColor emptycolor; irr::video::SColor emptycolor;
irr::video::SColor bordercolor; irr::video::SColor bordercolor;
irr::video::IVideoDriver * vdriver; irr::video::IVideoDriver * vdriver;
irr::gui::IGUIFont * textfont;
}; };
#endif #endif

View File

@ -1096,21 +1096,27 @@ void the_game(
ss<<(client.nodedefReceived()?L"[X]":L"[ ]"); ss<<(client.nodedefReceived()?L"[X]":L"[ ]");
ss<<L" Node definitions\n"; ss<<L" Node definitions\n";
//ss<<L"["<<(int)(client.mediaReceiveProgress()*100+0.5)<<L"%] "; //ss<<L"["<<(int)(client.mediaReceiveProgress()*100+0.5)<<L"%] ";
//ss<<L" Media\n"; if((int)(client.mediaReceiveProgress()*100+0.5) > 90) {
ss<<L"[X]";
} else {
ss<<L"[ ]";
}
ss<<L" Media\n";
draw_load_screen(ss.str(), driver, font, false);
v2u32 screensize = driver->getScreenSize(); v2u32 screensize = driver->getScreenSize();
core::vector2d<u32> textsize_u = font->getDimension(ss.str().c_str()); core::vector2d<u32> textsize_u = font->getDimension(ss.str().c_str());
core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y); core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
core::vector2d<s32> center(screensize.X/2, screensize.Y/2); core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
core::rect<s32> progrect(center - textsize/2, (center + textsize/2) + screensize.Y/16); core::rect<s32> progrect(center - textsize/2, center + textsize/2);
IProgressBar * pb = new IProgressBar(guienv,progrect,-1,0,font); IProgressBar * pb = new IProgressBar(guienv,progrect);
pb->setProgress((irr::u32)(client.mediaReceiveProgress()*100+0.5)); pb->setProgress((irr::u32)(client.mediaReceiveProgress()*100+0.5));
pb->addBorder(1); pb->addBorder(2, irr::video::SColor(255,105,105,105));
pb->setText("Media"); pb->setColors(irr::video::SColor(255,19,136,8), irr::video::SColor(255,128,128,128));
pb->drop(); pb->drop();
draw_load_screen(ss.str(), driver, font, false);
driver->endScene(); driver->endScene();
pb->remove();
// Delay a bit // Delay a bit
sleep_ms(1000*frametime); sleep_ms(1000*frametime);