X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftitle.cpp;h=537ff96e0ffdc555a3304e175e379bd7eb1eca25;hb=87b7bf0359f2fb87234fdc9241c9e02320175daa;hp=12c58e2ae9cf23b75c1b4d3131a78cbedbc75019;hpb=c0093d25093395cb62fc2526ab42be65a9f015b8;p=supertux.git diff --git a/src/title.cpp b/src/title.cpp index 12c58e2ae..537ff96e0 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -31,47 +31,41 @@ #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" -#include "level_subset.h" -#include "game_session.h" -#include "worldmap.h" -#include "leveleditor.h" -#include "player_status.h" -#include "tile.h" -#include "sector.h" -#include "object/tilemap.h" -#include "object/camera.h" -#include "object/player.h" -#include "resources.h" -#include "app/gettext.h" -#include "misc.h" -#include "textscroller.h" -#include "control/joystickkeyboardcontroller.h" -#include "control/codecontroller.h" -#include "main.h" +#include + +#include "title.hpp" +#include "video/screen.hpp" +#include "video/surface.hpp" +#include "audio/sound_manager.hpp" +#include "gui/menu.hpp" +#include "timer.hpp" +#include "lisp/lisp.hpp" +#include "lisp/parser.hpp" +#include "level.hpp" +#include "level_subset.hpp" +#include "game_session.hpp" +#include "worldmap.hpp" +#include "player_status.hpp" +#include "tile.hpp" +#include "sector.hpp" +#include "object/tilemap.hpp" +#include "object/camera.hpp" +#include "object/player.hpp" +#include "resources.hpp" +#include "gettext.hpp" +#include "misc.hpp" +#include "textscroller.hpp" +#include "file_system.hpp" +#include "control/joystickkeyboardcontroller.hpp" +#include "control/codecontroller.hpp" +#include "main.hpp" 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; @@ -179,6 +181,7 @@ void check_levels_contrib_menu() if(subset.has_worldmap) { WorldMapNS::WorldMap worldmap; worldmap.set_map_filename(subset.get_worldmap_filename()); + sound_manager->stop_music(); // some fading fadeout(256); @@ -188,15 +191,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 +226,23 @@ 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) { + sound_manager->stop_music(); + 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 +251,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 +271,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); } @@ -275,19 +279,15 @@ void draw_demo(float elapsed_time) void title() { walking = true; - LevelEditor* leveleditor; - MusicRef credits_music; + //LevelEditor* leveleditor; 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,12 +304,13 @@ 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(); float elapsed_time = float(ticks - lastticks) / 1000.; - global_time += elapsed_time; + game_time += elapsed_time; lastticks = ticks; // 40fps is minimum if(elapsed_time > .04) @@ -326,7 +327,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 +342,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 +354,7 @@ void title() if(menu) { menu->draw(context); - menu->action(); + menu->update(); if(menu == main_menu) { @@ -366,29 +366,29 @@ void title() break; case MNID_LEVELS_CONTRIB: // Contrib Menu - puts("Entering contrib menu"); generate_contrib_menu(); break; #if 0 - case MNID_LEVELEDITOR: - leveleditor = new LevelEditor(); + case MNID_LEVELEDITOR: { + LevelEdtiro* leveleditor = new LevelEditor(); leveleditor->run(); delete leveleditor; Menu::set_current(main_menu); resume_demo(); break; + } #endif case MNID_CREDITS: + sound_manager->stop_music(); fadeout(500); - credits_music = sound_manager->load_music( - get_resource_filename("/music/credits.ogg")); - sound_manager->play_music(credits_music); + sound_manager->play_music("music/credits.ogg"); display_text_file("credits.txt"); + sound_manager->stop_music(); fadeout(500); Menu::set_current(main_menu); break; case MNID_QUITMAINMENU: - Menu::set_current(0); + running = false; break; } } @@ -405,12 +405,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); @@ -431,11 +430,16 @@ 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(); + sound_manager->update(); - frame_rate.update(); + //frame_rate.update(); /* Pause: */ frame++; @@ -446,5 +450,5 @@ void title() delete titlesession; delete bkg_title; delete logo; - delete img_choose_subset; + //delete img_choose_subset; }