X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftitle.cpp;h=1e5449ef35c9bf9522262fc9167cf5c6ddcc0cce;hb=8f9dfa122134b04d68140dacf7d16e4a064e1584;hp=a1739666e19a43941473e6049e45065a77c2d706;hpb=d46c78c842ab4090a3f46e560c891234167f124b;p=supertux.git diff --git a/src/title.cpp b/src/title.cpp index a1739666e..1e5449ef3 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -41,25 +41,26 @@ #include "title.h" #include "video/screen.h" #include "video/surface.h" -#include "high_scores.h" #include "gui/menu.h" #include "timer.h" #include "special/frame_rate.h" #include "app/setup.h" +#include "lisp/lisp.h" +#include "lisp/parser.h" #include "level.h" #include "level_subset.h" #include "gameloop.h" #include "worldmap.h" #include "leveleditor.h" #include "scene.h" -#include "player.h" #include "tile.h" #include "sector.h" -#include "tilemap.h" +#include "object/tilemap.h" +#include "object/camera.h" +#include "object/player.h" #include "resources.h" #include "app/gettext.h" #include "misc.h" -#include "camera.h" static Surface* bkg_title; static Surface* logo; @@ -127,13 +128,13 @@ void generate_contrib_menu() contrib_menu->additem(MN_HL,"",0,0); int i = 0; - for(std::set::iterator it = worldmap_list.begin(); it != worldmap_list.end(); ++it) - { + for(std::set::iterator it = worldmap_list.begin(); + it != worldmap_list.end(); ++it) { WorldMapNS::WorldMap worldmap; worldmap.loadmap((*it).c_str()); contrib_menu->additem(MN_ACTION, worldmap.get_world_title(),0,0, i); ++i; - } + } contrib_menu->additem(MN_HL,"",0,0); @@ -158,6 +159,25 @@ void generate_contrib_menu() level_subsets.clear(); } +std::string get_level_name(const std::string& filename) +{ + try { + lisp::Parser parser; + std::auto_ptr 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) { + std::cerr << "Problem getting name of '" << filename << "'.\n"; + return ""; + } +} + void check_levels_contrib_menu() { static int current_subset = -1; @@ -214,35 +234,12 @@ void check_levels_contrib_menu() contrib_subset_menu->additem(MN_HL,"",0,0); for (int i = 0; i < subset.get_num_levels(); ++i) - { + { /** get level's title */ - std::string level_title = ""; - std::string filename = subset.get_level_filename(i); - std::string filepath; - filepath = st_dir + "/levels/" + filename; - if (access(filepath.c_str(), R_OK) != 0) - { - filepath = datadir + "/levels/" + filename; - if (access(filepath.c_str(), R_OK) != 0) - { - std::cerr << "Error: Level: couldn't find level: " << filename << std::endl; - continue; - } - } - - LispReader* reader = LispReader::load(filepath, "supertux-level"); - if(!reader) - { - std::cerr << "Error: Could not open level file. Ignoring...\n"; - continue; - } - - reader->read_string("name", level_title, true); - delete reader; - - contrib_subset_menu->additem(MN_ACTION, level_title, 0, 0, i); - } + std::string title = get_level_name(filename); + contrib_subset_menu->additem(MN_ACTION, title, 0, 0, i); + } contrib_subset_menu->additem(MN_HL,"",0,0); contrib_subset_menu->additem(MN_BACK, _("Back"), 0, 0); @@ -279,7 +276,6 @@ void draw_demo(float elapsed_time) world->play_music(LEVEL_MUSIC); - global_frame_counter++; tux->key_event((SDLKey) keymap.right,DOWN); if(random_timer.check()) { @@ -323,7 +319,8 @@ void title(void) Ticks::pause_init(); - titlesession = new GameSession("misc/menu.stl", ST_GL_DEMO_GAME); + titlesession = new GameSession(get_resource_filename("levels/misc/menu.stl"), + ST_GL_DEMO_GAME); /* Load images: */ bkg_title = new Surface(datadir + "/images/background/arctis.jpg", false); @@ -417,7 +414,7 @@ void title(void) break; case MNID_CREDITS: fadeout(500); - display_text_file("CREDITS", SCROLL_SPEED_CREDITS, white_big_text , white_text, white_small_text, blue_text ); + display_text_file("credits.txt", SCROLL_SPEED_CREDITS, white_big_text , white_text, white_small_text, blue_text ); fadeout(500); Menu::set_current(main_menu); break; @@ -484,6 +481,3 @@ void title(void) delete img_choose_subset; } - -// EOF // -