e498739ec35e4b0e1822f56cde4b434402777162
[supertux.git] / src / supertux / menu / main_menu.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/main_menu.hpp"
18
19 #include "audio/sound_manager.hpp"
20 #include "gui/menu_manager.hpp"
21 #include "supertux/fadeout.hpp"
22 #include "supertux/globals.hpp"
23 #include "supertux/menu/menu_storage.hpp"
24 #include "supertux/menu/addon_menu.hpp"
25 #include "supertux/menu/options_menu.hpp"
26 #include "supertux/menu/contrib_menu.hpp"
27 #include "supertux/screen_manager.hpp"
28 #include "supertux/textscroller.hpp"
29 #include "supertux/title_screen.hpp"
30 #include "supertux/world.hpp"
31 #include "util/gettext.hpp"
32
33 MainMenu::MainMenu() :
34   m_addon_menu(),
35   m_contrib_menu()
36 {
37   set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
38   add_entry(MNID_STARTGAME, _("Start Game"));
39   add_entry(MNID_LEVELS_CONTRIB, _("Contrib Levels"));
40   add_entry(MNID_ADDONS, _("Add-ons"));
41   add_submenu(_("Options"), MenuStorage::get_options_menu());
42   add_entry(MNID_CREDITS, _("Credits"));
43   add_entry(MNID_QUITMAINMENU, _("Quit"));
44 }
45
46 void
47 MainMenu::check_menu()
48 {
49   switch (check())
50   {
51     case MNID_STARTGAME:
52       if (m_main_world.get() == NULL)
53       {
54         m_main_world.reset(new World());
55         m_main_world->load("levels/world1/info");
56       }
57       TitleScreen::start_game(m_main_world.get());
58       break;
59
60     case MNID_LEVELS_CONTRIB:
61       // Contrib Menu
62       m_contrib_menu.reset(new ContribMenu());
63       MenuManager::push_current(m_contrib_menu.get());
64       break;
65
66     case MNID_ADDONS:
67       // Add-ons Menu
68       m_addon_menu.reset(new AddonMenu());
69       MenuManager::push_current(m_addon_menu.get());
70       break;
71
72     case MNID_CREDITS:
73       MenuManager::set_current(NULL);
74       g_screen_manager->push_screen(new TextScroller("credits.txt"),
75                                     new FadeOut(0.5));
76       break;
77
78     case MNID_QUITMAINMENU:
79       g_screen_manager->quit(new FadeOut(0.25));
80       sound_manager->stop_music(0.25);
81       break;
82   }
83 }
84
85 /* EOF */