Moved menu code frome GameSession and Worldmap into the proper Menu::check_menu(...
authorIngo Ruhnke <grumbel@gmail.com>
Fri, 8 Aug 2014 02:02:52 +0000 (04:02 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Fri, 8 Aug 2014 03:53:51 +0000 (05:53 +0200)
src/gui/menu.hpp
src/supertux/game_session.cpp
src/supertux/game_session.hpp
src/supertux/menu/game_menu.cpp
src/supertux/menu/game_menu.hpp
src/supertux/menu/worldmap_menu.cpp
src/supertux/menu/worldmap_menu.hpp
src/worldmap/worldmap.cpp

index 49405b6..3027506 100644 (file)
@@ -74,10 +74,6 @@ public:
   /** Remove all entries from the menu */
   void clear();
 
-  /** Return the index of the menu item that was 'hit' (ie. the user
-      clicked on it) in the last event() call */
-  int check ();
-
   virtual void check_menu() =0;
 
   MenuItem& get_item(int index)
@@ -100,6 +96,10 @@ public:
   void set_toggled(int id, bool toggled);
 
 protected:
+  /** Return the index of the menu item that was 'hit' (ie. the user
+      clicked on it) in the last event() call */
+  int check ();
+
   MenuItem* add_item(std::unique_ptr<MenuItem> menu_item);
   float get_width() const;
   float get_height() const;
index 0a83e9d..2b57b04 100644 (file)
@@ -256,6 +256,18 @@ GameSession::toggle_pause()
 }
 
 void
+GameSession::abort_level()
+{
+  MenuManager::instance().set_current(0);
+  g_screen_manager->exit_screen();
+  currentsector->player->set_bonus(bonus_at_start);
+  PlayerStatus *currentStatus = get_player_status();
+  currentStatus->coins = coins_at_start;
+  currentStatus->max_fire_bullets = max_fire_bullets_at_start;
+  currentStatus->max_ice_bullets = max_ice_bullets_at_start;
+}
+
+void
 GameSession::set_editmode(bool edit_mode)
 {
   if (this->edit_mode == edit_mode) return;
@@ -391,30 +403,6 @@ GameSession::draw_pause(DrawingContext& context)
 }
 
 void
-GameSession::process_menu()
-{
-  Menu* menu = MenuManager::instance().current();
-  if(menu) {
-    if(menu == game_menu.get()) {
-      switch (game_menu->check()) {
-        case MNID_CONTINUE:
-          MenuManager::instance().set_current(0);
-          toggle_pause();
-          break;
-        case MNID_ABORTLEVEL:
-          MenuManager::instance().set_current(0);
-          g_screen_manager->exit_screen();
-          currentsector->player->set_bonus(bonus_at_start);
-          PlayerStatus *currentStatus = get_player_status();
-          currentStatus->coins = coins_at_start;
-          currentStatus->max_fire_bullets = max_fire_bullets_at_start;
-          currentStatus->max_ice_bullets = max_ice_bullets_at_start;
-      }
-    }
-  }
-}
-
-void
 GameSession::setup()
 {
   if (currentsector == NULL)
@@ -440,7 +428,11 @@ GameSession::update(float elapsed_time)
     on_escape_press();
 
   process_events();
-  process_menu();
+  Menu* menu = MenuManager::instance().current();
+  if (menu && menu == game_menu.get())
+  {
+    menu->check_menu();
+  }
 
   // Unpause the game if the menu has been closed
   if (game_pause && !MenuManager::instance().current()) {
index cdad319..87a4192 100644 (file)
@@ -83,6 +83,7 @@ public:
   int restart_level();
 
   void toggle_pause();
+  void abort_level();
 
   /**
    * Enters or leaves level editor mode
@@ -104,7 +105,6 @@ private:
 
   HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
   void on_escape_press();
-  void process_menu();
 
   std::unique_ptr<Level> level;
   SurfacePtr statistics_backdrop;
index 1bdc59b..13deef9 100644 (file)
@@ -16,6 +16,9 @@
 
 #include "supertux/menu/game_menu.hpp"
 
+#include "gui/menu_manager.hpp"
+#include "supertux/game_session.hpp"
+#include "supertux/screen_manager.hpp"
 #include "supertux/level.hpp"
 #include "supertux/menu/menu_storage.hpp"
 #include "supertux/menu/options_menu.hpp"
@@ -34,6 +37,17 @@ GameMenu::GameMenu(const Level& level)
 void
 GameMenu::check_menu()
 {
+  switch (check())
+  {
+    case MNID_CONTINUE:
+      MenuManager::instance().set_current(0);
+      GameSession::current()->toggle_pause();
+      break;
+
+    case MNID_ABORTLEVEL:
+      GameSession::current()->abort_level();
+      break;
+  }
 }
 
 /* EOF */
index 0255f37..c325926 100644 (file)
@@ -32,7 +32,7 @@ private:
 public:
   GameMenu(const Level& level);
 
-  void check_menu();
+  void check_menu() override;
 
 private:
   GameMenu(const GameMenu&);
index 2334edb..29b8777 100644 (file)
 
 #include "supertux/menu/worldmap_menu.hpp"
 
+#include "gui/menu_manager.hpp"
 #include "supertux/menu/menu_storage.hpp"
 #include "supertux/menu/options_menu.hpp"
+#include "supertux/screen_manager.hpp"
 #include "util/gettext.hpp"
 
 WorldmapMenu::WorldmapMenu()
@@ -33,6 +35,16 @@ WorldmapMenu::WorldmapMenu()
 void
 WorldmapMenu::check_menu()
 {
+  switch (check())
+  {
+    case MNID_RETURNWORLDMAP: // Return to game
+      MenuManager::instance().set_current(0);
+      break;
+
+    case MNID_QUITWORLDMAP: // Quit Worldmap
+      g_screen_manager->exit_screen();
+      break;
+  }
 }
 
 /* EOF */
index 6f06372..219abc2 100644 (file)
@@ -30,7 +30,7 @@ private:
 public:
   WorldmapMenu();
 
-  void check_menu();
+  void check_menu() override;
 
 private:
   WorldmapMenu(const WorldmapMenu&);
index b974db8..f21f854 100644 (file)
@@ -570,19 +570,9 @@ WorldMap::update(float delta)
 {
   if(!in_level) {
     Menu* menu = MenuManager::instance().current();
-    if(menu != NULL) {
-      if(menu == worldmap_menu.get()) {
-        switch (worldmap_menu->check())
-        {
-          case MNID_RETURNWORLDMAP: // Return to game
-            MenuManager::instance().set_current(0);
-            break;
-          case MNID_QUITWORLDMAP: // Quit Worldmap
-            g_screen_manager->exit_screen();
-            break;
-        }
-      }
-
+    if (menu && menu == worldmap_menu.get())
+    {
+      menu->check_menu();
       return;
     }