X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Ftitle_screen.cpp;h=7b70f457afcac346543c2d4fdb62cd5040a08306;hb=aa9dd770ebf02361a846acfaef136864b82b92ce;hp=8d3013993d30ba3c71c09d360332cc33156ec278;hpb=8099ed94a2642c410ebcd1315a28d14fa6524d49;p=supertux.git diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index 8d3013993..7b70f457a 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -18,6 +18,7 @@ #include "supertux/title_screen.hpp" #include "audio/sound_manager.hpp" +#include "gui/menu.hpp" #include "gui/menu_manager.hpp" #include "lisp/parser.hpp" #include "object/camera.hpp" @@ -25,12 +26,9 @@ #include "supertux/fadeout.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.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" -#include "supertux/menu/main_menu.hpp" +#include "supertux/menu/menu_storage.hpp" #include "supertux/resources.hpp" +#include "supertux/screen_manager.hpp" #include "supertux/sector.hpp" #include "supertux/textscroller.hpp" #include "supertux/world.hpp" @@ -39,43 +37,28 @@ #include "util/reader.hpp" #include "video/drawing_context.hpp" +#include #include -TitleScreen::TitleScreen() : - main_menu(new MainMenu()), +TitleScreen::TitleScreen(Savegame& savegame) : frame(), controller(), - titlesession() + titlesession(), + copyright_text() { controller.reset(new CodeController()); - titlesession.reset(new GameSession("levels/misc/menu.stl")); + titlesession.reset(new GameSession("levels/misc/menu.stl", savegame)); Player* player = titlesession->get_current_sector()->player; player->set_controller(controller.get()); player->set_speedlimit(230); //MAX_WALK_XM frame = Surface::create("images/engine/menu/frame.png"); -} - -std::string -TitleScreen::get_level_name(const std::string& filename) -{ - try { - lisp::Parser parser; - const lisp::Lisp* root = parser.parse(filename); - - const lisp::Lisp* level = root->get_lisp("supertux-level"); - if(!level) - return ""; - - std::string name; - level->get("name", name); - return name; - } catch(std::exception& e) { - log_warning << "Problem getting name of '" << filename << "': " - << e.what() << std::endl; - return ""; - } + copyright_text = "SuperTux " PACKAGE_VERSION "\n" + + _("Copyright") + " (c) 2003-2015 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" + ); } void @@ -113,15 +96,13 @@ TitleScreen::~TitleScreen() void TitleScreen::setup() { - player_status->reset(); - Sector* sector = titlesession->get_current_sector(); if(Sector::current() != sector) { sector->play_music(LEVEL_MUSIC); sector->activate(sector->player->get_pos()); } - MenuManager::set_current(main_menu.get()); + MenuManager::instance().set_menu(MenuStorage::MAIN_MENU); } void @@ -129,7 +110,7 @@ TitleScreen::leave() { Sector* sector = titlesession->get_current_sector(); sector->deactivate(); - MenuManager::set_current(NULL); + MenuManager::instance().clear_menu_stack(); } void @@ -138,63 +119,31 @@ TitleScreen::draw(DrawingContext& context) Sector* sector = titlesession->get_current_sector(); sector->draw(context); - // FIXME: Add something to scale the frame to the resolution of the screen - context.draw_surface(frame, Vector(0,0),LAYER_FOREGROUND1); + context.draw_surface_part(frame, + Rectf(0, 0, frame->get_width(), frame->get_height()), + Rectf(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), + 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" - "redistribute it under certain conditions; see the file COPYING for details.\n" - ), - Vector(5, SCREEN_HEIGHT - 50 + Resources::small_font->get_height() + 5), + copyright_text, + Vector(5, SCREEN_HEIGHT - 50), ALIGN_LEFT, LAYER_FOREGROUND1); } void TitleScreen::update(float elapsed_time) { - g_screen_manager->set_speed(0.6f); + ScreenManager::current()->set_speed(0.6f); Sector* sector = titlesession->get_current_sector(); sector->update(elapsed_time); make_tux_jump(); - 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_screen_manager->has_no_pending_fadeout()) - { - MenuManager::set_current(main_menu.get()); - } -} - -void -TitleScreen::start_game(World* world) -{ - MenuManager::set_current(NULL); - - 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 - { - world->set_savegame_filename(slotfile); - world->run(); - } - catch(std::exception& e) + if(!MenuManager::instance().is_active() && !ScreenManager::current()->has_pending_fadeout()) { - log_fatal << "Couldn't start world: " << e.what() << std::endl; + MenuManager::instance().set_menu(MenuStorage::MAIN_MENU); } }