Switched from passing pointers around to using numeric MenuIds and a factory class
[supertux.git] / src / supertux / menu / menu_storage.cpp
1 //  SuperTux
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "supertux/menu/menu_storage.hpp"
18
19 #include "supertux/globals.hpp"
20 #include "supertux/menu/addon_menu.hpp"
21 #include "supertux/menu/contrib_menu.hpp"
22 #include "supertux/menu/contrib_world_menu.hpp"
23 #include "supertux/menu/game_menu.hpp"
24 #include "supertux/menu/joystick_menu.hpp"
25 #include "supertux/menu/keyboard_menu.hpp"
26 #include "supertux/menu/language_menu.hpp"
27 #include "supertux/menu/main_menu.hpp"
28 #include "supertux/menu/options_menu.hpp"
29 #include "supertux/menu/profile_menu.hpp"
30 #include "supertux/menu/worldmap_menu.hpp"
31
32 MenuStorage* MenuStorage::s_instance = 0;
33
34 MenuStorage&
35 MenuStorage::instance()
36 {
37   assert(s_instance);
38   return *s_instance;
39 }
40
41 MenuStorage::MenuStorage()
42 {
43   assert(!s_instance);
44   s_instance = this;
45 }
46
47 MenuStorage::~MenuStorage()
48 {
49   s_instance = nullptr;
50 }
51
52 Menu*
53 MenuStorage::create(MenuId menu_id)
54 {
55   switch(menu_id)
56   {
57     case MAIN_MENU:
58       return new MainMenu;
59
60     case LANGUAGE_MENU:
61       return new LanguageMenu;
62
63     case OPTIONS_MENU:
64       return new OptionsMenu;
65
66     case PROFILE_MENU:
67       return new ProfileMenu;
68
69     case KEYBOARD_MENU:
70       return new KeyboardMenu(g_input_manager);
71
72     case JOYSTICK_MENU:
73       return new JoystickMenu(g_input_manager);
74
75     case WORLDMAP_MENU:
76       return new WorldmapMenu;
77
78     case GAME_MENU:
79       return new GameMenu;
80
81     case CONTRIB_MENU:
82       return new ContribMenu;
83
84     case CONTRIB_WORLD_MENU:
85       return 0; //return new ContribWorldMenu();
86
87     case ADDON_MENU:
88       return new AddonMenu;
89
90     default:
91       assert(!"unknown MenuId provided");
92   }
93 }
94
95 KeyboardMenu*
96 MenuStorage::get_key_options_menu()
97 {
98   return new KeyboardMenu(g_input_manager);
99 }
100
101 JoystickMenu*
102 MenuStorage::get_joystick_options_menu()
103 {
104   return new JoystickMenu(g_input_manager);
105 }
106
107 /* EOF */