Changed error handling in TransferStatus, then-callbacks are now always called and...
[supertux.git] / src / supertux / menu / menu_storage.cpp
index 3a3ea91..67b76da 100644 (file)
@@ -1,5 +1,5 @@
 //  SuperTux
-//  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
 //
 //  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
 
 #include "supertux/menu/menu_storage.hpp"
 
-#include "supertux/menu/options_menu.hpp"
-#include "supertux/menu/profile_menu.hpp"
+#include "supertux/globals.hpp"
+#include "supertux/menu/addon_menu.hpp"
+#include "supertux/menu/cheat_menu.hpp"
+#include "supertux/menu/contrib_menu.hpp"
+#include "supertux/menu/game_menu.hpp"
 #include "supertux/menu/joystick_menu.hpp"
 #include "supertux/menu/keyboard_menu.hpp"
-#include "supertux/globals.hpp"
+#include "supertux/menu/language_menu.hpp"
+#include "supertux/menu/main_menu.hpp"
+#include "supertux/menu/options_menu.hpp"
+#include "supertux/menu/profile_menu.hpp"
+#include "supertux/menu/worldmap_menu.hpp"
+#include "supertux/menu/worldmap_cheat_menu.hpp"
 
-OptionsMenu*  MenuStorage::options_menu = 0;
-ProfileMenu*  MenuStorage::profile_menu = 0;
-KeyboardMenu* MenuStorage::key_options_menu = 0;
-JoystickMenu* MenuStorage::joystick_options_menu = 0;
+MenuStorage* MenuStorage::s_instance = 0;
 
-OptionsMenu*
-MenuStorage::get_options_menu()
+MenuStorage&
+MenuStorage::instance()
 {
-  options_menu = new OptionsMenu();
-  return options_menu;
+  assert(s_instance);
+  return *s_instance;
 }
 
-ProfileMenu*
-MenuStorage::get_profile_menu()
+MenuStorage::MenuStorage()
 {
-  profile_menu = new ProfileMenu();
-  return profile_menu;
+  assert(!s_instance);
+  s_instance = this;
 }
 
-KeyboardMenu*
-MenuStorage::get_key_options_menu()
+MenuStorage::~MenuStorage()
 {
-  if (!key_options_menu)
-  { // FIXME: this in never freed
-    key_options_menu = new KeyboardMenu(g_jk_controller);
-  }
-
-  return key_options_menu;
+  s_instance = nullptr;
 }
 
-JoystickMenu*
-MenuStorage::get_joystick_options_menu()
+std::unique_ptr<Menu>
+MenuStorage::create(MenuId menu_id)
 {
-  if (!joystick_options_menu)
-  { // FIXME: this in never freed
-    joystick_options_menu = new JoystickMenu(g_jk_controller);
-  }
+  switch(menu_id)
+  {
+    case MAIN_MENU:
+      return std::unique_ptr<Menu>(new MainMenu);
+
+    case LANGUAGE_MENU:
+      return std::unique_ptr<Menu>(new LanguageMenu);
+
+    case OPTIONS_MENU:
+      return std::unique_ptr<Menu>(new OptionsMenu(true));
+
+    case INGAME_OPTIONS_MENU:
+      return std::unique_ptr<Menu>(new OptionsMenu(false));
 
-  return joystick_options_menu;
+    case PROFILE_MENU:
+      return std::unique_ptr<Menu>(new ProfileMenu);
+
+    case KEYBOARD_MENU:
+      return std::unique_ptr<Menu>(new KeyboardMenu(*InputManager::current()));
+
+    case JOYSTICK_MENU:
+      return std::unique_ptr<Menu>(new JoystickMenu(*InputManager::current()));
+
+    case WORLDMAP_MENU:
+      return std::unique_ptr<Menu>(new WorldmapMenu);
+
+    case WORLDMAP_CHEAT_MENU:
+      return std::unique_ptr<Menu>(new WorldmapCheatMenu);
+
+    case GAME_MENU:
+      return std::unique_ptr<Menu>(new GameMenu);
+
+    case CHEAT_MENU:
+      return std::unique_ptr<Menu>(new CheatMenu);
+
+    case CONTRIB_MENU:
+      return std::unique_ptr<Menu>(new ContribMenu);
+
+    case CONTRIB_WORLD_MENU:
+      return 0; //return new ContribWorldMenu();
+
+    case ADDON_MENU:
+      return std::unique_ptr<Menu>(new AddonMenu);
+
+    case NO_MENU:
+      return std::unique_ptr<Menu>();
+
+    default:
+      assert(!"unknown MenuId provided");
+      return std::unique_ptr<Menu>();
+  }
 }
 
 /* EOF */