Added little toy test for Dialog when exiting SuperTux
[supertux.git] / src / supertux / menu / main_menu.cpp
index a93ff54..615c0aa 100644 (file)
@@ -17,6 +17,8 @@
 #include "supertux/menu/main_menu.hpp"
 
 #include "audio/sound_manager.hpp"
+#include "gui/dialog.hpp"
+#include "gui/menu_item.hpp"
 #include "gui/menu_manager.hpp"
 #include "supertux/fadeout.hpp"
 #include "supertux/game_manager.hpp"
@@ -51,9 +53,9 @@ MainMenu::on_window_resize()
 }
 
 void
-MainMenu::check_menu()
+MainMenu::menu_action(MenuItem* item)
 {
-  switch (check())
+  switch (item->id)
   {
     case MNID_STARTGAME:
       {
@@ -74,13 +76,20 @@ MainMenu::check_menu()
 
     case MNID_CREDITS:
       MenuManager::instance().clear_menu_stack();
-      g_screen_manager->push_screen(std::unique_ptr<Screen>(new TextScroller("credits.txt")),
+      ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new TextScroller("credits.txt")),
                                     std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
       break;
 
     case MNID_QUITMAINMENU:
-      g_screen_manager->quit(std::unique_ptr<ScreenFade>(new FadeOut(0.25)));
-      sound_manager->stop_music(0.25);
+      std::unique_ptr<Dialog> dialog(new Dialog);
+      dialog->set_text(_("Do you really want to quit SuperTux?"));
+      dialog->add_button(_("Cancel"));
+      dialog->add_button(_("Quit SuperTux"), [] {
+          MenuManager::instance().clear_menu_stack();
+          ScreenManager::current()->quit(std::unique_ptr<ScreenFade>(new FadeOut(0.25)));
+          SoundManager::current()->stop_music(0.25);
+        }, true);
+      MenuManager::instance().set_dialog(std::move(dialog));
       break;
   }
 }