X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftitle.cpp;h=91a632f529fc470a477aad08388ae3ce5b43a1ec;hb=e409aaf88c618c2fc47ff8f9bbe523b8f271c795;hp=3ae54f67e2d08e3d5449553e7a51296bc426cbd3;hpb=60908c905544776c376421b8d3e12eeb936c068f;p=supertux.git diff --git a/src/title.cpp b/src/title.cpp index 3ae54f67e..91a632f52 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -31,11 +31,7 @@ #include #include #include - -#ifndef WIN32 -#include -#include -#endif +#include #include "title.h" #include "video/screen.h" @@ -66,10 +62,10 @@ static Surface* bkg_title; static Surface* logo; -static Surface* img_choose_subset; +//static Surface* img_choose_subset; static bool walking; -static Timer2 random_timer; +static Timer random_timer; static int frame; @@ -78,6 +74,7 @@ static CodeController* controller; static std::vector contrib_subsets; static LevelSubset* current_contrib_subset = 0; +static int current_subset = -1; /* If the demo was stopped - because game started, level editor was excuted, etc - call this when you get back @@ -110,12 +107,21 @@ void free_contrib_menu() contrib_subsets.clear(); contrib_menu->clear(); + current_contrib_subset = 0; + current_subset = -1; } void generate_contrib_menu() { /** Generating contrib levels list by making use of Level Subset */ - std::set level_subsets = FileSystem::dsubdirs("/levels", "info"); + std::vector level_subsets; + char** files = PHYSFS_enumerateFiles("levels/"); + for(const char* const* filename = files; *filename != 0; ++filename) { + std::string filepath = std::string("levels/") + *filename; + if(PHYSFS_isDirectory(filepath.c_str())) + level_subsets.push_back(filepath); + } + PHYSFS_freeList(files); free_contrib_menu(); @@ -123,24 +129,26 @@ void generate_contrib_menu() contrib_menu->add_hl(); int i = 0; - for (std::set::iterator it = level_subsets.begin(); - it != level_subsets.end(); ++it) - { - LevelSubset* subset = new LevelSubset(); + for (std::vector::iterator it = level_subsets.begin(); + it != level_subsets.end(); ++it) { + try { + std::auto_ptr subset (new LevelSubset()); subset->load(*it); if(subset->hide_from_contribs) { - delete subset; continue; } - contrib_menu->add_submenu(subset->title, contrib_subset_menu, i); - contrib_subsets.push_back(subset); - ++i; + contrib_menu->add_submenu(subset->title, contrib_subset_menu, i++); + contrib_subsets.push_back(subset.release()); + } catch(std::exception& e) { +#ifdef DEBUG + std::cerr << "Couldn't parse levelset info for '" + << *it << "': " << e.what() << "\n"; +#endif } + } contrib_menu->add_hl(); contrib_menu->add_back(_("Back")); - - level_subsets.clear(); } std::string get_level_name(const std::string& filename) @@ -164,8 +172,6 @@ std::string get_level_name(const std::string& filename) void check_levels_contrib_menu() { - static int current_subset = -1; - int index = contrib_menu->check(); if (index == -1) return; @@ -184,15 +190,13 @@ void check_levels_contrib_menu() context.do_drawing(); // TODO: slots should be available for contrib maps - worldmap.loadgame(user_dir + "/save/" + subset.name + "-slot1.stsg"); - + worldmap.loadgame("save/" + subset.name + "-slot1.stsg"); worldmap.display(); // run the map Menu::set_current(main_menu); resume_demo(); } else if (current_subset != index) { current_subset = index; - // FIXME: This shouln't be busy looping LevelSubset& subset = * (contrib_subsets[index]); current_contrib_subset = ⊂ @@ -246,10 +250,10 @@ void draw_demo(float elapsed_time) controller->press(Controller::RIGHT); if(random_timer.check() || - (walking && (int) last_tux_x_pos == (int) tux->get_pos().x)) { + (walking && fabsf(last_tux_x_pos - tux->get_pos().x)) < .1) { walking = false; } else { - if(!walking && (int) tux->get_pos().y == (int) last_tux_y_pos) { + if(!walking && fabsf(tux->get_pos().y - last_tux_y_pos) < .1) { random_timer.start(float(rand() % 3000 + 3000) / 1000.); walking = true; } @@ -265,7 +269,7 @@ void draw_demo(float elapsed_time) sector->camera->reset(tux->get_pos()); } - sector->action(elapsed_time); + sector->update(elapsed_time); sector->draw(*titlesession->context); } @@ -277,13 +281,12 @@ void title() MusicRef credits_music; controller = new CodeController(); - titlesession = new GameSession(get_resource_filename("levels/misc/menu.stl"), - ST_GL_DEMO_GAME); + titlesession = new GameSession("levels/misc/menu.stl", ST_GL_DEMO_GAME); /* Load images: */ - bkg_title = new Surface(datadir + "/images/background/arctis.jpg", false); - logo = new Surface(datadir + "/images/title/logo.png", true); - img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", true); + bkg_title = new Surface("images/background/arctis.jpg", false); + logo = new Surface("images/engine/menu/logo.png", true); + //img_choose_subset = new Surface("images/status/choose-level-subset.png", true); titlesession->get_current_sector()->activate("main"); titlesession->set_current(); @@ -338,7 +341,7 @@ void title() Vector(0, SCREEN_HEIGHT - 50), LEFT_ALLIGN, LAYER_FOREGROUND1); context.draw_text(white_small_text, _( -"Copyright (c) 2003 SuperTux Devel Team\n" +"Copyright (c) 2005 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" ), @@ -350,7 +353,7 @@ void title() if(menu) { menu->draw(context); - menu->action(); + menu->update(); if(menu == main_menu) { @@ -377,7 +380,7 @@ void title() case MNID_CREDITS: fadeout(500); credits_music = sound_manager->load_music( - get_resource_filename("/music/credits.ogg")); + "/music/credits.ogg"); sound_manager->play_music(credits_music); display_text_file("credits.txt"); fadeout(500); @@ -401,12 +404,11 @@ void title() stream << slot; std::string str = _("Are you sure you want to delete slot") + stream.str() + "?"; - if(confirm_dialog(bkg_title, str.c_str())) - { - str = user_dir + "/save/slot" + stream.str() + ".stsg"; + if(confirm_dialog(bkg_title, str.c_str())) { + str = "save/slot" + stream.str() + ".stsg"; printf("Removing: %s\n",str.c_str()); - remove(str.c_str()); - } + PHYSFS_delete(str.c_str()); + } update_load_save_game_menu(load_game_menu); Menu::set_current(main_menu); @@ -433,8 +435,6 @@ void title() Menu::set_current(main_menu); } - mouse_cursor->draw(context); - context.do_drawing(); //frame_rate.update(); @@ -448,5 +448,5 @@ void title() delete titlesession; delete bkg_title; delete logo; - delete img_choose_subset; + //delete img_choose_subset; }