Menu now shrinks when closed instead of disappearing
authorRyan Flegel <rflegel@gmail.com>
Wed, 18 Jun 2008 05:08:20 +0000 (05:08 +0000)
committerRyan Flegel <rflegel@gmail.com>
Wed, 18 Jun 2008 05:08:20 +0000 (05:08 +0000)
SVN-Revision: 5584

src/game_session.cpp
src/gui/menu.cpp
src/gui/menu.hpp

index ecf7f92..8489356 100644 (file)
@@ -378,9 +378,14 @@ void
 GameSession::process_events()
 {
   // end of pause mode?
+  // XXX this looks like a fail-safe to unpause the game if there's no menu
+  // XXX having it enabled causes some unexpected problems
+  // XXX hopefully disabling it won't...
+  /*
   if(!Menu::current() && game_pause) {
     game_pause = false;
   }
+  */
 
   // playback a demo?
   if(playback_demo_stream != 0) {
index 6d6c2f6..b7873b6 100644 (file)
@@ -142,23 +142,30 @@ Menu::pop_current()
     current_->effect_progress   = 0.0f;
     last_menus.pop_back();
   } else {
-    current_ = 0;
+    set_current(NULL);
   }
 }
 
 void
 Menu::set_current(Menu* menu)
 {
+  //last_menus.clear();
+  if (current_ && current_->close == true)
+    return;
+
   previous = current_;
 
-  last_menus.clear();
+  if (menu) {
+    menu->effect_start_time = real_time;
+    menu->effect_progress = 0.0f;
+    current_ = menu;
+  }
+  else if (current_) {
+    current_->effect_start_time = real_time;
+    current_->effect_progress = 0.0f;
+    current_->close = true;
+  }
 
-  if (menu)
-    {
-      menu->effect_start_time = real_time;
-      menu->effect_progress = 0.0f;
-    }
-  current_ = menu;
   // just to be sure...
   main_controller->reset();
 }
@@ -243,6 +250,7 @@ Menu::~Menu()
 }
 
 Menu::Menu()
+    : close(false)
 {
   all_menus.push_back(this);
 
@@ -401,7 +409,13 @@ Menu::update()
 
   if(effect_progress >= 1.0f) {
     effect_progress = 1.0f;
-  } else if (effect_progress <= 0.0f) {
+
+    if (close) {
+      current_ = 0;
+      close = false;
+    }
+  }
+  else if (effect_progress <= 0.0f) {
     effect_progress = 0.0f;
   }
 
@@ -813,7 +827,12 @@ Menu::draw(DrawingContext& context)
 
   if (effect_progress != 1.0f)
     {
-      if (Menu::previous)
+      if (close)
+        {
+          menu_width  = (current_->get_width()  * (1.0f - effect_progress));
+          menu_height = (current_->get_height() * (1.0f - effect_progress));
+        }
+      else if (Menu::previous)
         {
           menu_width  = (menu_width  * effect_progress) + (Menu::previous->get_width()  * (1.0f - effect_progress));
           menu_height = (menu_height * effect_progress) + (Menu::previous->get_height() * (1.0f - effect_progress));
index cdb3325..60d48dd 100644 (file)
@@ -146,6 +146,8 @@ private:
   char  mn_input_char;
   float menu_repeat_time;
 
+  bool close;
+
 public:
   static Font* default_font;
   static Font* active_font;