diff options
author | kilbith <kilbith@users.noreply.github.com> | 2017-03-13 08:07:14 +0100 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-03-13 08:07:14 +0100 |
commit | c9492b4d37c11f35cfdc1558f771eef87fc5c972 (patch) | |
tree | 132b5990267c4780073be91121621fd5e13ccae7 /src | |
parent | 7a4878cd0b563296b3f2718b79dc9af177dd4fd2 (diff) | |
download | minetest-c9492b4d37c11f35cfdc1558f771eef87fc5c972.tar.gz minetest-c9492b4d37c11f35cfdc1558f771eef87fc5c972.tar.bz2 minetest-c9492b4d37c11f35cfdc1558f771eef87fc5c972.zip |
GUI: Allow texture packs to customize the progress bar (#5368)
Diffstat (limited to 'src')
-rw-r--r-- | src/drawscene.cpp | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/src/drawscene.cpp b/src/drawscene.cpp index c4ef3cc51..e3e6301a8 100644 --- a/src/drawscene.cpp +++ b/src/drawscene.cpp @@ -592,30 +592,51 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device, // draw progress bar if ((percent >= 0) && (percent <= 100)) { - std::string gamepath = fs::RemoveRelativePathComponents( - porting::path_share + DIR_DELIM + "textures"); - video::ITexture *progress_img = driver->getTexture( - (gamepath + "/base/pack/progress_bar.png").c_str()); - video::ITexture *progress_img_bg = driver->getTexture( - (gamepath + "/base/pack/progress_bar_bg.png").c_str()); - - 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); - - 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); - - 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); + const std::string &texture_path = g_settings->get("texture_path"); + std::string tp_progress_bar = texture_path + "/progress_bar.png"; + std::string tp_progress_bar_bg = texture_path + "/progress_bar_bg.png"; + + if (!(fs::PathExists(tp_progress_bar) && + fs::PathExists(tp_progress_bar_bg))) { + std::string gamepath = fs::RemoveRelativePathComponents( + porting::path_share + DIR_DELIM + "textures"); + tp_progress_bar = gamepath + "/base/pack/progress_bar.png"; + tp_progress_bar_bg = gamepath + "/base/pack/progress_bar_bg.png"; + } + + video::ITexture *progress_img = + driver->getTexture(tp_progress_bar.c_str()); + video::ITexture *progress_img_bg = + driver->getTexture(tp_progress_bar_bg.c_str()); + + if (progress_img && progress_img_bg) { + const core::dimension2d<u32> &img_size = progress_img_bg->getSize(); + u32 imgW = rangelim(img_size.Width, 200, 600); + u32 imgH = rangelim(img_size.Height, 24, 72); + 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); + + 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); + } } guienv->drawAll(); |