Disabled confirmation dialog on Quit
[supertux.git] / src / supertux / menu / main_menu.cpp
1 //  SuperTux
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
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/dialog.hpp"
21 #include "gui/menu_item.hpp"
22 #include "gui/menu_manager.hpp"
23 #include "supertux/fadeout.hpp"
24 #include "supertux/game_manager.hpp"
25 #include "supertux/globals.hpp"
26 #include "supertux/menu/addon_menu.hpp"
27 #include "supertux/menu/contrib_menu.hpp"
28 #include "supertux/menu/menu_storage.hpp"
29 #include "supertux/menu/options_menu.hpp"
30 #include "supertux/screen_fade.hpp"
31 #include "supertux/screen_manager.hpp"
32 #include "supertux/textscroller.hpp"
33 #include "supertux/title_screen.hpp"
34 #include "supertux/world.hpp"
35 #include "util/gettext.hpp"
36
37 MainMenu::MainMenu()
38 {
39   set_center_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
40
41   add_entry(MNID_STARTGAME, _("Start Game"));
42   add_entry(MNID_LEVELS_CONTRIB, _("Contrib Levels"));
43   add_entry(MNID_ADDONS, _("Add-ons"));
44   add_submenu(_("Options"), MenuStorage::OPTIONS_MENU);
45   add_entry(MNID_CREDITS, _("Credits"));
46   add_entry(MNID_QUITMAINMENU, _("Quit"));
47 }
48
49 void
50 MainMenu::on_window_resize()
51 {
52   set_center_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
53 }
54
55 void
56 MainMenu::menu_action(MenuItem* item)
57 {
58   switch (item->id)
59   {
60     case MNID_STARTGAME:
61       {
62         std::unique_ptr<World> world = World::load("levels/world1");
63         GameManager::current()->start_worldmap(std::move(world));
64       }
65       break;
66
67     case MNID_LEVELS_CONTRIB:
68       // Contrib Menu
69       MenuManager::instance().push_menu(MenuStorage::CONTRIB_MENU);
70       break;
71
72     case MNID_ADDONS:
73       // Add-ons Menu
74       MenuManager::instance().push_menu(MenuStorage::ADDON_MENU);
75       break;
76
77     case MNID_CREDITS:
78       MenuManager::instance().clear_menu_stack();
79       ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new TextScroller("credits.txt")),
80                                             std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
81       break;
82
83     case MNID_QUITMAINMENU:
84       if (true)
85       {
86         // instantly exit the game
87         MenuManager::instance().clear_menu_stack();
88         ScreenManager::current()->quit(std::unique_ptr<ScreenFade>(new FadeOut(0.25)));
89         SoundManager::current()->stop_music(0.25);
90       }
91       else
92       {
93         // confirmation dialog
94         std::unique_ptr<Dialog> dialog(new Dialog);
95         dialog->set_text(_("Do you really want to quit SuperTux?"));
96         dialog->add_cancel_button(_("Cancel"));
97         dialog->add_default_button(_("Quit SuperTux"), [] {
98             MenuManager::instance().clear_menu_stack();
99             ScreenManager::current()->quit(std::unique_ptr<ScreenFade>(new FadeOut(0.25)));
100             SoundManager::current()->stop_music(0.25);
101           });
102         MenuManager::instance().set_dialog(std::move(dialog));
103       }
104       break;
105   }
106 }
107
108 /* EOF */