X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Ftitle_screen.cpp;h=fbe7fee0b07324bb367055855dce7fe7a5fb4cf0;hb=08bddcf4d4fbe2edf9a0078dc6f3c3275ef05302;hp=afbc717306fb0081fe3b2509760ccf0b5b9e00a3;hpb=b6693682e157c0edb3813884215def96d314fd21;p=supertux.git diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index afbc71730..fbe7fee0b 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -15,10 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - #include "supertux/title_screen.hpp" - #include "audio/sound_manager.hpp" #include "gui/menu_manager.hpp" #include "lisp/parser.hpp" @@ -27,7 +25,7 @@ #include "supertux/fadeout.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" -#include "supertux/mainloop.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/menu/addon_menu.hpp" #include "supertux/menu/contrib_world_menu.hpp" #include "supertux/menu/contrib_menu.hpp" @@ -41,28 +39,23 @@ #include "util/reader.hpp" #include "video/drawing_context.hpp" -TitleScreen::TitleScreen() : - main_menu(), - contrib_menu(), - contrib_world_menu(), - addons_menu(), - main_world(), - contrib_worlds(), - current_world(), +#include +#include + +TitleScreen::TitleScreen(PlayerStatus* player_status) : + main_menu(new MainMenu()), frame(), controller(), titlesession() { controller.reset(new CodeController()); - titlesession.reset(new GameSession("levels/misc/menu.stl")); + titlesession.reset(new GameSession("levels/misc/menu.stl", player_status)); Player* player = titlesession->get_current_sector()->player; player->set_controller(controller.get()); player->set_speedlimit(230); //MAX_WALK_XM - generate_main_menu(); - - frame = std::auto_ptr(new Surface("images/engine/menu/frame.png")); + frame = Surface::create("images/engine/menu/frame.png"); } std::string @@ -87,25 +80,6 @@ TitleScreen::get_level_name(const std::string& filename) } void -TitleScreen::check_levels_contrib_menu() -{ - current_world = contrib_menu->get_current_world(); - - if (current_world) - { - if (!current_world->is_levelset) - { - start_game(); - } - else - { - contrib_world_menu.reset(new ContribWorldMenu(*current_world)); - MenuManager::push_current(contrib_world_menu.get()); - } - } -} - -void TitleScreen::make_tux_jump() { static bool jumpWasReleased = true; @@ -116,7 +90,7 @@ TitleScreen::make_tux_jump() controller->press(Controller::RIGHT); // Check if we should press the jump button - Rect lookahead = tux->get_bbox(); + Rectf lookahead = tux->get_bbox(); lookahead.p2.x += 96; bool pathBlocked = !sector->is_free_of_statics(lookahead); if ((pathBlocked && jumpWasReleased) || !tux->on_ground()) { @@ -133,12 +107,6 @@ TitleScreen::make_tux_jump() } } -void -TitleScreen::generate_main_menu() -{ - main_menu.reset(new MainMenu()); -} - TitleScreen::~TitleScreen() { } @@ -146,8 +114,6 @@ TitleScreen::~TitleScreen() void TitleScreen::setup() { - player_status->reset(); - Sector* sector = titlesession->get_current_sector(); if(Sector::current() != sector) { sector->play_music(LEVEL_MUSIC); @@ -172,98 +138,59 @@ TitleScreen::draw(DrawingContext& context) sector->draw(context); // FIXME: Add something to scale the frame to the resolution of the screen - context.draw_surface(frame.get(), Vector(0,0),LAYER_FOREGROUND1); + //context.draw_surface(frame, Vector(0,0),LAYER_FOREGROUND1); - context.draw_text(Resources::small_font, "SuperTux " PACKAGE_VERSION "\n", - Vector(5, SCREEN_HEIGHT - 50), ALIGN_LEFT, LAYER_FOREGROUND1); context.draw_text(Resources::small_font, - _( - "Copyright (c) 2007 SuperTux Devel Team\n" - "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to\n" + "SuperTux " PACKAGE_VERSION "\n" + + _("Copyright") + " (c) 2003-2013 SuperTux Devel Team\n" + + _("This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to\n" "redistribute it under certain conditions; see the file COPYING for details.\n" ), - Vector(5, SCREEN_HEIGHT - 50 + Resources::small_font->get_height() + 5), + Vector(5, SCREEN_HEIGHT - 50), ALIGN_LEFT, LAYER_FOREGROUND1); } void TitleScreen::update(float elapsed_time) { - g_main_loop->set_speed(0.6f); + g_screen_manager->set_speed(0.6f); Sector* sector = titlesession->get_current_sector(); sector->update(elapsed_time); make_tux_jump(); - Menu* menu = MenuManager::current(); - if(menu) { - if(menu == main_menu.get()) { - switch (main_menu->check()) { - case MNID_STARTGAME: - // Start Game, ie. goto the slots menu - if(main_world.get() == NULL) { - main_world.reset(new World()); - main_world->load("levels/world1/info"); - } - current_world = main_world.get(); - start_game(); - break; - - case MNID_LEVELS_CONTRIB: - // Contrib Menu - contrib_menu.reset(new ContribMenu()); - MenuManager::push_current(contrib_menu.get()); - break; - - case MNID_ADDONS: - // Add-ons Menu - addons_menu.reset(new AddonMenu()); - MenuManager::push_current(addons_menu.get()); - break; - - case MNID_CREDITS: - MenuManager::set_current(NULL); - g_main_loop->push_screen(new TextScroller("credits.txt"), - new FadeOut(0.5)); - break; - - case MNID_QUITMAINMENU: - g_main_loop->quit(new FadeOut(0.25)); - sound_manager->stop_music(0.25); - break; - } - } else if(menu == contrib_menu.get()) { - check_levels_contrib_menu(); - } else if(menu == addons_menu.get()) { - addons_menu->check_menu(); - } else if (menu == contrib_world_menu.get()) { - contrib_world_menu->check_menu(); - } + if (Menu* menu = MenuManager::current()) + { + menu->check_menu(); } // reopen menu if user closed it (so that the app doesn't close when user // accidently hit ESC) - if(MenuManager::current() == 0 && g_main_loop->has_no_pending_fadeout()) { - generate_main_menu(); + if(MenuManager::current() == 0 && g_screen_manager->has_no_pending_fadeout()) + { MenuManager::set_current(main_menu.get()); } } void -TitleScreen::start_game() +TitleScreen::start_game(World* world) { MenuManager::set_current(NULL); - std::string basename = current_world->get_basedir(); + + std::string basename = world->get_basedir(); basename = basename.substr(0, basename.length()-1); std::string worlddirname = FileSystem::basename(basename); std::ostringstream stream; stream << "profile" << g_config->profile << "/" << worlddirname << ".stsg"; std::string slotfile = stream.str(); - try { - current_world->set_savegame_filename(slotfile); - current_world->run(); - } catch(std::exception& e) { + try + { + world->set_savegame_filename(slotfile); + world->run(); + } + catch(std::exception& e) + { log_fatal << "Couldn't start world: " << e.what() << std::endl; } }