Cleaned up some function names in MenuManager
authorIngo Ruhnke <grumbel@gmail.com>
Fri, 8 Aug 2014 18:14:53 +0000 (20:14 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Fri, 8 Aug 2014 19:34:53 +0000 (21:34 +0200)
src/control/keyboard_manager.cpp
src/gui/menu.cpp
src/gui/menu_manager.hpp
src/supertux/game_session.cpp
src/supertux/screen_manager.cpp
src/supertux/title_screen.cpp
src/worldmap/worldmap.cpp

index d53ed39..c6b3b1b 100644 (file)
@@ -76,7 +76,7 @@ KeyboardManager::process_key_event(const SDL_KeyboardEvent& event)
     // if console is open: send key there
     process_console_key_event(event);
   }
-  else if (MenuManager::instance().current())
+  else if (MenuManager::instance().is_active())
   {
     // if menu mode: send key there
     process_menu_key_event(event);
index 240f2fa..5c0a1dc 100644 (file)
@@ -69,10 +69,10 @@ Menu::~Menu()
 {
   MenuManager::instance().m_all_menus.remove(this);
 
-  if (MenuManager::instance().current() == this)
+  if (MenuManager::instance().m_current == this)
     MenuManager::instance().m_current = nullptr;
 
-  if (MenuManager::instance().get_previous() == this)
+  if (MenuManager::instance().m_previous == this)
     MenuManager::instance().m_previous = nullptr;
 }
 
@@ -630,13 +630,13 @@ Menu::draw(DrawingContext& context)
   {
     if (close)
     {
-      menu_width  = (MenuManager::instance().current()->get_width()  * (1.0f - effect_progress));
-      menu_height = (MenuManager::instance().current()->get_height() * (1.0f - effect_progress));
+      menu_width *= 1.0f - effect_progress;
+      menu_height *= 1.0f - effect_progress;
     }
-    else if (MenuManager::instance().get_previous())
+    else if (MenuManager::instance().m_previous)
     {
-      menu_width  = (menu_width  * effect_progress) + (MenuManager::instance().get_previous()->get_width()  * (1.0f - effect_progress));
-      menu_height = (menu_height * effect_progress) + (MenuManager::instance().get_previous()->get_height() * (1.0f - effect_progress));
+      menu_width  = (menu_width  * effect_progress) + (MenuManager::instance().m_previous->get_width()  * (1.0f - effect_progress));
+      menu_height = (menu_height * effect_progress) + (MenuManager::instance().m_previous->get_height() * (1.0f - effect_progress));
       //std::cout << effect_progress << " " << this << " " << last_menus.back() << std::endl;
     }
     else
index a390c6f..d601ae2 100644 (file)
@@ -52,15 +52,15 @@ public:
 
   void recalc_pos();
 
-  Menu* get_previous()
+  /** Return the current active menu or NULL if none is active */
+  Menu* current() const
   {
-    return m_previous;
+    return m_current;
   }
 
-  /** Return the current active menu or NULL if none is active */
-  Menu* current()
+  bool is_active() const
   {
-    return m_current;
+    return m_current != nullptr;
   }
 
 private:
index f6bd71a..86cc2bc 100644 (file)
@@ -436,7 +436,7 @@ GameSession::update(float elapsed_time)
   }
 
   // Unpause the game if the menu has been closed
-  if (game_pause && !MenuManager::instance().current()) {
+  if (game_pause && !MenuManager::instance().is_active()) {
     g_screen_manager->set_speed(speed_before_pause);
     game_pause = false;
   }
index 49468c2..4b7661b 100644 (file)
@@ -139,8 +139,8 @@ ScreenManager::draw(DrawingContext& context)
   static int frame_count = 0;
 
   current_screen->draw(context);
-  if(MenuManager::instance().current() != NULL)
-    MenuManager::instance().current()->draw(context);
+  if(m_menu_manager->current() != NULL)
+    m_menu_manager->current()->draw(context);
   if(screen_fade.get() != NULL)
     screen_fade->draw(context);
   Console::instance->draw(context);
@@ -175,8 +175,8 @@ ScreenManager::update_gamelogic(float elapsed_time)
   scripting::update_debugger();
   scripting::TimeScheduler::instance->update(game_time);
   current_screen->update(elapsed_time);
-  if (MenuManager::instance().current() != NULL)
-    MenuManager::instance().current()->update();
+  if (m_menu_manager->current() != NULL)
+    m_menu_manager->current()->update();
   if(screen_fade.get() != NULL)
     screen_fade->update(elapsed_time);
   Console::instance->update(elapsed_time);
@@ -191,8 +191,8 @@ ScreenManager::process_events()
   {
     g_input_manager->process_event(event);
 
-    if(MenuManager::instance().current() != NULL)
-      MenuManager::instance().current()->event(event);
+    if(m_menu_manager->current() != NULL)
+      m_menu_manager->current()->event(event);
 
     switch(event.type)
     {
@@ -206,7 +206,7 @@ ScreenManager::process_events()
           case SDL_WINDOWEVENT_RESIZED:
             Renderer::instance()->resize(event.window.data1,
                                          event.window.data2);
-            MenuManager::instance().recalc_pos();
+            m_menu_manager->recalc_pos();
             break;
         }
         break;
@@ -220,7 +220,7 @@ ScreenManager::process_events()
         {
           g_config->use_fullscreen = !g_config->use_fullscreen;
           Renderer::instance()->apply_config();
-          MenuManager::instance().recalc_pos();
+          m_menu_manager->recalc_pos();
         }
         else if (event.key.keysym.sym == SDLK_PRINTSCREEN ||
                  event.key.keysym.sym == SDLK_F12)
index bea6547..03201fe 100644 (file)
@@ -167,7 +167,7 @@ TitleScreen::update(float elapsed_time)
 
   // reopen menu if user closed it (so that the app doesn't close when user
   // accidently hit ESC)
-  if(MenuManager::instance().current() == 0 && g_screen_manager->has_no_pending_fadeout())
+  if(!MenuManager::instance().is_active() && g_screen_manager->has_no_pending_fadeout())
   {
     MenuManager::instance().set_current(main_menu.get());
   }
index c21fc07..01fce1d 100644 (file)
@@ -406,7 +406,7 @@ void
 WorldMap::on_escape_press()
 {
   // Show or hide the menu
-  if(!MenuManager::instance().current()) {
+  if(!MenuManager::instance().is_active()) {
     MenuManager::instance().set_current(worldmap_menu.get());
     tux->set_direction(D_NONE);  // stop tux movement when menu is called
   } else {