From: Ingo Ruhnke Date: Thu, 19 Nov 2009 14:55:47 +0000 (+0000) Subject: Move some code from TitleScreen to ContribWorldMenu X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=52c749cffd94bff3899a0f93f3f3af11a5c1dfab;p=supertux.git Move some code from TitleScreen to ContribWorldMenu SVN-Revision: 6046 --- diff --git a/src/supertux/menu/contrib_world_menu.cpp b/src/supertux/menu/contrib_world_menu.cpp index 5991c59df..29e81d5fb 100644 --- a/src/supertux/menu/contrib_world_menu.cpp +++ b/src/supertux/menu/contrib_world_menu.cpp @@ -16,19 +16,24 @@ #include "supertux/menu/contrib_world_menu.hpp" +#include "audio/sound_manager.hpp" +#include "gui/menu_item.hpp" +#include "supertux/globals.hpp" +#include "supertux/mainloop.hpp" #include "supertux/title_screen.hpp" #include "supertux/world.hpp" #include "util/gettext.hpp" -ContribWorldMenu::ContribWorldMenu(const World& current_world) +ContribWorldMenu::ContribWorldMenu(const World& current_world) : + m_current_world(current_world) { - add_label(current_world.title); + add_label(m_current_world.title); add_hl(); - for (unsigned int i = 0; i < current_world.get_num_levels(); ++i) + for (unsigned int i = 0; i < m_current_world.get_num_levels(); ++i) { /** get level's title */ - std::string filename = current_world.get_level_filename(i); + std::string filename = m_current_world.get_level_filename(i); std::string title = TitleScreen::get_level_name(filename); add_entry(i, title); } @@ -37,4 +42,18 @@ ContribWorldMenu::ContribWorldMenu(const World& current_world) add_back(_("Back")); } +void +ContribWorldMenu::check_menu() +{ + int index = check(); + if (index != -1) { + if (get_item_by_id(index).kind == MN_ACTION) + { + sound_manager->stop_music(); + GameSession* session = new GameSession(m_current_world.get_level_filename(index)); + g_main_loop->push_screen(session); + } + } +} + /* EOF */ diff --git a/src/supertux/menu/contrib_world_menu.hpp b/src/supertux/menu/contrib_world_menu.hpp index 123b2c75d..bfe55cd48 100644 --- a/src/supertux/menu/contrib_world_menu.hpp +++ b/src/supertux/menu/contrib_world_menu.hpp @@ -24,9 +24,13 @@ class World; class ContribWorldMenu : public Menu { private: + const World& m_current_world; + public: ContribWorldMenu(const World& current_world); + void check_menu(); + private: ContribWorldMenu(const ContribWorldMenu&); ContribWorldMenu& operator=(const ContribWorldMenu&); diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index 10abd39ba..1dedf8a5b 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -145,20 +145,6 @@ TitleScreen::check_levels_contrib_menu() } } -void -TitleScreen::check_contrib_world_menu() -{ - int index = contrib_world_menu->check(); - if (index != -1) { - if (contrib_world_menu->get_item_by_id(index).kind == MN_ACTION) { - sound_manager->stop_music(); - GameSession* session = - new GameSession(current_world->get_level_filename(index)); - g_main_loop->push_screen(session); - } - } -} - namespace { bool generate_addons_menu_sorter(const Addon* a1, const Addon* a2) { @@ -370,7 +356,7 @@ TitleScreen::update(float elapsed_time) } else if(menu == addons_menu.get()) { check_addons_menu(); } else if (menu == contrib_world_menu.get()) { - check_contrib_world_menu(); + contrib_world_menu->check_menu(); } } diff --git a/src/supertux/title_screen.hpp b/src/supertux/title_screen.hpp index ef4a5d077..99f2f72cf 100644 --- a/src/supertux/title_screen.hpp +++ b/src/supertux/title_screen.hpp @@ -22,6 +22,7 @@ #include "supertux/game_session.hpp" class Menu; +class ContribWorldMenu; class World; class CodeController; @@ -51,7 +52,6 @@ private: void generate_main_menu(); void generate_contrib_menu(); void check_levels_contrib_menu(); - void check_contrib_world_menu(); void free_contrib_menu(); void generate_addons_menu(); void check_addons_menu(); @@ -60,7 +60,7 @@ private: private: std::auto_ptr main_menu; std::auto_ptr contrib_menu; - std::auto_ptr contrib_world_menu; + std::auto_ptr contrib_world_menu; std::auto_ptr main_world; std::vector contrib_worlds; std::auto_ptr addons_menu;