+ 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));
+ main_loop->push_screen(session);
+ }
+ }
+}
+
+namespace {
+ bool generate_addons_menu_sorter(const Addon& a1, const Addon& a2)
+ {
+ return a1.title < a2.title;
+ }
+
+ const int ADDON_LIST_START_ID = 10;
+}
+
+void
+TitleScreen::generate_addons_menu()
+{
+ AddonManager& adm = AddonManager::get_instance();
+
+ // refresh list of installed addons
+ installed_addons = adm.get_installed_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<Addon>::iterator it2 = addons.begin();
+ while (it2 != addons.end()) {
+ Addon addon = *it2;
+ if (addon.isInstalled) {
+ bool restart = false;
+ for (std::vector<Addon>::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());
+
+ addons_menu->add_label(_("Add-ons"));
+ addons_menu->add_hl();
+
+#ifdef HAVE_LIBCURL
+ addons_menu->add_entry(0, std::string(_("Check Online")));
+#else
+ addons_menu->add_deactive(0, std::string(_("Check Online (disabled)")));
+#endif
+
+ //addons_menu->add_hl();
+
+ for (unsigned int i = 0; i < addons.size(); i++) {
+ 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_hl();
+ addons_menu->add_back(_("Back"));
+}
+
+void
+TitleScreen::check_addons_menu()
+{
+ int index = addons_menu->check();
+ if (index == -1) return;
+
+ // check if "Check Online" was chosen
+ if (index == 0) {
+ try {
+ available_addons = AddonManager::get_instance().get_available_addons();
+ generate_addons_menu();
+ Menu::set_current(addons_menu.get());
+ addons_menu->set_active_item(index);
+ }
+ catch (std::runtime_error e) {
+ log_warning << "Check for available Add-ons failed: " << e.what() << std::endl;