Only pause game on focus lose when game session is active
authorTobias Markus <tobbi@mozilla-uk.org>
Tue, 17 Mar 2015 14:44:40 +0000 (15:44 +0100)
committerTobias Markus <tobbi@mozilla-uk.org>
Tue, 17 Mar 2015 14:44:40 +0000 (15:44 +0100)
src/supertux/game_session.cpp
src/supertux/game_session.hpp
src/supertux/screen_manager.cpp

index da864e2..d29300d 100644 (file)
@@ -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<Screen>(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))
index 0499e2d..5356ee1 100644 (file)
@@ -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&);
index decc603..e1c3376 100644 (file)
@@ -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;