From: Tobias Markus Date: Tue, 17 Mar 2015 14:44:40 +0000 (+0100) Subject: Only pause game on focus lose when game session is active X-Git-Url: https://git.octo.it/?p=supertux.git;a=commitdiff_plain;h=590805b8b24971ca43f777abfbf79fce21792804 Only pause game on focus lose when game session is active --- diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index da864e27b..d29300d92 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -75,7 +75,8 @@ GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Stat coins_at_start(), bonus_at_start(), max_fire_bullets_at_start(), - max_ice_bullets_at_start() + max_ice_bullets_at_start(), + active(false) { if (restart_level() != 0) throw std::runtime_error ("Initializing the level failed."); @@ -272,6 +273,12 @@ GameSession::abort_level() currentStatus->max_ice_bullets = max_ice_bullets_at_start; } +bool +GameSession::is_active() const +{ + return !game_pause && active; +} + void GameSession::set_editmode(bool edit_mode_) { @@ -411,6 +418,7 @@ GameSession::setup() int total_stats_to_be_collected = level->stats.total_coins + level->stats.total_badguys + level->stats.total_secrets; if ((!levelintro_shown) && (total_stats_to_be_collected > 0)) { levelintro_shown = true; + active = false; ScreenManager::current()->push_screen(std::unique_ptr(new LevelIntro(level.get(), best_level_statistics))); } } @@ -423,6 +431,11 @@ GameSession::leave() void GameSession::update(float elapsed_time) { + // Set active flag + if(!active) + { + active = true; + } // handle controller if(InputManager::current()->get_controller()->pressed(Controller::ESCAPE) || InputManager::current()->get_controller()->pressed(Controller::START)) diff --git a/src/supertux/game_session.hpp b/src/supertux/game_session.hpp index 0499e2d32..5356ee130 100644 --- a/src/supertux/game_session.hpp +++ b/src/supertux/game_session.hpp @@ -83,6 +83,7 @@ public: void toggle_pause(); void abort_level(); + bool is_active() const; /** * Enters or leaves level editor mode @@ -151,6 +152,8 @@ private: BonusType bonus_at_start; /** What bonuses does the player have at the start */ int max_fire_bullets_at_start; /** How many fire bullets does the player have */ int max_ice_bullets_at_start; /** How many ice bullets does the player have */ + + bool active; /** Game active? **/ private: GameSession(const GameSession&); diff --git a/src/supertux/screen_manager.cpp b/src/supertux/screen_manager.cpp index decc603e3..e1c3376f5 100644 --- a/src/supertux/screen_manager.cpp +++ b/src/supertux/screen_manager.cpp @@ -216,7 +216,9 @@ ScreenManager::process_events() break; case SDL_WINDOWEVENT_FOCUS_LOST: - if(GameSession::current() != NULL) { + if(GameSession::current() != NULL && + GameSession::current()->is_active()) + { GameSession::current()->toggle_pause(); } break;