Updated addon repository URL and improved debug output on download
[supertux.git] / src / supertux / menu / worldmap_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/worldmap_cheat_menu.hpp"
18
19 #include "gui/menu_item.hpp"
20 #include "gui/menu_manager.hpp"
21 #include "supertux/player_status.hpp"
22 #include "supertux/savegame.hpp"
23 #include "util/gettext.hpp"
24 #include "worldmap/level.hpp"
25 #include "worldmap/worldmap.hpp"
26
27 WorldmapCheatMenu::WorldmapCheatMenu()
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_SHRINK, _("Bonus: None"));
37   add_hl();
38   add_entry(MNID_FINISH_LEVEL, _("Finish Level"));
39   add_entry(MNID_RESET_LEVEL, _("Reset Level"));
40   add_hl();
41   add_entry(MNID_FINISH_WORLDMAP, _("Finish WorldMap"));
42   add_entry(MNID_RESET_WORLDMAP, _("Reset WorldMap"));
43   add_hl();
44   add_back(_("Back"));
45 }
46
47 void
48 WorldmapCheatMenu::menu_action(MenuItem* item)
49 {
50   worldmap::WorldMap* worldmap = worldmap::WorldMap::current();
51   if (!worldmap)
52   {
53     log_warning << "couldn't access WorldMap::current()" << std::endl;
54   }
55   else
56   {
57     PlayerStatus* status = worldmap->get_savegame().get_player_status();
58
59     switch(item->id)
60     {
61       case MNID_GROW:
62         status->bonus = GROWUP_BONUS;
63         break;
64
65       case MNID_FIRE:
66         status->bonus = FIRE_BONUS;
67         break;
68
69       case MNID_ICE:
70         status->bonus = ICE_BONUS;
71         break;
72
73       case MNID_AIR:
74         status->bonus = AIR_BONUS;
75         break;
76
77       case MNID_EARTH:
78         status->bonus = EARTH_BONUS;
79         break;
80
81       case MNID_SHRINK:
82         status->bonus = NO_BONUS;
83         break;
84
85       case MNID_FINISH_LEVEL:
86         {
87           worldmap::LevelTile* level_tile = worldmap->at_level();
88           if (level_tile)
89           {
90             level_tile->set_solved(true);
91             level_tile->set_perfect(false);
92           }
93         }
94         break;
95
96       case MNID_RESET_LEVEL:
97         {
98           worldmap::LevelTile* level_tile = worldmap->at_level();
99           if (level_tile)
100           {
101             level_tile->set_solved(false);
102             level_tile->set_perfect(false);
103           }
104         }
105         break;
106
107       case MNID_FINISH_WORLDMAP:
108         worldmap->set_levels_solved(true, false);
109         break;
110
111       case MNID_RESET_WORLDMAP:
112         worldmap->set_levels_solved(false, false);
113         break;
114     }
115   }
116
117   MenuManager::instance().clear_menu_stack();
118 }
119
120 /* EOF */