1 //  SuperTux
2 //  Copyright (C) 2016 Hume2 <teratux.mail@gmail.com>
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 "gui/menu_paths.hpp"
18 
19 #include "editor/editor.hpp"
20 #include "gui/dialog.hpp"
21 #include "gui/menu_item.hpp"
22 #include "gui/menu_manager.hpp"
23 #include "object/path_gameobject.hpp"
24 #include "object/path_object.hpp"
25 #include "supertux/sector.hpp"
26 
__anon3ca6343c0102(std::string path, PathObject& target, std::string path_ref) 27 auto on_select = [](std::string path, PathObject& target, std::string path_ref) {
28   return [path, &target, path_ref] {
29     auto dialog = std::make_unique<Dialog>();
30     dialog->add_default_button(_("Clone"), [path, path_ref] {
31       auto* from = Editor::current()->get_sector()->get_object_by_name<PathGameObject>(path);
32       auto* into = Editor::current()->get_sector()->get_object_by_name<PathGameObject>(path_ref);
33       if (from && into) {
34         from->copy_into(*into);
35         MenuManager::instance().pop_menu();
36       } else {
37         log_warning << "Could not copy path, misses " << (from ? "" : "'from'")
38                     << (into ? "" : "'into'") << std::endl;
39         Dialog::show_message(_("An error occured and the game could\nnot clone the path. Please contact\nthe developers for support."));
40       }
41     });
42     dialog->add_button(_("Bind"), [path, &target] {
43       target.editor_set_path_by_ref(path);
44         MenuManager::instance().pop_menu();
45     });
46     dialog->add_cancel_button(_("Cancel"));
47     dialog->set_text("Do you wish to clone the path to edit it separately,\nor do you want to bind both paths together\nso that any edit on one edits the other?");
48     MenuManager::instance().set_dialog(std::move(dialog));
49   };
50 };
51 
PathsMenu(PathObject & target,const std::string & path_ref)52 PathsMenu::PathsMenu(PathObject& target, const std::string& path_ref)
53 {
54   add_label(_("Path") + " " + path_ref);
55   add_hl();
56 
57   const auto paths = Editor::current()->get_sector()->get_objects_by_type<PathGameObject>();
58 
59   for (const auto& path : paths)
60   {
61     add_entry(path.get_name(), on_select(path.get_name(), target, path_ref));
62   }
63 
64   add_hl();
65   add_back(_("Back"));
66 }
67 
68 /* EOF */
69