Move some code from TitleScreen to ContribWorldMenu
authorgrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 19 Nov 2009 14:55:47 +0000 (14:55 +0000)
committergrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 19 Nov 2009 14:55:47 +0000 (14:55 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6046 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/supertux/menu/contrib_world_menu.cpp
src/supertux/menu/contrib_world_menu.hpp
src/supertux/title_screen.cpp
src/supertux/title_screen.hpp

index 5991c59..29e81d5 100644 (file)
 
 #include "supertux/menu/contrib_world_menu.hpp"
 
+#include "audio/sound_manager.hpp"
+#include "gui/menu_item.hpp"
+#include "supertux/globals.hpp"
+#include "supertux/mainloop.hpp"
 #include "supertux/title_screen.hpp"
 #include "supertux/world.hpp"
 #include "util/gettext.hpp"
 
-ContribWorldMenu::ContribWorldMenu(const World& current_world)
+ContribWorldMenu::ContribWorldMenu(const World& current_world) :
+  m_current_world(current_world)
 {
-  add_label(current_world.title);
+  add_label(m_current_world.title);
   add_hl();
 
-  for (unsigned int i = 0; i < current_world.get_num_levels(); ++i)
+  for (unsigned int i = 0; i < m_current_world.get_num_levels(); ++i)
   {
     /** get level's title */
-    std::string filename = current_world.get_level_filename(i);
+    std::string filename = m_current_world.get_level_filename(i);
     std::string title = TitleScreen::get_level_name(filename);
     add_entry(i, title);
   }
@@ -37,4 +42,18 @@ ContribWorldMenu::ContribWorldMenu(const World& current_world)
   add_back(_("Back"));
 }
 
+void
+ContribWorldMenu::check_menu()
+{
+  int index = check();
+  if (index != -1) {
+    if (get_item_by_id(index).kind == MN_ACTION) 
+    {
+      sound_manager->stop_music();
+      GameSession* session = new GameSession(m_current_world.get_level_filename(index));
+      g_main_loop->push_screen(session);
+    }
+  }
+}
+
 /* EOF */
index 123b2c7..bfe55cd 100644 (file)
@@ -24,9 +24,13 @@ class World;
 class ContribWorldMenu : public Menu
 {
 private:
+  const World& m_current_world;
+
 public:
   ContribWorldMenu(const World& current_world);
 
+  void check_menu();
+
 private:
   ContribWorldMenu(const ContribWorldMenu&);
   ContribWorldMenu& operator=(const ContribWorldMenu&);
index 10abd39..1dedf8a 100644 (file)
@@ -145,20 +145,6 @@ TitleScreen::check_levels_contrib_menu()
   }
 }
 
-void
-TitleScreen::check_contrib_world_menu()
-{
-  int index = contrib_world_menu->check();
-  if (index != -1) {
-    if (contrib_world_menu->get_item_by_id(index).kind == MN_ACTION) {
-      sound_manager->stop_music();
-      GameSession* session =
-        new GameSession(current_world->get_level_filename(index));
-      g_main_loop->push_screen(session);
-    }
-  }
-}
-
 namespace {
 bool generate_addons_menu_sorter(const Addon* a1, const Addon* a2)
 {
@@ -370,7 +356,7 @@ TitleScreen::update(float elapsed_time)
     } else if(menu == addons_menu.get()) {
       check_addons_menu();
     } else if (menu == contrib_world_menu.get()) {
-      check_contrib_world_menu();
+      contrib_world_menu->check_menu();
     }
   }
 
index ef4a5d0..99f2f72 100644 (file)
@@ -22,6 +22,7 @@
 #include "supertux/game_session.hpp"
 
 class Menu;
+class ContribWorldMenu;
 class World;
 class CodeController;
 
@@ -51,7 +52,6 @@ private:
   void generate_main_menu();
   void generate_contrib_menu();
   void check_levels_contrib_menu();
-  void check_contrib_world_menu();
   void free_contrib_menu();
   void generate_addons_menu();
   void check_addons_menu();
@@ -60,7 +60,7 @@ private:
 private:
   std::auto_ptr<Menu> main_menu;
   std::auto_ptr<Menu> contrib_menu;
-  std::auto_ptr<Menu> contrib_world_menu;
+  std::auto_ptr<ContribWorldMenu> contrib_world_menu;
   std::auto_ptr<World> main_world;
   std::vector<World*> contrib_worlds;
   std::auto_ptr<Menu> addons_menu;