|
| 1 | +// SuperTux |
| 2 | +// Copyright (C) 2021 mrkubax10 <[email protected]> |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +#include "supertux/menu/editor_delete_levelset_menu.hpp" |
| 18 | + |
| 19 | +#include "editor/editor.hpp" |
| 20 | +#include "gui/dialog.hpp" |
| 21 | +#include "physfs/util.hpp" |
| 22 | +#include "supertux/menu/editor_levelset_select_menu.hpp" |
| 23 | +#include "supertux/world.hpp" |
| 24 | +#include "util/gettext.hpp" |
| 25 | +#include "util/log.hpp" |
| 26 | + |
| 27 | +EditorDeleteLevelsetMenu::EditorDeleteLevelsetMenu(EditorLevelsetSelectMenu* editor_levelset_select_menu) : |
| 28 | + m_editor_levelset_select_menu(editor_levelset_select_menu) |
| 29 | +{ |
| 30 | + refresh(); |
| 31 | +} |
| 32 | + |
| 33 | +void |
| 34 | +EditorDeleteLevelsetMenu::refresh() |
| 35 | +{ |
| 36 | + clear(); |
| 37 | + |
| 38 | + add_label(_("Delete World")); |
| 39 | + add_hl(); |
| 40 | + |
| 41 | + unsigned int i = 0; |
| 42 | + std::vector<std::string>& contrib_worlds = m_editor_levelset_select_menu->get_contrib_worlds(); |
| 43 | + for(std::string& level_world : contrib_worlds) |
| 44 | + { |
| 45 | + std::unique_ptr<World> world = World::from_directory(level_world); |
| 46 | + if (world->hide_from_contribs()) |
| 47 | + { |
| 48 | + continue; |
| 49 | + } |
| 50 | + if (!world->is_levelset() && !world->is_worldmap()) |
| 51 | + { |
| 52 | + log_warning << level_world << ": unknown World type" << std::endl; |
| 53 | + continue; |
| 54 | + } |
| 55 | + auto title = world->get_title(); |
| 56 | + if (title.empty()) |
| 57 | + { |
| 58 | + continue; |
| 59 | + } |
| 60 | + add_entry(i++, title); |
| 61 | + } |
| 62 | + |
| 63 | + add_hl(); |
| 64 | + |
| 65 | + add_back(_("Back")); |
| 66 | +} |
| 67 | + |
| 68 | +void |
| 69 | +EditorDeleteLevelsetMenu::menu_action(MenuItem& item) |
| 70 | +{ |
| 71 | + int id = item.get_id(); |
| 72 | + |
| 73 | + if (id >= 0) |
| 74 | + { |
| 75 | + std::vector<std::string>& contrib_worlds = m_editor_levelset_select_menu->get_contrib_worlds(); |
| 76 | + if (Editor::is_active() && Editor::current()->get_world() && Editor::current()->get_world()->get_basedir() == contrib_worlds[id]) |
| 77 | + Dialog::show_message(_("You cannot delete the world that you are editing")); |
| 78 | + else |
| 79 | + { |
| 80 | + physfsutil::remove_with_content(contrib_worlds[id]); |
| 81 | + m_editor_levelset_select_menu->reload_menu(); |
| 82 | + refresh(); |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +/* EOF */ |
0 commit comments