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 From ee8067f7cfa5b25e12a166bd5d306a905630ee92 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 2 May 2013 20:59:52 +0300 Subject: Switch menu to game selected in world creation dialog --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 67aa82bc4..9a646413d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1795,6 +1795,7 @@ int main(int argc, char *argv[]) continue; } g_settings->set("selected_world_path", path); + g_settings->set("selected_mainmenu_game", menudata.create_world_gameid); continue; } -- cgit v1.2.3 From b75505e6b2b82d48980ff71649dd4944b04b6f78 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Thu, 2 May 2013 19:57:03 +0200 Subject: Show game name instead of game ID of selected game --- src/guiMainMenu.cpp | 6 ++++-- src/guiMainMenu.h | 2 ++ src/main.cpp | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index c6142d4ce..5d5ae1e90 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -258,9 +258,9 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, size.X, 40); rect += v2s32(4, 0); std::string t = "Minetest " VERSION_STRING; - if(m_data->selected_game != ""){ + if(m_data->selected_game_name != ""){ t += "/"; - t += m_data->selected_game; + t += m_data->selected_game_name; } Environment->addStaticText(narrow_to_wide(t).c_str(), rect, false, true, this, -1); @@ -1356,6 +1356,8 @@ bool GUIMainMenu::OnEvent(const SEvent& event) eid <= GUI_ID_GAME_BUTTON_MAX){ m_data->selected_game = m_data->games[eid - GUI_ID_GAME_BUTTON_FIRST].id; + m_data->selected_game_name = + m_data->games[eid - GUI_ID_GAME_BUTTON_FIRST].name; regenerateGui(m_screensize_old); } } diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index 1c5ca4d37..1d09c8baa 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -40,6 +40,7 @@ struct MainMenuData // Generic int selected_tab; std::string selected_game; + std::string selected_game_name; // Client options std::string servername; std::string serverdescription; @@ -80,6 +81,7 @@ struct MainMenuData // Generic selected_tab(0), selected_game("minetest"), + selected_game_name("Minetest"), // Client opts fancy_trees(false), smooth_lighting(false), diff --git a/src/main.cpp b/src/main.cpp index 9a646413d..501e4cdf4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1501,8 +1501,10 @@ int main(int argc, char *argv[]) menudata.selected_tab = g_settings->getS32("selected_mainmenu_tab"); if(g_settings->exists("selected_serverlist")) menudata.selected_serverlist = g_settings->getS32("selected_serverlist"); - if(g_settings->exists("selected_mainmenu_game")) + if(g_settings->exists("selected_mainmenu_game")){ menudata.selected_game = g_settings->get("selected_mainmenu_game"); + menudata.selected_game_name = findSubgame(menudata.selected_game).name; + } menudata.address = narrow_to_wide(address); menudata.name = narrow_to_wide(playername); menudata.port = narrow_to_wide(itos(port)); -- cgit v1.2.3 From a888b232fe1315e4922c541f30b214647511bb93 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 4 May 2013 10:03:56 +0300 Subject: Add header.png and footer.png support for games, and support texture packs via _menu_.png --- src/main.cpp | 141 +++++++++++++++++++++++++++++++++++++++++++++++--------- src/subgame.cpp | 6 +-- src/subgame.h | 6 --- 3 files changed, 121 insertions(+), 32 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 501e4cdf4..3cf6728e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -612,15 +612,53 @@ private: bool rightreleased; }; -void drawMenuBackground(video::IVideoDriver* driver, const SubgameSpec *spec) +struct MenuTextures { - v2u32 screensize = driver->getScreenSize(); + std::string current_gameid; + video::ITexture *background; + video::ITexture *overlay; + video::ITexture *header; + video::ITexture *footer; + + MenuTextures(): + background(NULL), + overlay(NULL), + header(NULL), + footer(NULL) + {} - /* Figure out background texture */ - video::ITexture *texture = NULL; - if(spec && spec->menubackground_path != ""){ - texture = driver->getTexture(spec->menubackground_path.c_str()); + static video::ITexture* getMenuTexture(const std::string &tname, + video::IVideoDriver* driver, const SubgameSpec *spec) + { + std::string path; + // eg. minetest_menu_background.png (for texture packs) + std::string pack_tname = spec->id + "_menu_" + tname + ".png"; + path = getTexturePath(pack_tname); + if(path != "") + return driver->getTexture(path.c_str()); + // eg. games/minetest_game/menu/background.png + path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png"); + if(path != "") + return driver->getTexture(path.c_str()); + return NULL; + } + + void update(video::IVideoDriver* driver, const SubgameSpec *spec) + { + if(spec->id == current_gameid) + return; + current_gameid = spec->id; + background = getMenuTexture("background", driver, spec); + overlay = getMenuTexture("overlay", driver, spec); + header = getMenuTexture("header", driver, spec); + footer = getMenuTexture("footer", driver, spec); } +}; + +void drawMenuBackground(video::IVideoDriver* driver, const MenuTextures &menutextures) +{ + v2u32 screensize = driver->getScreenSize(); + video::ITexture *texture = menutextures.background; /* If no texture, draw background of solid color */ if(!texture){ @@ -638,15 +676,10 @@ void drawMenuBackground(video::IVideoDriver* driver, const SubgameSpec *spec) NULL, NULL, true); } -void drawMenuOverlay(video::IVideoDriver* driver, const SubgameSpec *spec) +void drawMenuOverlay(video::IVideoDriver* driver, const MenuTextures &menutextures) { v2u32 screensize = driver->getScreenSize(); - - /* Figure out overlay texture */ - video::ITexture *texture = NULL; - if(spec && spec->menuoverlay_path != ""){ - texture = driver->getTexture(spec->menuoverlay_path.c_str()); - } + video::ITexture *texture = menutextures.overlay; /* If no texture, draw nothing */ if(!texture) @@ -660,6 +693,66 @@ void drawMenuOverlay(video::IVideoDriver* driver, const SubgameSpec *spec) NULL, NULL, true); } +void drawMenuHeader(video::IVideoDriver* driver, const MenuTextures &menutextures) +{ + core::dimension2d screensize = driver->getScreenSize(); + video::ITexture *texture = menutextures.header; + + /* If no texture, draw nothing */ + if(!texture) + return; + + f32 mult = (((f32)screensize.Width / 2)) / + ((f32)texture->getOriginalSize().Width); + + v2s32 splashsize(((f32)texture->getOriginalSize().Width) * mult, + ((f32)texture->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); + + video::SColor bgcolor(255,50,50,50); + + driver->draw2DImage(texture, splashrect, + core::rect(core::position2d(0,0), + core::dimension2di(texture->getSize())), + NULL, NULL, true); + } +} + +void drawMenuFooter(video::IVideoDriver* driver, const MenuTextures &menutextures) +{ + core::dimension2d screensize = driver->getScreenSize(); + video::ITexture *texture = menutextures.footer; + + /* If no texture, draw nothing */ + if(!texture) + return; + + f32 mult = (((f32)screensize.Width)) / + ((f32)texture->getOriginalSize().Width); + + v2s32 footersize(((f32)texture->getOriginalSize().Width) * mult, + ((f32)texture->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(texture, rect, + core::rect(core::position2d(0,0), + core::dimension2di(texture->getSize())), + NULL, NULL, true); + } +} + static const SubgameSpec* getMenuGame(const MainMenuData &menudata) { for(size_t i=0; igetVideoDriver(); @@ -1578,7 +1674,7 @@ int main(int argc, char *argv[]) break; driver->beginScene(true, true, video::SColor(255,128,128,128)); - drawMenuBackground(driver, menugame); + drawMenuBackground(driver, menutextures); guienv->drawAll(); driver->endScene(); // On some computers framerate doesn't seem to be @@ -1628,18 +1724,17 @@ int main(int argc, char *argv[]) // Game can be selected in the menu menugame = getMenuGame(menudata); + menutextures.update(driver, menugame); // 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()){ + if(cloud_menu_background && menutextures.background && + !menutextures.overlay){ 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()){ + else if(menutextures.overlay && !menutextures.background){ cloud_menu_background = true; } } @@ -1663,9 +1758,13 @@ int main(int argc, char *argv[]) clouds->step(dtime*3); clouds->render(); smgr->drawAll(); - drawMenuOverlay(driver, menugame); + drawMenuOverlay(driver, menutextures); + drawMenuHeader(driver, menutextures); + drawMenuFooter(driver, menutextures); } else { - drawMenuBackground(driver, menugame); + drawMenuBackground(driver, menutextures); + drawMenuHeader(driver, menutextures); + drawMenuFooter(driver, menutextures); } guienv->drawAll(); diff --git a/src/subgame.cpp b/src/subgame.cpp index 1bee630b2..cdb546619 100644 --- a/src/subgame.cpp +++ b/src/subgame.cpp @@ -97,16 +97,12 @@ SubgameSpec findSubgame(const std::string &id) std::string game_name = getGameName(game_path); if(game_name == "") game_name = id; - std::string menubackground_path; - std::string menuoverlay_path; std::string menuicon_path; #ifndef SERVER - menubackground_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "background.png"); - menuoverlay_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "overlay.png"); menuicon_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png"); #endif return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name, - menubackground_path, menuoverlay_path, menuicon_path); + menuicon_path); } SubgameSpec findWorldSubgame(const std::string &world_path) diff --git a/src/subgame.h b/src/subgame.h index 2e16c2fec..4b15faa8d 100644 --- a/src/subgame.h +++ b/src/subgame.h @@ -35,8 +35,6 @@ struct SubgameSpec std::string gamemods_path; //path to mods of the game std::set addon_mods_paths; //paths to addon mods for this game std::string name; - std::string menubackground_path; - std::string menuoverlay_path; std::string menuicon_path; SubgameSpec(const std::string &id_="", @@ -44,16 +42,12 @@ struct SubgameSpec const std::string &gamemods_path_="", const std::set &addon_mods_paths_=std::set(), const std::string &name_="", - const std::string &menubackground_path_="", - const std::string &menuoverlay_path_="", const std::string &menuicon_path_=""): id(id_), path(path_), gamemods_path(gamemods_path_), addon_mods_paths(addon_mods_paths_), name(name_), - menubackground_path(menubackground_path_), - menuoverlay_path(menuoverlay_path_), menuicon_path(menuicon_path_) {} -- cgit v1.2.3 From 3332f606ed9d3016bd73bea2fde685df2a52b1c5 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Thu, 9 May 2013 15:48:35 +0200 Subject: Drop IrrlichtDevice when running --speedtests --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 3cf6728e4..f2ff88c0c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1462,6 +1462,7 @@ int main(int argc, char *argv[]) { dstream<<"Running speed tests"<drop(); return 0; } -- cgit v1.2.3 From 3b1c3ac678157a1b7b7c17769499bec53868c9a9 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Thu, 9 May 2013 15:53:29 +0200 Subject: Add --videomodes option to show available video modes --- doc/minetest.6 | 3 +++ src/main.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/doc/minetest.6 b/doc/minetest.6 index b3fdd94d9..64dfdd149 100644 --- a/doc/minetest.6 +++ b/doc/minetest.6 @@ -61,6 +61,9 @@ Run dedicated server \-\-speedtests Run speed tests .TP +\-\-videomodes +List available video modes +.TP \-\-info Print more information to console .TP diff --git a/src/main.cpp b/src/main.cpp index f2ff88c0c..b87a3e6d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -936,6 +936,8 @@ int main(int argc, char *argv[]) allowed_options.insert(std::make_pair("gameid", ValueSpec(VALUETYPE_STRING, _("Set gameid (\"--gameid list\" prints available ones)")))); #ifndef SERVER + allowed_options.insert(std::make_pair("videomodes", ValueSpec(VALUETYPE_FLAG, + _("Show available video modes")))); allowed_options.insert(std::make_pair("speedtests", ValueSpec(VALUETYPE_FLAG, _("Run speed tests")))); allowed_options.insert(std::make_pair("address", ValueSpec(VALUETYPE_STRING, @@ -1035,7 +1037,7 @@ int main(int argc, char *argv[]) print_worldspecs(worldspecs, dstream); return 0; } - + // Print startup message infostream<(640, 480); + params.Bits = 24; + params.AntiAlias = fsaa; + params.Fullscreen = false; + params.Stencilbuffer = false; + params.Vsync = vsync; + params.EventReceiver = &receiver; + + nulldevice = createDeviceEx(params); + + if(nulldevice == 0) + return 1; + + dstream<<_("Available video modes (WxHxD):")<getVideoModeList(); + + if(videomode_list == 0){ + nulldevice->drop(); + return 1; + } + + s32 videomode_count = videomode_list->getVideoModeCount(); + core::dimension2d videomode_res; + s32 videomode_depth; + for (s32 i = 0; i < videomode_count; ++i){ + videomode_res = videomode_list->getVideoModeResolution(i); + videomode_depth = videomode_list->getVideoModeDepth(i); + dstream<getDesktopResolution(); + videomode_depth = videomode_list->getDesktopDepth(); + dstream<drop(); + + return 0; + } + + /* + Create device and exit if creation failed + */ + IrrlichtDevice *device; SIrrlichtCreationParameters params = SIrrlichtCreationParameters(); -- cgit v1.2.3 From 81c863ac4df1530123ef7952713623dadb049bec Mon Sep 17 00:00:00 2001 From: Zeg9 Date: Thu, 9 May 2013 18:23:48 +0200 Subject: Add clouds to all loading screens and better progress handling --- src/game.cpp | 188 ++++++++++++++++++++++++++++++++++++++++------------------- src/main.cpp | 44 ++++++++------ src/main.h | 8 +++ 3 files changed, 161 insertions(+), 79 deletions(-) (limited to 'src/main.cpp') diff --git a/src/game.cpp b/src/game.cpp index 61e4963c0..81f35d4c0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -396,12 +396,11 @@ PointedThing getPointedThing(Client *client, v3f player_position, Draws a screen with a single text on it. Text will be removed when the screen is drawn the next time. Additionally, a progressbar can be drawn when percent is set between 0 and 100. - With drawsmgr, you can for example draw clouds */ /*gui::IGUIStaticText **/ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device, gui::IGUIFont* font, - int percent=-1, bool drawsmgr=false) + float dtime=0 ,int percent=0, bool clouds=true) { video::IVideoDriver* driver = device->getVideoDriver(); v2u32 screensize = driver->getScreenSize(); @@ -415,11 +414,13 @@ void draw_load_screen(const std::wstring &text, loadingtext, textrect, false, false); guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); - if (drawsmgr) + bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds"); + if (cloud_menu_background) { + g_menuclouds->step(dtime*3); + g_menuclouds->render(); driver->beginScene(true, true, video::SColor(255,140,186,250)); - scene::ISceneManager* smgr = device->getSceneManager(); - smgr->drawAll(); + g_menucloudsmgr->drawAll(); } else driver->beginScene(true, true, video::SColor(255,0,0,0)); @@ -428,7 +429,7 @@ void draw_load_screen(const std::wstring &text, core::vector2d barsize(256,32); core::rect barrect(center-barsize/2, center+barsize/2); driver->draw2DRectangle(video::SColor(255,255,255,255),barrect, NULL); // border - driver->draw2DRectangle(video::SColor(255,0,0,0), core::rect ( + driver->draw2DRectangle(video::SColor(255,64,64,64), core::rect ( barrect.UpperLeftCorner+1, barrect.LowerRightCorner-1), NULL); // black inside the bar driver->draw2DRectangle(video::SColor(255,128,128,128), core::rect ( @@ -907,7 +908,11 @@ void the_game( Draw "Loading" screen */ - draw_load_screen(L"Loading...", device, font); + { + wchar_t* text = wgettext("Loading..."); + draw_load_screen(text, device, font,0,0); + delete[] text; + } // Create texture source IWritableTextureSource *tsrc = createTextureSource(device); @@ -964,7 +969,9 @@ void the_game( */ if(address == ""){ - draw_load_screen(L"Creating server...", device, font); + wchar_t* text = wgettext("Creating server...."); + draw_load_screen(text, device, font,0,25); + delete[] text; infostream<<"Creating server"<clear(); + float fps_max = g_settings->getFloat("fps_max"); + bool cloud_menu_background = g_settings->getBool("menu_clouds"); + u32 lasttime = device->getTimer()->getTime(); while(device->run()) { + f32 dtime=0; // in seconds + if (cloud_menu_background) { + u32 time = device->getTimer()->getTime(); + if(time > lasttime) + dtime = (time - lasttime) / 1000.0; + else + dtime = 0; + lasttime = time; + } // Update client and server - client.step(frametime); + client.step(dtime); if(server != NULL) - server->step(frametime); + server->step(dtime); // End condition if(client.connectedAndInitialized()){ @@ -1049,15 +1075,37 @@ void the_game( } // Display status - std::wostringstream ss; - ss<getTimer()->getTime(); + if(time > lasttime) + busytime_u32 = time - lasttime; + else + busytime_u32 = 0; + busytime = busytime_u32 / 1000.0; + + // FPS limiter + u32 frametime_min = 1000./fps_max; + + if(busytime_u32 < frametime_min) { + u32 sleeptime = frametime_min - busytime_u32; + device->sleep(sleeptime); + } + } else { + sleep_ms(25); + } + time_counter += dtime; } } catch(con::PeerNotFoundException &e) @@ -1081,32 +1129,26 @@ void the_game( bool got_content = false; bool content_aborted = false; { - float frametime = 0.033; float time_counter = 0.0; input->clear(); - - scene::ISceneManager* smgr = device->getSceneManager(); - Clouds *clouds = 0; - if (g_settings->getBool("menu_clouds")) - { - // add 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); - } - + float fps_max = g_settings->getFloat("fps_max"); + bool cloud_menu_background = g_settings->getBool("menu_clouds"); + u32 lasttime = device->getTimer()->getTime(); while(device->run()) { + f32 dtime=0; // in seconds + if (cloud_menu_background) { + u32 time = device->getTimer()->getTime(); + if(time > lasttime) + dtime = (time - lasttime) / 1000.0; + else + dtime = 0; + lasttime = time; + } // Update client and server - client.step(frametime); + client.step(dtime); if(server != NULL) - server->step(frametime); + server->step(dtime); // End condition if(client.texturesReceived() && @@ -1128,30 +1170,52 @@ void the_game( } // Display status - std::wostringstream ss; + std::ostringstream ss; + int progress=0; if (!client.itemdefReceived()) - ss << L"Item definitions..."; + { + ss << "Item definitions..."; + progress = 0; + } else if (!client.nodedefReceived()) - ss << L"Node definitions..."; + { + ss << "Node definitions..."; + progress = 25; + } else - ss << L"Media (" << (int)(client.mediaReceiveProgress()*100+0.5) << L"%)..."; - - if (clouds != 0) { - clouds->step(frametime*3); - clouds->render(); + ss << "Media..."; + progress = 50+client.mediaReceiveProgress()*50+0.5; } + wchar_t* text = wgettext(ss.str().c_str()); + draw_load_screen(text, device, font, dtime, progress); + delete[] text; - draw_load_screen(ss.str(), device, font, client.mediaReceiveProgress()*100+0.5, clouds!=0); - - // Delay a bit - sleep_ms(1000*frametime); - time_counter += frametime; - } - if (clouds != 0) - { - smgr->addToDeletionQueue(clouds); - clouds->drop(); + // On some computers framerate doesn't seem to be + // automatically limited + if (cloud_menu_background) { + // Time of frame without fps limit + float busytime; + u32 busytime_u32; + // not using getRealTime is necessary for wine + u32 time = device->getTimer()->getTime(); + if(time > lasttime) + busytime_u32 = time - lasttime; + else + busytime_u32 = 0; + busytime = busytime_u32 / 1000.0; + + // FPS limiter + u32 frametime_min = 1000./fps_max; + + if(busytime_u32 < frametime_min) { + u32 sleeptime = frametime_min - busytime_u32; + device->sleep(sleeptime); + } + } else { + sleep_ms(25); + } + time_counter += dtime; } } @@ -3278,7 +3342,9 @@ void the_game( */ { /*gui::IGUIStaticText *gui_shuttingdowntext = */ - draw_load_screen(L"Shutting down stuff...", device, font); + wchar_t* text = wgettext("Shutting down stuff..."); + draw_load_screen(text, device, font, 0, -1, false); + delete[] text; /*driver->beginScene(true, true, video::SColor(255,0,0,0)); guienv->drawAll(); driver->endScene(); diff --git a/src/main.cpp b/src/main.cpp index b87a3e6d0..94382ec60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,6 +88,10 @@ Settings *g_settings = &main_settings; Profiler main_profiler; Profiler *g_profiler = &main_profiler; +// Menu clouds are created later +Clouds *g_menuclouds = 0; +irr::scene::ISceneManager *g_menucloudsmgr = 0; + /* Debug streams */ @@ -1569,6 +1573,19 @@ int main(int argc, char *argv[]) skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255,96,134,49)); #endif + + // Create the menu clouds + if (!g_menucloudsmgr) + g_menucloudsmgr = smgr->createNewSceneManager(); + if (!g_menuclouds) + g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(), + g_menucloudsmgr, -1, rand(), 100); + g_menuclouds->update(v2f(0, 0), video::SColor(255,200,200,255)); + scene::ICameraSceneNode* camera; + camera = g_menucloudsmgr->addCameraSceneNode(0, + v3f(0,0,0), v3f(0, 60, 100)); + camera->setFarValue(10000); + /* GUI stuff */ @@ -1744,18 +1761,6 @@ int main(int argc, char *argv[]) &g_menumgr, &menudata, g_gamecallback); menu->allowFocusRemoval(true); - // 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"") { verbosestream<<"error_message = " @@ -1796,7 +1801,7 @@ int main(int argc, char *argv[]) } // Time calc for the clouds - f32 dtime; // in seconds + f32 dtime=0; // in seconds if (cloud_menu_background) { u32 time = device->getTimer()->getTime(); if(time > lasttime) @@ -1811,9 +1816,9 @@ int main(int argc, char *argv[]) if (cloud_menu_background) { // *3 otherwise the clouds would move very slowly - clouds->step(dtime*3); - clouds->render(); - smgr->drawAll(); + g_menuclouds->step(dtime*3); + g_menuclouds->render(); + g_menucloudsmgr->drawAll(); drawMenuOverlay(driver, menutextures); drawMenuHeader(driver, menutextures); drawMenuFooter(driver, menutextures); @@ -1856,8 +1861,6 @@ int main(int argc, char *argv[]) infostream<<"Dropping main menu"<drop(); - clouds->drop(); - smgr->clear(); } playername = wide_to_narrow(menudata.name); @@ -2018,6 +2021,7 @@ int main(int argc, char *argv[]) gamespec, simple_singleplayer_mode ); + smgr->clear(); } //try catch(con::PeerNotFoundException &e) @@ -2048,6 +2052,10 @@ int main(int argc, char *argv[]) } } // Menu-game loop + + g_menuclouds->drop(); + g_menucloudsmgr->drop(); + delete input; /* diff --git a/src/main.h b/src/main.h index daa8c70d2..df67a6348 100644 --- a/src/main.h +++ b/src/main.h @@ -28,6 +28,14 @@ extern Settings *g_settings; class Profiler; extern Profiler *g_profiler; +// Menu clouds +class Clouds; +extern Clouds *g_menuclouds; + +// Scene manager used for menu clouds +namespace irr{namespace scene{class ISceneManager;}} +extern irr::scene::ISceneManager *g_menucloudsmgr; + // Debug streams #include -- cgit v1.2.3 From e5781b5e34a7f867c8dc7ebc1cbb6e81efaa9b86 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Fri, 10 May 2013 21:54:50 +0200 Subject: Fix memory leaks: delete font in main and GUIChatConsole --- src/guiChatConsole.cpp | 1 + src/main.cpp | 2 ++ 2 files changed, 3 insertions(+) (limited to 'src/main.cpp') diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index ec23648f8..f31e599dc 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -121,6 +121,7 @@ GUIChatConsole::GUIChatConsole( GUIChatConsole::~GUIChatConsole() { + delete m_font; } void GUIChatConsole::openConsole(f32 height) diff --git a/src/main.cpp b/src/main.cpp index 94382ec60..e2ea19295 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2063,6 +2063,8 @@ int main(int argc, char *argv[]) */ device->drop(); + delete font; + #endif // !SERVER // Update configuration file -- cgit v1.2.3 From 9575b0a2a8bf6f5f24a98215cda494440e4f3831 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Wed, 1 May 2013 13:09:10 +0200 Subject: Add code to play main_menu.ogg in main menu --- src/main.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index e2ea19295..56cb310ca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,6 +76,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "subgame.h" #include "quicktune.h" #include "serverlist.h" +#include "sound.h" +#include "sound_openal.h" /* Settings. @@ -200,7 +202,49 @@ u32 getTime(TimePrecision prec) { return 0; return g_timegetter->getTime(prec); } +#endif + +//Client side main menu music fetcher +#ifndef SERVER +class MenuMusicFetcher: public OnDemandSoundFetcher +{ + std::set m_fetched; +public: + void fetchSounds(const std::string &name, + std::set &dst_paths, + std::set &dst_datas) + { + if(m_fetched.count(name)) + return; + m_fetched.insert(name); + std::string base; + base = porting::path_share + DIR_DELIM + "sounds"; + dst_paths.insert(base + DIR_DELIM + name + ".ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".0.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".1.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".2.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".3.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".4.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".5.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".6.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".7.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".8.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".9.ogg"); + base = porting::path_user + DIR_DELIM + "sounds"; + dst_paths.insert(base + DIR_DELIM + name + ".ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".0.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".1.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".2.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".3.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".4.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".5.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".6.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".7.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".8.ogg"); + dst_paths.insert(base + DIR_DELIM + name + ".9.ogg"); + } +}; #endif class StderrLogOutput: public ILogOutput @@ -1776,6 +1820,16 @@ int main(int argc, char *argv[]) // Time is in milliseconds, for clouds u32 lasttime = device->getTimer()->getTime(); + MenuMusicFetcher soundfetcher; + ISoundManager *sound = NULL; + sound = createOpenALSoundManager(&soundfetcher); + if(!sound) + sound = &dummySoundManager; + SimpleSoundSpec spec; + spec.name = "main_menu"; + spec.gain = 1; + s32 handle = sound->playSound(spec, true); + infostream<<"Created main menu"<run() && kill == false) @@ -1857,7 +1911,12 @@ int main(int argc, char *argv[]) sleep_ms(25); } } - + sound->stopSound(handle); + if(sound != &dummySoundManager){ + delete sound; + sound = NULL; + } + infostream<<"Dropping main menu"<drop(); -- cgit v1.2.3 From efc9329033ece46f04c5aaee3e34c49eb482eaa3 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Sat, 11 May 2013 16:08:01 +0200 Subject: Only use game filter in singleplayer tab; use menu_{background, overlay, header, footer}.png for other tabs --- src/guiMainMenu.cpp | 53 +++++++++++++++++++------------------------- src/guiMainMenu.h | 9 ++++++++ src/main.cpp | 63 ++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 74 insertions(+), 51 deletions(-) (limited to 'src/main.cpp') diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 9966b9fa7..36685db84 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -166,15 +166,6 @@ enum GUI_ID_GAME_BUTTON_MAX = 150, }; -enum -{ - TAB_SINGLEPLAYER=0, - TAB_MULTIPLAYER, - TAB_ADVANCED, - TAB_SETTINGS, - TAB_CREDITS -}; - GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, @@ -258,7 +249,8 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, size.X, 40); rect += v2s32(4, 0); std::string t = "Minetest " VERSION_STRING; - if(m_data->selected_game_name != ""){ + if(m_data->selected_game_name != "" && + m_data->selected_tab == TAB_SINGLEPLAYER){ t += "/"; t += m_data->selected_game_name; } @@ -428,6 +420,26 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) delete[] text; } changeCtype("C"); + + /* Add game selection buttons */ + video::IVideoDriver* driver = Environment->getVideoDriver(); + for(size_t i=0; igames.size(); i++){ + const SubgameSpec *spec = &m_data->games[i]; + v2s32 p(8 + i*(48+8), screensize.Y - (48+8)); + core::rect rect(0, 0, 48, 48); + rect += p; + video::ITexture *bgtexture = NULL; + if(spec->menuicon_path != "") + bgtexture = driver->getTexture(spec->menuicon_path.c_str()); + gui::IGUIButton *b = Environment->addButton(rect, this, + GUI_ID_GAME_BUTTON_FIRST+i, narrow_to_wide(wrap_rows(spec->id, 4)).c_str()); + if(bgtexture){ + b->setImage(bgtexture); + b->setText(L""); + b->setDrawBorder(false); + b->setUseAlphaChannel(true); + } + } } else if(m_data->selected_tab == TAB_MULTIPLAYER) { @@ -920,27 +932,6 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) } } - /* Add game selection buttons */ - - video::IVideoDriver* driver = Environment->getVideoDriver(); - for(size_t i=0; igames.size(); i++){ - const SubgameSpec *spec = &m_data->games[i]; - v2s32 p(8 + i*(48+8), screensize.Y - (48+8)); - core::rect rect(0, 0, 48, 48); - rect += p; - video::ITexture *bgtexture = NULL; - if(spec->menuicon_path != "") - bgtexture = driver->getTexture(spec->menuicon_path.c_str()); - gui::IGUIButton *b = Environment->addButton(rect, this, - GUI_ID_GAME_BUTTON_FIRST+i, narrow_to_wide(wrap_rows(spec->id, 4)).c_str()); - if(bgtexture){ - b->setImage(bgtexture); - b->setText(L""); - b->setDrawBorder(false); - b->setUseAlphaChannel(true); - } - } - m_is_regenerating = false; } diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index 1d09c8baa..8697344c8 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -34,6 +34,15 @@ enum { SERVERLIST_PUBLIC, }; +enum +{ + TAB_SINGLEPLAYER=0, + TAB_MULTIPLAYER, + TAB_ADVANCED, + TAB_SETTINGS, + TAB_CREDITS +}; + struct MainMenuData { // These are in the native format of the gui elements diff --git a/src/main.cpp b/src/main.cpp index 56cb310ca..7f9ec1ace 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -663,12 +663,14 @@ private: struct MenuTextures { std::string current_gameid; + bool global_textures; video::ITexture *background; video::ITexture *overlay; video::ITexture *header; video::ITexture *footer; MenuTextures(): + global_textures(false), background(NULL), overlay(NULL), header(NULL), @@ -678,28 +680,49 @@ struct MenuTextures static video::ITexture* getMenuTexture(const std::string &tname, video::IVideoDriver* driver, const SubgameSpec *spec) { - std::string path; - // eg. minetest_menu_background.png (for texture packs) - std::string pack_tname = spec->id + "_menu_" + tname + ".png"; - path = getTexturePath(pack_tname); - if(path != "") - return driver->getTexture(path.c_str()); - // eg. games/minetest_game/menu/background.png - path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png"); - if(path != "") - return driver->getTexture(path.c_str()); + if(spec){ + std::string path; + // eg. minetest_menu_background.png (for texture packs) + std::string pack_tname = spec->id + "_menu_" + tname + ".png"; + path = getTexturePath(pack_tname); + if(path != "") + return driver->getTexture(path.c_str()); + // eg. games/minetest_game/menu/background.png + path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png"); + if(path != "") + return driver->getTexture(path.c_str()); + } else { + std::string path; + // eg. menu_background.png + std::string pack_tname = "menu_" + tname + ".png"; + path = getTexturePath(pack_tname); + if(path != "") + return driver->getTexture(path.c_str()); + } return NULL; } - void update(video::IVideoDriver* driver, const SubgameSpec *spec) + void update(video::IVideoDriver* driver, const SubgameSpec *spec, int tab) { - if(spec->id == current_gameid) - return; - current_gameid = spec->id; - background = getMenuTexture("background", driver, spec); - overlay = getMenuTexture("overlay", driver, spec); - header = getMenuTexture("header", driver, spec); - footer = getMenuTexture("footer", driver, spec); + if(tab == TAB_SINGLEPLAYER){ + if(spec->id == current_gameid) + return; + current_gameid = spec->id; + global_textures = false; + background = getMenuTexture("background", driver, spec); + overlay = getMenuTexture("overlay", driver, spec); + header = getMenuTexture("header", driver, spec); + footer = getMenuTexture("footer", driver, spec); + } else { + if(global_textures) + return; + current_gameid = ""; + global_textures = true; + background = getMenuTexture("background", driver, NULL); + overlay = getMenuTexture("overlay", driver, NULL); + header = getMenuTexture("header", driver, NULL); + footer = getMenuTexture("footer", driver, NULL); + } } }; @@ -1778,7 +1801,7 @@ int main(int argc, char *argv[]) const SubgameSpec *menugame = getMenuGame(menudata); MenuTextures menutextures; - menutextures.update(driver, menugame); + menutextures.update(driver, menugame, menudata.selected_tab); if(skip_main_menu == false) { @@ -1839,7 +1862,7 @@ int main(int argc, char *argv[]) // Game can be selected in the menu menugame = getMenuGame(menudata); - menutextures.update(driver, menugame); + menutextures.update(driver, menugame, menu->getTab()); // Clouds for the main menu bool cloud_menu_background = g_settings->getBool("menu_clouds"); if(menugame){ -- cgit v1.2.3