X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgame_session.cpp;h=26f65f1c43cf9a4dbd3ede596cbf584dd6f5d9df;hb=7a6f00e27bdc0aac2107506c3b00cbf0bf1cccc5;hp=0a61cd336d67a97882c2f142fb593988c9dac5f1;hpb=fea3446f05e1e7673607b835c269d3e8d1929ab3;p=supertux.git diff --git a/src/game_session.cpp b/src/game_session.cpp index 0a61cd336..26f65f1c4 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -92,7 +92,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) end_sequence(0), levelfile(levelfile_), best_level_statistics(statistics), capture_demo_stream(0), playback_demo_stream(0), demo_controller(0), - play_time(0) + play_time(0), edit_mode(false) { current_ = this; currentsector = NULL; @@ -116,6 +116,12 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) void GameSession::restart_level() { + + if (edit_mode) { + force_ghost_mode(); + return; + } + game_pause = false; end_sequence = 0; @@ -129,7 +135,6 @@ GameSession::restart_level() level->stats.total_badguys = level->get_total_badguys(); level->stats.total_secrets = level->get_total_count(); level->stats.reset(); - if(reset_sector != "")level->stats.declare_invalid(); if(reset_sector != "") { currentsector = level->get_sector(reset_sector); @@ -138,11 +143,13 @@ GameSession::restart_level() msg << "Couldn't find sector '" << reset_sector << "' for resetting tux."; throw std::runtime_error(msg.str()); } + level->stats.declare_invalid(); currentsector->activate(reset_pos); } else { currentsector = level->get_sector("main"); if(!currentsector) throw std::runtime_error("Couldn't find main sector"); + play_time = 0; currentsector->activate("main"); } @@ -311,6 +318,32 @@ GameSession::toggle_pause() } } +void +GameSession::set_editmode(bool edit_mode) +{ + if (this->edit_mode == edit_mode) return; + this->edit_mode = edit_mode; + + currentsector->get_players()[0]->set_edit_mode(edit_mode); + + if (edit_mode) { + + // entering edit mode + + } else { + + // leaving edit mode + restart_level(); + + } +} + +void +GameSession::force_ghost_mode() +{ + currentsector->get_players()[0]->set_ghost_mode(true); +} + HSQUIRRELVM GameSession::run_script(std::istream& in, const std::string& sourcename) { @@ -411,7 +444,7 @@ GameSession::draw_pause(DrawingContext& context) { context.draw_filled_rect( Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), - Color(.2f, .2f, .2f, .5f), LAYER_FOREGROUND1); + Color(0.0f, 0.0f, 0.0f, .25f), LAYER_FOREGROUND1); } void @@ -495,7 +528,7 @@ GameSession::update(float elapsed_time) } // update sounds - sound_manager->set_listener_position(currentsector->player->get_pos()); + if (currentsector && currentsector->camera) sound_manager->set_listener_position(currentsector->camera->get_center()); /* Handle music: */ if (end_sequence) @@ -518,6 +551,11 @@ GameSession::finish(bool win) { using namespace WorldMapNS; + if (edit_mode) { + force_ghost_mode(); + return; + } + if(win) { if(WorldMap::current()) WorldMap::current()->finished_level(level.get()); @@ -547,45 +585,14 @@ GameSession::get_working_directory() } void -GameSession::display_info_box(const std::string& text) +GameSession::start_sequence(const std::string& sequencename) { - InfoBox* box = new InfoBox(text); - - bool running = true; - DrawingContext context; - - while(running) { - - // TODO make a screen out of this, another mainloop is ugly - main_controller->update(); - SDL_Event event; - while (SDL_PollEvent(&event)) { - main_controller->process_event(event); - if(event.type == SDL_QUIT) - main_loop->quit(); - } - - if(main_controller->pressed(Controller::JUMP) - || main_controller->pressed(Controller::ACTION) - || main_controller->pressed(Controller::PAUSE_MENU) - || main_controller->pressed(Controller::MENU_SELECT)) - running = false; - else if(main_controller->pressed(Controller::DOWN)) - box->scrolldown(); - else if(main_controller->pressed(Controller::UP)) - box->scrollup(); - box->draw(context); - draw(context); - context.do_drawing(); - sound_manager->update(); + // do not play sequences when in edit mode + if (edit_mode) { + force_ghost_mode(); + return; } - delete box; -} - -void -GameSession::start_sequence(const std::string& sequencename) -{ // handle special "stoptux" sequence if (sequencename == "stoptux") { if (!end_sequence) {