X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftitle.cpp;h=91a632f529fc470a477aad08388ae3ce5b43a1ec;hb=e409aaf88c618c2fc47ff8f9bbe523b8f271c795;hp=6badcd5a3453326c9f69d9c18c01424e3ea9dc95;hpb=eba5f4b45f92cb19a09fbac1a478648062480adb;p=supertux.git diff --git a/src/title.cpp b/src/title.cpp index 6badcd5a3..91a632f52 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -31,20 +31,13 @@ #include #include #include +#include -#ifndef WIN32 -#include -#include -#endif - -#include "app/globals.h" #include "title.h" #include "video/screen.h" #include "video/surface.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" @@ -59,19 +52,20 @@ #include "object/camera.h" #include "object/player.h" #include "resources.h" -#include "app/gettext.h" +#include "gettext.h" #include "misc.h" #include "textscroller.h" +#include "file_system.h" #include "control/joystickkeyboardcontroller.h" #include "control/codecontroller.h" #include "main.h" 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; @@ -80,8 +74,7 @@ static CodeController* controller; static std::vector contrib_subsets; static LevelSubset* current_contrib_subset = 0; - -static FrameRate frame_rate(100); +static int current_subset = -1; /* If the demo was stopped - because game started, level editor was excuted, etc - call this when you get back @@ -93,7 +86,7 @@ void resume_demo() titlesession->get_current_sector()->activate("main"); titlesession->set_current(); - frame_rate.update(); + //frame_rate.update(); } void update_load_save_game_menu(Menu* menu) @@ -114,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(); @@ -127,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); - 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) @@ -168,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; @@ -188,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 = ⊂ @@ -225,25 +225,22 @@ void check_levels_contrib_menu() void check_contrib_subset_menu() { int index = contrib_subset_menu->check(); - if (index != -1) - { - if (contrib_subset_menu->get_item_by_id(index).kind == MN_ACTION) - { - std::cout << "Starting level: " << index << std::endl; - - GameSession session( - current_contrib_subset->get_level_filename(index), ST_GL_PLAY); - session.run(); - player_status.reset(); - Menu::set_current(main_menu); - resume_demo(); - } - } + if (index != -1) { + if (contrib_subset_menu->get_item_by_id(index).kind == MN_ACTION) { + GameSession session( + current_contrib_subset->get_level_filename(index), ST_GL_PLAY); + session.run(); + player_status.reset(); + Menu::set_current(main_menu); + resume_demo(); + } + } } void draw_demo(float elapsed_time) { static float last_tux_x_pos = -1; + static float last_tux_y_pos = -1; Sector* sector = titlesession->get_current_sector(); Player* tux = sector->player; @@ -252,14 +249,19 @@ void draw_demo(float elapsed_time) controller->update(); controller->press(Controller::RIGHT); - if(random_timer.check() || (int) last_tux_x_pos == (int) tux->get_pos().x) { - random_timer.start(float(rand() % 3000 + 3000) / 1000.); - walking = !walking; + if(random_timer.check() || + (walking && fabsf(last_tux_x_pos - tux->get_pos().x)) < .1) { + walking = false; } else { - if(!walking) - controller->press(Controller::JUMP); + if(!walking && fabsf(tux->get_pos().y - last_tux_y_pos) < .1) { + random_timer.start(float(rand() % 3000 + 3000) / 1000.); + walking = true; + } } + if(!walking) + controller->press(Controller::JUMP); last_tux_x_pos = tux->get_pos().x; + last_tux_y_pos = tux->get_pos().y; // Wrap around at the end of the level back to the beginnig if(sector->solids->get_width() * 32 - 320 < tux->get_pos().x) { @@ -267,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); } @@ -279,15 +281,12 @@ void title() MusicRef credits_music; controller = new CodeController(); - Ticks::pause_init(); - - 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(); @@ -304,7 +303,8 @@ void title() Menu::set_current(main_menu); DrawingContext& context = *titlesession->context; - while (Menu::current()) + bool running = true; + while (running) { // Calculate the movement-factor Uint32 ticks = SDL_GetTicks(); @@ -326,7 +326,6 @@ void title() Menu::current()->event(event); } main_controller->process_event(event); - // FIXME: QUIT signal should be handled more generic, not locally if (event.type == SDL_QUIT) throw std::runtime_error("Received window close"); } @@ -342,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" ), @@ -354,7 +353,7 @@ void title() if(menu) { menu->draw(context); - menu->action(); + menu->update(); if(menu == main_menu) { @@ -366,7 +365,6 @@ void title() break; case MNID_LEVELS_CONTRIB: // Contrib Menu - puts("Entering contrib menu"); generate_contrib_menu(); break; #if 0 @@ -382,14 +380,14 @@ 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); Menu::set_current(main_menu); break; case MNID_QUITMAINMENU: - Menu::set_current(0); + running = false; break; } } @@ -406,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); @@ -432,11 +429,15 @@ void title() } } - mouse_cursor->draw(context); - + // reopen menu of user closed it (so that the app doesn't close when user + // accidently hit ESC) + if(Menu::current() == 0) { + Menu::set_current(main_menu); + } + context.do_drawing(); - frame_rate.update(); + //frame_rate.update(); /* Pause: */ frame++; @@ -447,5 +448,5 @@ void title() delete titlesession; delete bkg_title; delete logo; - delete img_choose_subset; + //delete img_choose_subset; }