Replaced .reset(new Surface()) with a factory method
[supertux.git] / src / supertux / game_session.cpp
index a14c900..cffb72d 100644 (file)
@@ -22,6 +22,7 @@
 #include "audio/sound_manager.hpp"
 #include "control/joystickkeyboardcontroller.hpp"
 #include "gui/menu.hpp"
+#include "gui/menu_manager.hpp"
 #include "math/random_generator.hpp"
 #include "object/camera.hpp"
 #include "object/endsequence_fireworks.hpp"
 #include "scripting/squirrel_util.hpp"
 #include "supertux/gameconfig.hpp"
 #include "supertux/levelintro.hpp"
-#include "supertux/main.hpp"
-#include "supertux/mainloop.hpp"
-#include "supertux/options_menu.hpp"
+#include "supertux/globals.hpp"
+#include "supertux/screen_manager.hpp"
+#include "supertux/menu/menu_storage.hpp"
+#include "supertux/menu/game_menu.hpp"
+#include "supertux/menu/options_menu.hpp"
 #include "supertux/sector.hpp"
 #include "util/file_system.hpp"
 #include "util/gettext.hpp"
 #include "worldmap/worldmap.hpp"
 
-enum GameMenuIDs {
-  MNID_CONTINUE,
-  MNID_ABORTLEVEL
-};
-
 GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) :
   level(0), 
+  statistics_backdrop(),
+  scripts(),
   currentsector(0),
+  levelnb(),
+  pause_menu_frame(),
   end_sequence(0),
+  game_pause(),
+  speed_before_pause(),
   levelfile(levelfile_), 
+  reset_sector(),
+  reset_pos(),
+  newsector(),
+  newspawnpoint(),
   best_level_statistics(statistics),
   capture_demo_stream(0), 
+  capture_file(),
   playback_demo_stream(0), 
   demo_controller(0),
+  game_menu(),
   play_time(0), 
   edit_mode(false), 
   levelintro_shown(false)
@@ -61,19 +71,13 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics)
   currentsector = NULL;
 
   game_pause = false;
-  speed_before_pause = g_main_loop->get_speed();
+  speed_before_pause = g_screen_manager->get_speed();
 
-  statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png"));
+  statistics_backdrop = Surface::create("images/engine/menu/score-backdrop.png");
 
   restart_level();
 
-  game_menu.reset(new Menu());
-  game_menu->add_label(level->name);
-  game_menu->add_hl();
-  game_menu->add_entry(MNID_CONTINUE, _("Continue"));
-  game_menu->add_submenu(_("Options"), get_options_menu());
-  game_menu->add_hl();
-  game_menu->add_entry(MNID_ABORTLEVEL, _("Abort Level"));
+  game_menu.reset(new GameMenu(*level));
 }
 
 void
@@ -118,7 +122,7 @@ GameSession::restart_level()
     }
   } catch(std::exception& e) {
     log_fatal << "Couldn't start level: " << e.what() << std::endl;
-    g_main_loop->exit_screen();
+    g_screen_manager->exit_screen();
   }
 
   sound_manager->stop_music();
@@ -139,7 +143,6 @@ GameSession::~GameSession()
   delete capture_demo_stream;
   delete playback_demo_stream;
   delete demo_controller;
-  free_options_menu();
 }
 
 void
@@ -232,9 +235,9 @@ GameSession::toggle_pause()
 {
   // pause
   if(!game_pause) {
-    speed_before_pause = g_main_loop->get_speed();
-    g_main_loop->set_speed(0);
-    Menu::set_current(game_menu.get());
+    speed_before_pause = g_screen_manager->get_speed();
+    g_screen_manager->set_speed(0);
+    MenuManager::set_current(game_menu.get());
     game_menu->set_active_item(MNID_CONTINUE);
     game_pause = true;
   }
@@ -271,7 +274,7 @@ GameSession::force_ghost_mode()
 HSQUIRRELVM
 GameSession::run_script(std::istream& in, const std::string& sourcename)
 {
-  using namespace Scripting;
+  using namespace scripting;
 
   // garbage collect thread list
   for(ScriptList::iterator i = scripts.begin();
@@ -379,17 +382,17 @@ GameSession::draw_pause(DrawingContext& context)
 void
 GameSession::process_menu()
 {
-  Menu* menu = Menu::current();
+  Menu* menu = MenuManager::current();
   if(menu) {
     if(menu == game_menu.get()) {
       switch (game_menu->check()) {
         case MNID_CONTINUE:
-          Menu::set_current(0);
+          MenuManager::set_current(0);
           toggle_pause();
           break;
         case MNID_ABORTLEVEL:
-          Menu::set_current(0);
-          g_main_loop->exit_screen();
+          MenuManager::set_current(0);
+          g_screen_manager->exit_screen();
           break;
       }
     }
@@ -411,7 +414,7 @@ GameSession::setup()
 
   if (!levelintro_shown) {
     levelintro_shown = true;
-    g_main_loop->push_screen(new LevelIntro(level.get(), best_level_statistics));
+    g_screen_manager->push_screen(new LevelIntro(level.get(), best_level_statistics));
   }
 }
 
@@ -426,8 +429,8 @@ GameSession::update(float elapsed_time)
   process_menu();
 
   // Unpause the game if the menu has been closed
-  if (game_pause && !Menu::current()) {
-    g_main_loop->set_speed(speed_before_pause);
+  if (game_pause && !MenuManager::current()) {
+    g_screen_manager->set_speed(speed_before_pause);
     game_pause = false;
   }
 
@@ -488,7 +491,7 @@ GameSession::update(float elapsed_time)
 void
 GameSession::finish(bool win)
 {
-  using namespace WorldMapNS;
+  using namespace worldmap;
 
   if (edit_mode) {
     force_ghost_mode();
@@ -500,7 +503,7 @@ GameSession::finish(bool win)
       WorldMap::current()->finished_level(level.get());
   }
 
-  g_main_loop->exit_screen();
+  g_screen_manager->exit_screen();
 }
 
 void
@@ -560,7 +563,7 @@ GameSession::start_sequence(const std::string& sequencename)
   }
 
   /* slow down the game for end-sequence */
-  g_main_loop->set_speed(0.5f);
+  g_screen_manager->set_speed(0.5f);
 
   currentsector->add_object(end_sequence);
   end_sequence->start();