X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftitle.cpp;h=724d1afb5d7e95cc8c960f9d7c83e2166dd318a0;hb=47c58b6b5d40807eee7bd37fa2fd5d2188a333fd;hp=61276638008898cbe02a9af81d3c7499735f295c;hpb=3e4c1285ee74547ce0b970835b15453e4a4e4f7d;p=supertux.git diff --git a/src/title.cpp b/src/title.cpp index 612766380..724d1afb5 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -18,55 +18,34 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include -#include "gameconfig.hpp" #include "title.hpp" -#include "mainloop.hpp" -#include "video/drawing_context.hpp" -#include "video/surface.hpp" + +#include "addon/addon_manager.hpp" #include "audio/sound_manager.hpp" +#include "fadeout.hpp" +#include "file_system.hpp" +#include "gameconfig.hpp" +#include "gettext.hpp" #include "gui/menu.hpp" -#include "timer.hpp" -#include "lisp/lisp.hpp" #include "lisp/parser.hpp" -#include "level.hpp" -#include "world.hpp" -#include "game_session.hpp" -#include "worldmap/worldmap.hpp" -#include "player_status.hpp" -#include "tile.hpp" -#include "sector.hpp" -#include "object/tilemap.hpp" +#include "log.hpp" +#include "main.hpp" +#include "mainloop.hpp" #include "object/camera.hpp" #include "object/player.hpp" +#include "options_menu.hpp" #include "resources.hpp" -#include "gettext.hpp" +#include "sector.hpp" #include "textscroller.hpp" -#include "fadeout.hpp" -#include "file_system.hpp" -#include "control/joystickkeyboardcontroller.hpp" -#include "control/codecontroller.hpp" -#include "main.hpp" -#include "log.hpp" -#include "options_menu.hpp" -#include "console.hpp" -#include "random_generator.hpp" -#include "addon_manager.hpp" +#include "video/drawing_context.hpp" +#include "world.hpp" + +#include +#include enum MainMenuIDs { MNID_STARTGAME, @@ -149,7 +128,7 @@ TitleScreen::get_level_name(const std::string& filename) level->get("name", name); return name; } catch(std::exception& e) { - log_warning << "Problem getting name of '" << filename << "': " + log_warning << "Problem getting name of '" << filename << "': " << e.what() << std::endl; return ""; } @@ -202,9 +181,9 @@ TitleScreen::check_contrib_world_menu() } namespace { - bool generate_addons_menu_sorter(const Addon& a1, const Addon& a2) + bool generate_addons_menu_sorter(const Addon* a1, const Addon* a2) { - return a1.title < a2.title; + return a1->title < a2->title; } const int ADDON_LIST_START_ID = 10; @@ -215,43 +194,12 @@ TitleScreen::generate_addons_menu() { AddonManager& adm = AddonManager::get_instance(); - // refresh list of installed addons - installed_addons = adm.get_installed_addons(); + // refresh list of addons + addons = adm.get_addons(); - // build new Add-on list - addons.clear(); - - // add installed addons to list - addons.insert(addons.end(), installed_addons.begin(), installed_addons.end()); - - // add available addons to list - addons.insert(addons.end(), available_addons.begin(), available_addons.end()); - // sort list std::sort(addons.begin(), addons.end(), generate_addons_menu_sorter); - // remove available addons that are already installed - std::vector::iterator it2 = addons.begin(); - while (it2 != addons.end()) { - Addon addon = *it2; - if (addon.isInstalled) { - bool restart = false; - for (std::vector::iterator it = addons.begin(); it != addons.end(); ++it) { - Addon addon2 = *it; - if ((addon2.equals(addon)) && (!addon2.isInstalled)) { - addons.erase(it); - restart = true; - break; - } - } - if (restart) { - it2 = addons.begin(); - continue; - } - } - it2++; - } - // (re)generate menu free_addons_menu(); addons_menu.reset(new Menu()); @@ -262,18 +210,18 @@ TitleScreen::generate_addons_menu() #ifdef HAVE_LIBCURL addons_menu->add_entry(0, std::string(_("Check Online"))); #else - addons_menu->add_deactive(0, std::string(_("Check Online (disabled)"))); + addons_menu->add_inactive(0, std::string(_("Check Online (disabled)"))); #endif //addons_menu->add_hl(); for (unsigned int i = 0; i < addons.size(); i++) { - Addon addon = addons[i]; + const Addon& addon = *addons[i]; std::string text = ""; if (addon.kind != "") text += addon.kind + " "; text += std::string("\"") + addon.title + "\""; if (addon.author != "") text += " by \"" + addon.author + "\""; - addons_menu->add_toggle(ADDON_LIST_START_ID + i, text, addon.isInstalled); + addons_menu->add_toggle(ADDON_LIST_START_ID + i, text, addon.loaded); } addons_menu->add_hl(); @@ -289,7 +237,7 @@ TitleScreen::check_addons_menu() // check if "Check Online" was chosen if (index == 0) { try { - available_addons = AddonManager::get_instance().get_available_addons(); + AddonManager::get_instance().check_online(); generate_addons_menu(); Menu::set_current(addons_menu.get()); addons_menu->set_active_item(index); @@ -302,32 +250,33 @@ TitleScreen::check_addons_menu() // if one of the Addons listed was chosen, take appropriate action if ((index >= ADDON_LIST_START_ID) && (index < ADDON_LIST_START_ID) + addons.size()) { - Addon addon = addons[index - ADDON_LIST_START_ID]; - if (!addon.isInstalled) { + Addon& addon = *addons[index - ADDON_LIST_START_ID]; + if (!addon.installed) { try { - addon.install(); - //generate_addons_menu(); - //Menu::set_current(addons_menu.get()); - //addons_menu->set_active_item(index); - Menu::set_current(0); + AddonManager::get_instance().install(&addon); } catch (std::runtime_error e) { - log_warning << "Installation of Add-on failed: " << e.what() << std::endl; + log_warning << "Installing Add-on failed: " << e.what() << std::endl; } + addons_menu->set_toggled(index, addon.loaded); + } else if (!addon.loaded) { + try { + AddonManager::get_instance().enable(&addon); + } + catch (std::runtime_error e) { + log_warning << "Enabling Add-on failed: " << e.what() << std::endl; + } + addons_menu->set_toggled(index, addon.loaded); } else { try { - addon.remove(); - //generate_addons_menu(); - //Menu::set_current(addons_menu.get()); - //addons_menu->set_active_item(index); - Menu::set_current(0); + AddonManager::get_instance().disable(&addon); } catch (std::runtime_error e) { - log_warning << "Removal of Add-on failed: " << e.what() << std::endl; + log_warning << "Disabling Add-on failed: " << e.what() << std::endl; } + addons_menu->set_toggled(index, addon.loaded); } } - } void @@ -356,7 +305,7 @@ TitleScreen::make_tux_jump() jumpWasReleased = true; } - // Wrap around at the end of the level back to the beginnig + // Wrap around at the end of the level back to the beginning if(sector->get_width() - 320 < tux->get_pos().x) { sector->activate("main"); sector->camera->reset(tux->get_pos()); @@ -425,15 +374,15 @@ TitleScreen::draw(DrawingContext& context) // FIXME: Add something to scale the frame to the resolution of the screen context.draw_surface(frame.get(), Vector(0,0),LAYER_FOREGROUND1); - context.draw_text(white_small_text, "SuperTux " PACKAGE_VERSION "\n", + context.draw_text(small_font, "SuperTux " PACKAGE_VERSION "\n", Vector(5, SCREEN_HEIGHT - 50), ALIGN_LEFT, LAYER_FOREGROUND1); - context.draw_text(white_small_text, + context.draw_text(small_font, _( "Copyright (c) 2007 SuperTux Devel Team\n" "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to\n" "redistribute it under certain conditions; see the file COPYING for details.\n" ), - Vector(5, SCREEN_HEIGHT - 50 + white_small_text->get_height() + 5), + Vector(5, SCREEN_HEIGHT - 50 + small_font->get_height() + 5), ALIGN_LEFT, LAYER_FOREGROUND1); } @@ -448,8 +397,6 @@ TitleScreen::update(float elapsed_time) Menu* menu = Menu::current(); if(menu) { - menu->update(); - if(menu == main_menu.get()) { switch (main_menu->check()) { case MNID_STARTGAME: @@ -475,13 +422,14 @@ TitleScreen::update(float elapsed_time) break; case MNID_CREDITS: + Menu::set_current(NULL); main_loop->push_screen(new TextScroller("credits.txt"), new FadeOut(0.5)); break; case MNID_QUITMAINMENU: main_loop->quit(new FadeOut(0.25)); - sound_manager->stop_music(0.25); + sound_manager->stop_music(0.25); break; } } else if(menu == contrib_menu.get()) { @@ -493,9 +441,9 @@ TitleScreen::update(float elapsed_time) } } - // reopen menu of user closed it (so that the app doesn't close when user + // reopen menu if user closed it (so that the app doesn't close when user // accidently hit ESC) - if(Menu::current() == 0) { + if(Menu::current() == 0 && main_loop->has_no_pending_fadeout()) { generate_main_menu(); Menu::set_current(main_menu.get()); } @@ -504,6 +452,7 @@ TitleScreen::update(float elapsed_time) void TitleScreen::start_game() { + Menu::set_current(NULL); std::string basename = current_world->get_basedir(); basename = basename.substr(0, basename.length()-1); std::string worlddirname = FileSystem::basename(basename);