Updated addon repository URL and improved debug output on download
[supertux.git] / src / supertux / menu / cheat_menu.cpp
1 //  SuperTux
2 //  Copyright (C) 2014 Ingo Ruhnke <grumbel@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 "supertux/menu/cheat_menu.hpp"
18
19 #include "gui/menu_item.hpp"
20 #include "gui/menu_manager.hpp"
21 #include "object/player.hpp"
22 #include "supertux/game_session.hpp"
23 #include "supertux/player_status.hpp"
24 #include "supertux/sector.hpp"
25 #include "util/gettext.hpp"
26
27 CheatMenu::CheatMenu()
28 {
29   add_label(_("Cheats"));
30   add_hl();
31   add_entry(MNID_GROW, _("Bonus: Grow"));
32   add_entry(MNID_FIRE, _("Bonus: Fire"));
33   add_entry(MNID_ICE, _("Bonus: Ice"));
34   add_entry(MNID_AIR, _("Bonus: Air"));
35   add_entry(MNID_EARTH, _("Bonus: Earth"));
36   add_entry(MNID_STAR, _("Bonus: Star"));
37   add_entry(MNID_SHRINK, _("Shrink Tux"));
38   add_entry(MNID_KILL, _("Kill Tux"));
39   add_entry(MNID_FINISH, _("Finish Level"));
40   add_hl();
41   add_back(_("Back"));
42 }
43
44 void
45 CheatMenu::menu_action(MenuItem* item)
46 {
47   if (Sector::current())
48   {
49     std::vector<Player*> players = Sector::current()->get_players();
50     Player* player = players.empty() ? nullptr : players[0];
51
52     switch(item->id)
53     {
54       case MNID_GROW:
55         if (player)
56         {
57           player->set_bonus(GROWUP_BONUS);
58         }
59         break;
60
61       case MNID_FIRE:
62         if (player)
63         {
64           player->set_bonus(FIRE_BONUS);
65         }
66         break;
67
68       case MNID_ICE:
69         if (player)
70         {
71           player->set_bonus(ICE_BONUS);
72         }
73         break;
74
75       case MNID_AIR:
76         if (player)
77         {
78           player->set_bonus(AIR_BONUS);
79         }
80         break;
81
82       case MNID_EARTH:
83         if (player)
84         {
85           player->set_bonus(EARTH_BONUS);
86         }
87         break;
88
89       case MNID_STAR:
90         if (player)
91         {
92           player->make_invincible();
93         }
94         break;
95
96       case MNID_SHRINK:
97         if (player)
98         {
99           player->kill(false);
100         }
101         break;
102
103       case MNID_KILL:
104         if (player)
105         {
106           player->kill(true);
107         }
108         break;
109
110       case MNID_FINISH:
111         if (GameSession::current())
112         {
113           GameSession::current()->finish(true);
114         }
115         break;
116
117       default:
118         break;
119     }
120   }
121
122   MenuManager::instance().clear_menu_stack();
123 }
124
125 /* EOF */