X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fmenu%2Fcontrib_menu.cpp;h=802c0eac293c06009ec8e2c9222071c2da8dcd93;hb=1ca7a41254b95a52083b63496b8a18048ee55253;hp=2139e21fdbd39ee9259797894b6d41b7ba0ce820;hpb=3370e84afe7f0cf18dc6bbdd6e6b9fdd0f98a05f;p=supertux.git diff --git a/src/supertux/menu/contrib_menu.cpp b/src/supertux/menu/contrib_menu.cpp index 2139e21fd..802c0eac2 100644 --- a/src/supertux/menu/contrib_menu.cpp +++ b/src/supertux/menu/contrib_menu.cpp @@ -1,5 +1,5 @@ // SuperTux -// Copyright (C) 2009 Ingo Ruhnke +// Copyright (C) 2009 Ingo Ruhnke // // 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,15 +17,20 @@ #include "supertux/menu/contrib_menu.hpp" #include +#include +#include "gui/menu_item.hpp" #include "gui/menu_manager.hpp" -#include "supertux/menu/contrib_world_menu.hpp" +#include "supertux/game_manager.hpp" +#include "supertux/gameconfig.hpp" +#include "supertux/menu/contrib_levelset_menu.hpp" +#include "supertux/menu/menu_storage.hpp" #include "supertux/title_screen.hpp" #include "supertux/world.hpp" +#include "util/file_system.hpp" #include "util/gettext.hpp" ContribMenu::ContribMenu() : - m_contrib_world_menu(), m_contrib_worlds() { /** Generating contrib levels list by making use of Level Subset */ @@ -46,12 +51,73 @@ ContribMenu::ContribMenu() : { try { - std::unique_ptr world (new World()); - world->load(*it + "/info"); - if (!world->hide_from_contribs) + std::unique_ptr world = World::load(*it); + + if (!world->hide_from_contribs()) { - add_entry(i++, world->get_title()); - m_contrib_worlds.push_back(std::move(world)); + Savegame savegame(world->get_savegame_filename()); + savegame.load(); + + if (world->is_levelset()) + { + int level_count = 0; + int solved_count = 0; + + const auto& state = savegame.get_levelset_state(world->get_basedir()); + for(const auto& level_state : state.level_states) + { + if (level_state.solved) + { + solved_count += 1; + } + level_count += 1; + } + + std::ostringstream title; + title << "[" << world->get_title() << "]"; + if (level_count == 0) + { + title << " *NEW*"; + } + else + { + title << " (" << solved_count << "/" << level_count << ")"; + } + add_entry(i++, title.str()); + m_contrib_worlds.push_back(std::move(world)); + } + else if (world->is_worldmap()) + { + int level_count = 0; + int solved_count = 0; + + const auto& state = savegame.get_worldmap_state(world->get_worldmap_filename()); + for(const auto& level_state : state.level_states) + { + if (level_state.solved) + { + solved_count += 1; + } + level_count += 1; + } + + std::ostringstream title; + title << world->get_title(); + if (level_count == 0) + { + title << " *NEW*"; + } + else + { + title << " (" << solved_count << "/" << level_count << ")"; + } + add_entry(i++, title.str()); + m_contrib_worlds.push_back(std::move(world)); + } + else + { + log_warning << "unknown World type" << std::endl; + } } } catch(std::exception& e) @@ -69,21 +135,21 @@ ContribMenu::~ContribMenu() } void -ContribMenu::check_menu() +ContribMenu::menu_action(MenuItem* item) { - int index = check(); + int index = item->id; if (index != -1) { - World* world = m_contrib_worlds[index].get(); - - if (!world->is_levelset) + // reload the World so that we have something that we can safely + // std::move() around without wreaking the ContribMenu + std::unique_ptr world = World::load(m_contrib_worlds[index]->get_basedir()); + if (!world->is_levelset()) { - TitleScreen::start_game(world); + GameManager::current()->start_worldmap(std::move(world)); } - else + else { - m_contrib_world_menu.reset(new ContribWorldMenu(*world)); - MenuManager::instance().push_current(m_contrib_world_menu.get()); + MenuManager::instance().push_menu(std::unique_ptr(new ContribLevelsetMenu(std::move(world)))); } } }