1// SuperTux
2// Copyright (C) 2015 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 "editor/object_menu.hpp"
18
19#include "editor/editor.hpp"
20#include "gui/menu_item.hpp"
21#include "gui/menu_manager.hpp"
22#include "supertux/d_scope.hpp"
23#include "supertux/sector.hpp"
24#include "supertux/game_object.hpp"
25#include "supertux/moving_object.hpp"
26
27ObjectMenu::ObjectMenu(Editor& editor, GameObject* go) :
28 m_editor(editor),
29 m_object(go)
30{
31 ObjectSettings os = m_object->get_settings();
32 add_label(os.get_name());
33 add_hl();
34 for (const auto& oo_ptr : os.get_options())
35 {
36 const auto& oo = *oo_ptr;
37
38 if (!(oo.get_flags() & OPTION_HIDDEN)) {
39 oo.add_to_menu(*this);
40 }
41 }
42 add_hl();
43 add_back(_("OK"), -1);
44}
45
46ObjectMenu::~ObjectMenu()
47{
48}
49
50void
51ObjectMenu::menu_action(MenuItem& item)
52{
53 switch (item.get_id())
54 {
55 case MNID_REMOVE:
56 m_editor.delete_markers();
57 m_editor.m_reactivate_request = true;
58 MenuManager::instance().pop_menu();
59 m_object->remove_me();
60 break;
61
62 default:
63 break;
64 }
65}
66
67bool
68ObjectMenu::on_back_action()
69{
70 // FIXME: this is a bit fishy, menus shouldn't mess with editor internals
71 BIND_SECTOR(*m_editor.get_sector());
72
73 m_object->after_editor_set();
74
75 m_editor.m_reactivate_request = true;
76 if (!dynamic_cast<MovingObject*>(m_object)) {
77 m_editor.sort_layers();
78 }
79
80 return true;
81}
82
83/* EOF */
84