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_badguy_select.hpp"
18
19#include "gui/dialog.hpp"
20#include "gui/menu_item.hpp"
21#include "gui/menu_manager.hpp"
22
23std::vector<std::string> BadguySelectMenu::all_badguys;
24
25BadguySelectMenu::BadguySelectMenu(std::vector<std::string>* badguys_) :
26 badguys(badguys_),
27 selected(),
28 remove_item()
29{
30 //initialize badguy list
31 if (all_badguys.empty()) {
32 all_badguys.push_back("angrystone");
33 all_badguys.push_back("bouncingsnowball");
34 all_badguys.push_back("captainsnowball");
35 all_badguys.push_back("crystallo");
36 all_badguys.push_back("dart");
37 all_badguys.push_back("darttrap");
38 all_badguys.push_back("dispenser");
39 all_badguys.push_back("fish");
40 all_badguys.push_back("flame");
41 all_badguys.push_back("flyingsnowball");
42 all_badguys.push_back("ghostflame");
43 all_badguys.push_back("ghosttree");
44 all_badguys.push_back("haywire");
45 all_badguys.push_back("iceflame");
46 all_badguys.push_back("igel");
47 all_badguys.push_back("jumpy");
48 all_badguys.push_back("kamikazesnowball");
49 all_badguys.push_back("kugelblitz");
50 all_badguys.push_back("leafshot");
51 all_badguys.push_back("livefire");
52 all_badguys.push_back("livefire_asleep");
53 all_badguys.push_back("livefire_dormant");
54 all_badguys.push_back("mole");
55 all_badguys.push_back("mole_rock");
56 all_badguys.push_back("mrbomb");
57 all_badguys.push_back("mrcandle");
58 all_badguys.push_back("mriceblock");
59 all_badguys.push_back("mrtree");
60 all_badguys.push_back("owl");
61 all_badguys.push_back("plant");
62 all_badguys.push_back("poisonivy");
63 all_badguys.push_back("short_fuse");
64 all_badguys.push_back("sspiky");
65 all_badguys.push_back("skydive");
66 all_badguys.push_back("skullyhop");
67 all_badguys.push_back("smartball");
68 all_badguys.push_back("smartblock");
69 all_badguys.push_back("snail");
70 all_badguys.push_back("snowball");
71 all_badguys.push_back("snowman");
72 all_badguys.push_back("spidermite");
73 all_badguys.push_back("spiky");
74 all_badguys.push_back("stalactite");
75 all_badguys.push_back("stumpy");
76 all_badguys.push_back("toad");
77 all_badguys.push_back("totem");
78 all_badguys.push_back("walkingleaf");
79 all_badguys.push_back("willowisp");
80 all_badguys.push_back("yeti");
81 all_badguys.push_back("yeti_stalactite");
82 all_badguys.push_back("zeekling");
83 }
84
85 refresh_menu();
86}
87
88void
89BadguySelectMenu::refresh_menu()
90{
91 m_items.clear();
92
93 add_label(_("List of enemies"));
94 add_hl();
95 add_string_select(-2, _("Enemy"), &selected, all_badguys);
96 add_entry(-3, _("Add"));
97 add_hl();
98
99 int i = 0;
100 for (auto& badguy : *badguys) {
101 add_entry(i, badguy);
102 i++;
103 }
104
105 add_hl();
106 add_back(_("OK"));
107}
108
109void
110BadguySelectMenu::remove_badguy()
111{
112 badguys->erase(badguys->begin() + remove_item);
113 refresh_menu();
114 if (m_items[m_active_item]->skippable()) {
115 //We are on the bottom headline.
116 m_active_item++;
117 }
118}
119
120void
121BadguySelectMenu::add_badguy()
122{
123 badguys->push_back(all_badguys[selected]);
124 refresh_menu();
125}
126
127void
128BadguySelectMenu::menu_action(MenuItem& item)
129{
130 if (item.get_id() >= 0) {
131 remove_item = item.get_id();
132 auto self = this;
133 // confirmation dialog
134 auto dialog = std::make_unique<Dialog>();
135 dialog->set_text(_("Do you want to delete this badguy from the list?"));
136 dialog->add_default_button(_("Yes"), [self] {
137 self->remove_badguy();
138 });
139 dialog->add_cancel_button(_("No"));
140 MenuManager::instance().set_dialog(std::move(dialog));
141 } else if (item.get_id() == -3) {
142 add_badguy();
143 }
144}
145
146/* EOF */
147