Merge branch 'feature/init-cleanup'
[supertux.git] / src / supertux / menu / main_menu.cpp
index b4974a4..8eb4d7a 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
@@ -17,6 +17,7 @@
 #include "supertux/menu/main_menu.hpp"
 
 #include "audio/sound_manager.hpp"
+#include "gui/menu_item.hpp"
 #include "gui/menu_manager.hpp"
 #include "supertux/fadeout.hpp"
 #include "supertux/game_manager.hpp"
@@ -34,7 +35,8 @@
 
 MainMenu::MainMenu()
 {
-  set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
+  set_center_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
+
   add_entry(MNID_STARTGAME, _("Start Game"));
   add_entry(MNID_LEVELS_CONTRIB, _("Contrib Levels"));
   add_entry(MNID_ADDONS, _("Add-ons"));
@@ -44,15 +46,20 @@ MainMenu::MainMenu()
 }
 
 void
-MainMenu::check_menu()
+MainMenu::on_window_resize()
+{
+  set_center_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
+}
+
+void
+MainMenu::menu_action(MenuItem* item)
 {
-  switch (check())
+  switch (item->id)
   {
     case MNID_STARTGAME:
       {
-        std::unique_ptr<World> world(new World);
-        world->load("levels/world1/info");
-        GameManager::current()->start_game(std::move(world));
+        std::unique_ptr<World> world = World::load("levels/world1");
+        GameManager::current()->start_worldmap(std::move(world));
       }
       break;
 
@@ -68,13 +75,13 @@ 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);
+      ScreenManager::current()->quit(std::unique_ptr<ScreenFade>(new FadeOut(0.25)));
+      SoundManager::current()->stop_music(0.25);
       break;
   }
 }