Added MenuManager to keep track of created Menus
authorgrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 19 Nov 2009 00:52:29 +0000 (00:52 +0000)
committergrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 19 Nov 2009 00:52:29 +0000 (00:52 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6038 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/supertux/game_session.cpp
src/supertux/menu/menu_manager.cpp [new file with mode: 0644]
src/supertux/menu/menu_manager.hpp [new file with mode: 0644]
src/supertux/menu/options_menu.cpp
src/supertux/menu/options_menu.hpp
src/supertux/menu/profile_menu.cpp
src/supertux/menu/profile_menu.hpp
src/supertux/title_screen.cpp
src/worldmap/worldmap.cpp

index 65336e3..79b5aca 100644 (file)
@@ -34,6 +34,7 @@
 #include "supertux/levelintro.hpp"
 #include "supertux/globals.hpp"
 #include "supertux/mainloop.hpp"
+#include "supertux/menu/menu_manager.hpp"
 #include "supertux/menu/options_menu.hpp"
 #include "supertux/sector.hpp"
 #include "util/file_system.hpp"
@@ -83,7 +84,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics)
   game_menu->add_label(level->name);
   game_menu->add_hl();
   game_menu->add_entry(MNID_CONTINUE, _("Continue"));
-  game_menu->add_submenu(_("Options"), get_options_menu());
+  game_menu->add_submenu(_("Options"), MenuManager::get_options_menu());
   game_menu->add_hl();
   game_menu->add_entry(MNID_ABORTLEVEL, _("Abort Level"));
 }
@@ -151,7 +152,7 @@ GameSession::~GameSession()
   delete capture_demo_stream;
   delete playback_demo_stream;
   delete demo_controller;
-  free_options_menu();
+  MenuManager::free_options_menu();
 }
 
 void
diff --git a/src/supertux/menu/menu_manager.cpp b/src/supertux/menu/menu_manager.cpp
new file mode 100644 (file)
index 0000000..1c9f0bc
--- /dev/null
@@ -0,0 +1,53 @@
+//  SuperTux
+//  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "supertux/menu/menu_manager.hpp"
+
+#include "supertux/menu/options_menu.hpp"
+#include "supertux/menu/profile_menu.hpp"
+
+Menu* MenuManager::options_menu = 0;
+Menu* MenuManager::profile_menu = 0;
+
+Menu*
+MenuManager::get_options_menu()
+{
+  options_menu = new OptionsMenu();
+  return options_menu;
+}
+
+void
+MenuManager::free_options_menu()
+{
+  delete options_menu;
+  options_menu = 0;
+}
+
+Menu*
+MenuManager::get_profile_menu()
+{
+  profile_menu = new ProfileMenu();
+  return profile_menu;
+}
+
+void
+MenuManager::free_profile_menu()
+{
+  delete profile_menu;
+  profile_menu = 0;
+}
+
+/* EOF */
diff --git a/src/supertux/menu/menu_manager.hpp b/src/supertux/menu/menu_manager.hpp
new file mode 100644 (file)
index 0000000..435421d
--- /dev/null
@@ -0,0 +1,44 @@
+//  SuperTux
+//  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_SUPERTUX_MENU_MENU_MANAGER_HPP
+#define HEADER_SUPERTUX_SUPERTUX_MENU_MENU_MANAGER_HPP
+
+class Menu;
+
+class MenuManager
+{
+public:
+  MenuManager();
+
+  static Menu* get_options_menu();
+  static void free_options_menu();
+
+  static Menu* get_profile_menu();
+  static void free_profile_menu();
+
+private:
+  static Menu* options_menu;
+  static Menu* profile_menu;
+
+private:
+  MenuManager(const MenuManager&);
+  MenuManager& operator=(const MenuManager&);
+};
+
+#endif
+
+/* EOF */
index 344b38d..1bebe59 100644 (file)
 #include "supertux/main.hpp"
 #include "supertux/menu/profile_menu.hpp"
 #include "supertux/menu/language_menu.hpp"
+#include "supertux/menu/menu_manager.hpp"
 #include "util/gettext.hpp"
 #include "video/renderer.hpp"
 
-Menu* options_menu   = 0;
-
 enum OptionsMenuIDs {
   MNID_FULLSCREEN,
   MNID_FULLSCREEN_RESOLUTION,
@@ -54,7 +53,7 @@ OptionsMenu::OptionsMenu() :
   add_submenu(_("Select Language"), language_menu.get())
     ->set_help(_("Select a different language to display text in"));
 
-  add_submenu(_("Select Profile"), get_profile_menu())
+  add_submenu(_("Select Profile"), MenuManager::get_profile_menu())
     ->set_help(_("Select a profile to play with"));
 
   add_toggle(MNID_PROFILES, _("Profile on Startup"), g_config->sound_enabled)
@@ -212,7 +211,7 @@ OptionsMenu::menu_action(MenuItem* item)
       break;
 
     case MNID_FULLSCREEN:
-      if(g_config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
+      if(g_config->use_fullscreen != is_toggled(MNID_FULLSCREEN)) {
         g_config->use_fullscreen = !g_config->use_fullscreen;
         init_video(); // FIXME: Should call apply_config instead
         Menu::recalc_pos();
@@ -221,7 +220,7 @@ OptionsMenu::menu_action(MenuItem* item)
       break;
 
     case MNID_SOUND:
-      if(g_config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
+      if(g_config->sound_enabled != is_toggled(MNID_SOUND)) {
         g_config->sound_enabled = !g_config->sound_enabled;
         sound_manager->enable_sound(g_config->sound_enabled);
         g_config->save();
@@ -229,7 +228,7 @@ OptionsMenu::menu_action(MenuItem* item)
       break;
 
     case MNID_MUSIC:
-      if(g_config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
+      if(g_config->music_enabled != is_toggled(MNID_MUSIC)) {
         g_config->music_enabled = !g_config->music_enabled;
         sound_manager->enable_music(g_config->music_enabled);
         g_config->save();
@@ -241,17 +240,4 @@ OptionsMenu::menu_action(MenuItem* item)
   }
 }
 
-Menu* get_options_menu()
-{
-  //static OptionsMenu menu;
-  options_menu = new OptionsMenu();
-  return options_menu;
-}
-
-void free_options_menu()
-{
-  delete options_menu;
-  options_menu = 0;
-}
-
 /* EOF */
index be2264d..4e70a64 100644 (file)
@@ -24,9 +24,6 @@
 
 class LanguageMenu;
 
-Menu* get_options_menu();
-void free_options_menu();
-
 class OptionsMenu : public Menu
 {
 public:
@@ -36,8 +33,7 @@ public:
   virtual void menu_action(MenuItem* item);
 
 protected:
-  std::auto_ptr<LanguageMenu> language_menu;
-  
+  std::auto_ptr<LanguageMenu> language_menu; 
 };
 
 #endif
index e97a640..39b0d95 100644 (file)
@@ -14,6 +14,8 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+#include "supertux/menu/profile_menu.hpp"
+
 #include <sstream>
 
 #include "gui/menu.hpp"
 #include "supertux/gameconfig.hpp"
 #include "util/gettext.hpp"
 
-enum ProfileMenuIDs {
-  
-};
-
-class ProfileMenu : public Menu
+ProfileMenu::ProfileMenu() 
 {
-public:
-  ProfileMenu() {
-    add_label(_("Select Profile"));
-    add_hl();
-    for(int i = 0; i < 5; ++i)
-    {
-      std::ostringstream out;
-      out << "Profile " << i+1;
-      add_entry(i+1, out.str());
-    }
-
-    add_hl();
-    add_back(_("Back"));
-  }
-
-  void menu_action(MenuItem* item) {
-    g_config->profile = item->id;
-    Menu::set_current(0);
+  add_label(_("Select Profile"));
+  add_hl();
+  for(int i = 0; i < 5; ++i)
+  {
+    std::ostringstream out;
+    out << "Profile " << i+1;
+    add_entry(i+1, out.str());
   }
-};
 
-Menu* profile_menu = 0;
-
-Menu* get_profile_menu()
-{
-  //static ProfileMenu menu;
-  profile_menu = new ProfileMenu();
-  return profile_menu;
+  add_hl();
+  add_back(_("Back"));
 }
 
-void free_profile_menu()
+void
+ProfileMenu::menu_action(MenuItem* item) 
 {
-  delete profile_menu;
-  profile_menu = 0;
+  g_config->profile = item->id;
+  Menu::set_current(0);
 }
 
 /*
index 89b965c..ac301e0 100644 (file)
 #ifndef HEADER_SUPERTUX_SUPERTUX_PROFILE_MENU_HPP
 #define HEADER_SUPERTUX_SUPERTUX_PROFILE_MENU_HPP
 
-class Menu;
-Menu* get_profile_menu();
-void free_profile_menu();
+#include "gui/menu.hpp"
+
+class ProfileMenu : public Menu
+{
+public:
+  ProfileMenu();
+
+  void menu_action(MenuItem* item);
+};
 
 #endif
 
index 2a5a2da..5da0446 100644 (file)
@@ -33,6 +33,7 @@
 #include "supertux/gameconfig.hpp"
 #include "supertux/globals.hpp"
 #include "supertux/mainloop.hpp"
+#include "supertux/menu/menu_manager.hpp"
 #include "supertux/menu/options_menu.hpp"
 #include "supertux/resources.hpp"
 #include "supertux/sector.hpp"
@@ -339,7 +340,7 @@ TitleScreen::generate_main_menu()
   main_menu->add_entry(MNID_STARTGAME, _("Start Game"));
   main_menu->add_entry(MNID_LEVELS_CONTRIB, _("Contrib Levels"));
   main_menu->add_entry(MNID_ADDONS, _("Add-ons"));
-  main_menu->add_submenu(_("Options"), get_options_menu());
+  main_menu->add_submenu(_("Options"), MenuManager::get_options_menu());
   main_menu->add_entry(MNID_CREDITS, _("Credits"));
   main_menu->add_entry(MNID_QUITMAINMENU, _("Quit"));
 }
index 3fd4ec5..b56c9f3 100644 (file)
@@ -45,6 +45,7 @@
 #include "supertux/game_session.hpp"
 #include "supertux/globals.hpp"
 #include "supertux/mainloop.hpp"
+#include "supertux/menu/menu_manager.hpp"
 #include "supertux/menu/options_menu.hpp"
 #include "supertux/player_status.hpp"
 #include "supertux/resources.hpp"
@@ -176,7 +177,7 @@ WorldMap::WorldMap(const std::string& filename, const std::string& force_spawnpo
   worldmap_menu->add_label(_("Pause"));
   worldmap_menu->add_hl();
   worldmap_menu->add_entry(MNID_RETURNWORLDMAP, _("Continue"));
-  worldmap_menu->add_submenu(_("Options"), get_options_menu());
+  worldmap_menu->add_submenu(_("Options"), MenuManager::get_options_menu());
   worldmap_menu->add_hl();
   worldmap_menu->add_entry(MNID_QUITWORLDMAP, _("Quit World"));