From 084be3599a5ef0acba7c341bfd14a4e9801423a2 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 15 Feb 2013 21:13:53 +0200 Subject: Get menu background image from selected game --- src/main.cpp | 215 +++++++++++++++++++++++++---------------------------------- 1 file changed, 89 insertions(+), 126 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index eef65cdb2..67aa82bc4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -612,122 +612,65 @@ private: bool rightreleased; }; -//Draw the tiled menu background -void drawMenuBackground(video::IVideoDriver* driver) { - core::dimension2d screensize = driver->getScreenSize(); - - std::string path = getTexturePath("menubg.png"); - if (path[0]) { - static const video::ITexture *bgtexture = - driver->getTexture(path.c_str()); +void drawMenuBackground(video::IVideoDriver* driver, const SubgameSpec *spec) +{ + v2u32 screensize = driver->getScreenSize(); - if (bgtexture) { - s32 scaledsize = 128; - - // The important difference between destsize and screensize is - // that destsize is rounded to whole scaled pixels. - // These formulas use component-wise multiplication and division of v2u32. - v2u32 texturesize = bgtexture->getSize(); - v2u32 sourcesize = texturesize * screensize / scaledsize + v2u32(1,1); - v2u32 destsize = scaledsize * sourcesize / texturesize; - - // Default texture wrapping mode in Irrlicht is ETC_REPEAT. - driver->draw2DImage(bgtexture, - core::rect(0, 0, destsize.X, destsize.Y), - core::rect(0, 0, sourcesize.X, sourcesize.Y), - NULL, NULL, true); - } + /* Figure out background texture */ + video::ITexture *texture = NULL; + if(spec && spec->menubackground_path != ""){ + texture = driver->getTexture(spec->menubackground_path.c_str()); } -} -//Draw the footer at the bottom of the window -void drawMenuFooter(video::IVideoDriver* driver, bool clouds) { - core::dimension2d screensize = driver->getScreenSize(); - std::string path = getTexturePath(clouds ? - "menufooter_clouds.png" : "menufooter.png"); - if (path[0]) { - static const video::ITexture *footertexture = - driver->getTexture(path.c_str()); - - if (footertexture) { - f32 mult = (((f32)screensize.Width)) / - ((f32)footertexture->getOriginalSize().Width); - - v2s32 footersize(((f32)footertexture->getOriginalSize().Width) * mult, - ((f32)footertexture->getOriginalSize().Height) * mult); - - // Don't draw the footer if there isn't enough room - s32 free_space = (((s32)screensize.Height)-320)/2; - if (free_space > footersize.Y) { - core::rect rect(0,0,footersize.X,footersize.Y); - rect += v2s32(screensize.Width/2,screensize.Height-footersize.Y); - rect -= v2s32(footersize.X/2, 0); - - driver->draw2DImage(footertexture, rect, - core::rect(core::position2d(0,0), - core::dimension2di(footertexture->getSize())), - NULL, NULL, true); - } - } + /* If no texture, draw background of solid color */ + if(!texture){ + video::SColor color(255,80,58,37); + core::rect rect(0, 0, screensize.X, screensize.Y); + driver->draw2DRectangle(color, rect, NULL); + return; } -} - -// Draw the Header over the main menu -void drawMenuHeader(video::IVideoDriver* driver) { - core::dimension2d screensize = driver->getScreenSize(); - - std::string path = getTexturePath("menuheader.png"); - if (path[0]) { - static const video::ITexture *splashtexture = - driver->getTexture(path.c_str()); - - if(splashtexture) { - f32 mult = (((f32)screensize.Width / 2)) / - ((f32)splashtexture->getOriginalSize().Width); - v2s32 splashsize(((f32)splashtexture->getOriginalSize().Width) * mult, - ((f32)splashtexture->getOriginalSize().Height) * mult); - - // Don't draw the header is there isn't enough room - s32 free_space = (((s32)screensize.Height)-320)/2; - if (free_space > splashsize.Y) { - core::rect splashrect(0, 0, splashsize.X, splashsize.Y); - splashrect += v2s32((screensize.Width/2)-(splashsize.X/2), - ((free_space/2)-splashsize.Y/2)+10); + /* Draw background texture */ + v2u32 sourcesize = texture->getSize(); + driver->draw2DImage(texture, + core::rect(0, 0, screensize.X, screensize.Y), + core::rect(0, 0, sourcesize.X, sourcesize.Y), + NULL, NULL, true); +} - video::SColor bgcolor(255,50,50,50); +void drawMenuOverlay(video::IVideoDriver* driver, const SubgameSpec *spec) +{ + v2u32 screensize = driver->getScreenSize(); - driver->draw2DImage(splashtexture, splashrect, - core::rect(core::position2d(0,0), - core::dimension2di(splashtexture->getSize())), - NULL, NULL, true); - } - } + /* Figure out overlay texture */ + video::ITexture *texture = NULL; + if(spec && spec->menuoverlay_path != ""){ + texture = driver->getTexture(spec->menuoverlay_path.c_str()); } -} -// Draw the Splash over the clouds and under the main menu -void drawMenuSplash(video::IVideoDriver* driver) { - core::dimension2d screensize = driver->getScreenSize(); - std::string path = getTexturePath("menusplash.png"); - if (path[0]) { - static const video::ITexture *splashtexture = - driver->getTexture(path.c_str()); + /* If no texture, draw nothing */ + if(!texture) + return; - if(splashtexture) { - core::rect splashrect(0, 0, screensize.Width, screensize.Height); - - video::SColor bgcolor(255,50,50,50); + /* Draw overlay texture */ + v2u32 sourcesize = texture->getSize(); + driver->draw2DImage(texture, + core::rect(0, 0, screensize.X, screensize.Y), + core::rect(0, 0, sourcesize.X, sourcesize.Y), + NULL, NULL, true); +} - driver->draw2DImage(splashtexture, splashrect, - core::rect(core::position2d(0,0), - core::dimension2di(splashtexture->getSize())), - NULL, NULL, true); +static const SubgameSpec* getMenuGame(const MainMenuData &menudata) +{ + for(size_t i=0; igetS32("selected_mainmenu_tab"); if(g_settings->exists("selected_serverlist")) menudata.selected_serverlist = g_settings->getS32("selected_serverlist"); + if(g_settings->exists("selected_mainmenu_game")) + menudata.selected_game = g_settings->get("selected_mainmenu_game"); menudata.address = narrow_to_wide(address); menudata.name = narrow_to_wide(playername); menudata.port = narrow_to_wide(itos(port)); @@ -1611,6 +1556,14 @@ int main(int argc, char *argv[]) } // Copy worldspecs to menu menudata.worlds = worldspecs; + // Get game listing + menudata.games = getAvailableGames(); + // If selected game doesn't exist, take first from list + if(findSubgame(menudata.selected_game).id == "" && + !menudata.games.empty()){ + menudata.selected_game = menudata.games[0].id; + } + const SubgameSpec *menugame = getMenuGame(menudata); if(skip_main_menu == false) { @@ -1623,7 +1576,7 @@ int main(int argc, char *argv[]) break; driver->beginScene(true, true, video::SColor(255,128,128,128)); - drawMenuBackground(driver); + drawMenuBackground(driver, menugame); guienv->drawAll(); driver->endScene(); // On some computers framerate doesn't seem to be @@ -1637,21 +1590,17 @@ int main(int argc, char *argv[]) &g_menumgr, &menudata, g_gamecallback); menu->allowFocusRemoval(true); - // Clouds for the main menu - bool cloud_menu_background = false; - Clouds *clouds = NULL; - if (g_settings->getBool("menu_clouds")) { - cloud_menu_background = true; - 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); - } + // Always create clouds because they may or may not be + // needed based on the game selected + 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); if(error_message != L"") { @@ -1675,6 +1624,24 @@ int main(int argc, char *argv[]) if(menu->getStatus() == true) break; + // Game can be selected in the menu + menugame = getMenuGame(menudata); + // Clouds for the main menu + bool cloud_menu_background = g_settings->getBool("menu_clouds"); + if(menugame){ + // If game has regular background and no overlay, don't use clouds + if(cloud_menu_background && + menugame->menuoverlay_path.empty() && + !menugame->menubackground_path.empty()){ + cloud_menu_background = false; + } + // If game game has overlay and no regular background, always draw clouds + else if(menugame->menubackground_path.empty() && + !menugame->menuoverlay_path.empty()){ + cloud_menu_background = true; + } + } + // Time calc for the clouds f32 dtime; // in seconds if (cloud_menu_background) { @@ -1694,12 +1661,9 @@ int main(int argc, char *argv[]) clouds->step(dtime*3); clouds->render(); smgr->drawAll(); - drawMenuSplash(driver); - drawMenuFooter(driver, true); - drawMenuHeader(driver); + drawMenuOverlay(driver, menugame); } else { - drawMenuBackground(driver); - drawMenuFooter(driver, false); + drawMenuBackground(driver, menugame); } guienv->drawAll(); @@ -1735,10 +1699,8 @@ int main(int argc, char *argv[]) infostream<<"Dropping main menu"<drop(); - if (cloud_menu_background) { - clouds->drop(); - smgr->clear(); - } + clouds->drop(); + smgr->clear(); } playername = wide_to_narrow(menudata.name); @@ -1755,6 +1717,7 @@ int main(int argc, char *argv[]) // Save settings g_settings->setS32("selected_mainmenu_tab", menudata.selected_tab); g_settings->setS32("selected_serverlist", menudata.selected_serverlist); + g_settings->set("selected_mainmenu_game", menudata.selected_game); g_settings->set("new_style_leaves", itos(menudata.fancy_trees)); g_settings->set("smooth_lighting", itos(menudata.smooth_lighting)); g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d)); -- cgit v1.2.3