f31d80d475d439e937d8b5e2e6117155ed96a0f0
[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_STAR, _("Bonus: Star"));
35   add_entry(MNID_SHRINK, _("Shrink Tux"));
36   add_entry(MNID_KILL, _("Kill Tux"));
37   add_entry(MNID_FINISH, _("Finish Level"));
38   add_hl();
39   add_back(_("Back"));
40 }
41
42 void
43 CheatMenu::menu_action(MenuItem* item)
44 {
45   if (Sector::current())
46   {
47     std::vector<Player*> players = Sector::current()->get_players();
48     Player* player = players.empty() ? nullptr : players[0];
49
50     switch(item->id)
51     {
52       case MNID_GROW:
53         if (player)
54         {
55           player->set_bonus(GROWUP_BONUS);
56         }
57         break;
58
59       case MNID_FIRE:
60         if (player)
61         {
62           player->set_bonus(FIRE_BONUS);
63         }
64         break;
65
66       case MNID_ICE:
67         if (player)
68         {
69           player->set_bonus(ICE_BONUS);
70         }
71         break;
72
73       case MNID_STAR:
74         if (player)
75         {
76           player->make_invincible();
77         }
78         break;
79
80       case MNID_SHRINK:
81         if (player)
82         {
83           player->kill(false);
84         }
85         break;
86
87       case MNID_KILL:
88         if (player)
89         {
90           player->kill(true);
91         }
92         break;
93
94       case MNID_FINISH:
95         if (GameSession::current())
96         {
97           GameSession::current()->finish(true);
98         }
99         break;
100
101       default:
102         break;
103     }
104   }
105
106   MenuManager::instance().clear_menu_stack();
107 }
108
109 /* EOF */