Improve game loading progress bar

master
MoNTE48 2020-03-09 22:09:35 +01:00
parent bb8d62e5cb
commit a753919454
2 changed files with 58 additions and 41 deletions

View File

@ -617,56 +617,73 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
else
{
driver->beginScene(true, true, video::SColor(255, 0, 0, 0));
video::ITexture *background_image = driver->getTexture((porting::path_share + "/textures/base/bg.png").c_str());
video::ITexture *background_image = tsrc->getTexture("bg.png");
driver->draw2DImage(background_image,
irr::core::rect<s32>(0, 0, screensize.X * 3, screensize.Y * 3),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
}
// draw progress bar
if ((percent >= 0) && (percent <= 100))
{
// rects to be painted with the bar color
const static core::rect<s32> rects[] = {
core::rect<s32>( 8, 11, 16, 53),
core::rect<s32>( 16, 5, 496, 59),
core::rect<s32>(496, 11, 504, 53),
};
static video::ITexture *progress_img_bg = NULL, *progress_img_o = NULL;
if (progress_img_bg == NULL) {
// IMPORTANT: the texture must be scaled to npot2 for Android beforehand
progress_img_bg = driver->getTexture((porting::path_share + "/textures/base/progress_bar_bg.png").c_str());
progress_img_o = driver->getTexture((porting::path_share + "/textures/base/progress_bar_overlay.png").c_str());
}
if ((percent >= 0) && (percent <= 100)) {
video::ITexture *progress_img = tsrc->getTexture("progress_bar.png");
video::ITexture *progress_img_bg = tsrc->getTexture("progress_bar_bg.png");
const core::dimension2d<u32> &img_size = progress_img_bg->getSize();
u32 imgW = MYMAX(208, img_size.Width);
u32 imgH = MYMAX(24, img_size.Height);
v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2);
if (progress_img && progress_img_bg) {
const core::dimension2d<u32> &img_size = progress_img_bg->getSize();
#ifndef __ANDROID__
u32 imgW = rangelim(img_size.Width, 256, 1024);
u32 imgH = rangelim(img_size.Height, 32, 128);
float imgR = 1.0f;
#else
float imgRatio = (float) img_size.Height / img_size.Width;
u32 imgW = screensize.X / 2.2f;
u32 imgH = floor(imgW * imgRatio);
float imgR = (float) (imgW) / img_size.Width;
#endif
v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2);
draw2DImageFilterScaled(
driver, progress_img_bg,
core::rect<s32>(img_pos.X, img_pos.Y, img_pos.X + imgW, img_pos.Y + imgH),
core::rect<s32>(0, 0, img_size.Width, img_size.Height),
0, 0, true);
for (u32 i = 0; i < ARRLEN(rects); i++) {
const s32 clipx = (percent * img_size.Width) / 100;
core::rect<s32> r(
MYMIN(rects[i].UpperLeftCorner.X, clipx), rects[i].UpperLeftCorner.Y,
MYMIN(rects[i].LowerRightCorner.X, clipx), rects[i].LowerRightCorner.Y
);
if (r.getArea() <= 0)
continue;
driver->draw2DRectangle(
video::SColor(255, 255 - percent * 2, percent * 2, 48),
r + img_pos, NULL);
draw2DImageFilterScaled(
driver, progress_img_bg,
core::rect<s32>(img_pos.X,
img_pos.Y,
img_pos.X + imgW,
img_pos.Y + imgH),
core::rect<s32>(0, 0,
img_size.Width,
img_size.Height),
0, 0, true);
// rects to be painted with the bar color
const static core::rect<s32> rects[] = {
core::rect<s32>( 8, 11, 16, 53),
core::rect<s32>( 16, 5, 496, 59),
core::rect<s32>(496, 11, 504, 53),
};
for (const auto & i : rects) {
const s32 clipx = (percent * imgW) / 100;
core::rect<s32> r(
MYMIN(i.UpperLeftCorner.X * imgR, clipx), i.UpperLeftCorner.Y * imgR,
MYMIN(i.LowerRightCorner.X * imgR, clipx), i.LowerRightCorner.Y * imgR
);
if (r.getArea() <= 0)
continue;
driver->draw2DRectangle(
video::SColor(255, 255 - percent * 2, percent * 2, 48),
r + img_pos, nullptr);
}
draw2DImageFilterScaled(
driver, progress_img,
core::rect<s32>(img_pos.X,
img_pos.Y,
img_pos.X + (percent * imgW) / 100,
img_pos.Y + imgH),
core::rect<s32>(0, 0,
(percent * img_size.Width) / 100,
img_size.Height),
0, 0, true);
}
draw2DImageFilterScaled(
driver, progress_img_o,
core::rect<s32>(img_pos.X, img_pos.Y,
img_pos.X + (percent * imgW) / 100, img_pos.Y + imgH),
core::rect<s32>(0, 0, ((percent * img_size.Width) / 100), img_size.Height),
0, 0, true); // the actual progress
}
guienv->drawAll();

View File

Before

Width:  |  Height:  |  Size: 161 B

After

Width:  |  Height:  |  Size: 161 B