Skip to content

Commit

Permalink
Added WorldmapCheatMenu (grow/fire/snow/etc., mark levels as solved)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Aug 15, 2014
1 parent 3150aa2 commit bcc4442
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/supertux/menu/menu_storage.cpp
Expand Up @@ -28,6 +28,7 @@
#include "supertux/menu/options_menu.hpp"
#include "supertux/menu/profile_menu.hpp"
#include "supertux/menu/worldmap_menu.hpp"
#include "supertux/menu/worldmap_cheat_menu.hpp"

MenuStorage* MenuStorage::s_instance = 0;

Expand Down Expand Up @@ -78,6 +79,9 @@ MenuStorage::create(MenuId menu_id)
case WORLDMAP_MENU:
return std::unique_ptr<Menu>(new WorldmapMenu);

case WORLDMAP_CHEAT_MENU:
return std::unique_ptr<Menu>(new WorldmapCheatMenu);

case GAME_MENU:
return std::unique_ptr<Menu>(new GameMenu);

Expand Down
1 change: 1 addition & 0 deletions src/supertux/menu/menu_storage.hpp
Expand Up @@ -46,6 +46,7 @@ class MenuStorage
KEYBOARD_MENU,
JOYSTICK_MENU,
WORLDMAP_MENU,
WORLDMAP_CHEAT_MENU,
GAME_MENU,
CHEAT_MENU
};
Expand Down
110 changes: 110 additions & 0 deletions src/supertux/menu/worldmap_cheat_menu.cpp
@@ -0,0 +1,110 @@
// SuperTux
// Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "supertux/menu/worldmap_cheat_menu.hpp"

#include "gui/menu_item.hpp"
#include "gui/menu_manager.hpp"
#include "supertux/player_status.hpp"
#include "supertux/savegame.hpp"
#include "util/gettext.hpp"
#include "worldmap/level.hpp"
#include "worldmap/worldmap.hpp"

WorldmapCheatMenu::WorldmapCheatMenu()
{
add_label(_("Cheats"));
add_hl();
add_entry(MNID_GROW, _("Bonus: Grow"));
add_entry(MNID_FIRE, _("Bonus: Fire"));
add_entry(MNID_ICE, _("Bonus: Ice"));
add_entry(MNID_SHRINK, _("Bonus: None"));
add_hl();
add_entry(MNID_FINISH_LEVEL, _("Finish Level"));
add_entry(MNID_RESET_LEVEL, _("Reset Level"));
add_hl();
add_entry(MNID_FINISH_WORLDMAP, _("Finish WorldMap"));
add_entry(MNID_RESET_WORLDMAP, _("Reset WorldMap"));
add_hl();
add_back(_("Back"));
}

void
WorldmapCheatMenu::menu_action(MenuItem* item)
{
worldmap::WorldMap* worldmap = worldmap::WorldMap::current();
if (!worldmap)
{
log_warning << "couldn't access WorldMap::current()" << std::endl;
}
else
{
PlayerStatus* status = worldmap->get_savegame().get_player_status();

switch(item->id)
{
case MNID_GROW:
status->bonus = GROWUP_BONUS;
break;

case MNID_FIRE:
status->bonus = FIRE_BONUS;
break;

case MNID_ICE:
status->bonus = ICE_BONUS;
break;

case MNID_SHRINK:
status->bonus = NO_BONUS;
break;

case MNID_FINISH_LEVEL:
{
worldmap::LevelTile* level_tile = worldmap->at_level();
if (level_tile)
{
level_tile->set_solved(true);
level_tile->set_perfect(false);
}
}
break;

case MNID_RESET_LEVEL:
{
worldmap::LevelTile* level_tile = worldmap->at_level();
if (level_tile)
{
level_tile->set_solved(false);
level_tile->set_perfect(false);
}
}
break;

case MNID_FINISH_WORLDMAP:
worldmap->set_levels_solved(true, false);
break;

case MNID_RESET_WORLDMAP:
worldmap->set_levels_solved(false, false);
break;
}
}

MenuManager::instance().clear_menu_stack();
}

/* EOF */
49 changes: 49 additions & 0 deletions src/supertux/menu/worldmap_cheat_menu.hpp
@@ -0,0 +1,49 @@
// SuperTux
// Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef HEADER_SUPERTUX_SUPERTUX_MENU_WORLDMAP_CHEAT_MENU_HPP
#define HEADER_SUPERTUX_SUPERTUX_MENU_WORLDMAP_CHEAT_MENU_HPP

#include "gui/menu.hpp"

class WorldmapCheatMenu : public Menu
{
private:
private:
enum MenuIDs {
MNID_GROW,
MNID_FIRE,
MNID_ICE,
MNID_SHRINK,
MNID_FINISH_LEVEL,
MNID_RESET_LEVEL,
MNID_FINISH_WORLDMAP,
MNID_RESET_WORLDMAP
};

public:
WorldmapCheatMenu();

void menu_action(MenuItem* item) override;

private:
WorldmapCheatMenu(const WorldmapCheatMenu&) = delete;
WorldmapCheatMenu& operator=(const WorldmapCheatMenu&) = delete;
};

#endif

/* EOF */
31 changes: 31 additions & 0 deletions src/worldmap/level.cpp
Expand Up @@ -78,6 +78,37 @@ LevelTile::update(float )
{
}

void
LevelTile::update_sprite_action()
{
if (perfect)
{
sprite->set_action("perfect");
}
else if (solved)
{
sprite->set_action("perfect");
}
else
{
sprite->set_action("default");
}
}

void
LevelTile::set_solved(bool v)
{
solved = v;
update_sprite_action();
}

void
LevelTile::set_perfect(bool v)
{
perfect = v;
update_sprite_action();
}

} // namespace worldmap

/* EOF */
7 changes: 7 additions & 0 deletions src/worldmap/level.hpp
Expand Up @@ -22,6 +22,7 @@
#include <string>

#include "math/vector.hpp"
#include "sprite/sprite_ptr.hpp"
#include "supertux/game_object.hpp"
#include "supertux/statistics.hpp"
#include "video/surface.hpp"
Expand All @@ -39,6 +40,12 @@ class LevelTile : public GameObject
virtual void draw(DrawingContext& context);
virtual void update(float elapsed_time);

void set_solved(bool v);
void set_perfect(bool v);

private:
void update_sprite_action();

public:
Vector pos;
std::string title;
Expand Down
17 changes: 17 additions & 0 deletions src/worldmap/worldmap.cpp
Expand Up @@ -642,7 +642,14 @@ WorldMap::update(float delta)
enter_level = true;
}
if(controller->pressed(Controller::PAUSE_MENU))
{
on_escape_press();
}

if(controller->pressed(Controller::CHEAT_MENU))
{
MenuManager::instance().set_menu(MenuStorage::WORLDMAP_CHEAT_MENU);
}

// check for teleporters
Teleporter* teleporter = at_teleporter(tux->get_tile_pos());
Expand Down Expand Up @@ -952,6 +959,16 @@ WorldMap::leave()
sq_pop(global_vm, 1);
}

void
WorldMap::set_levels_solved(bool solved, bool perfect)
{
for(auto& level : levels)
{
level->set_solved(solved);
level->set_perfect(perfect);
}
}

void
WorldMap::save_state()
{
Expand Down
5 changes: 5 additions & 0 deletions src/worldmap/worldmap.hpp
Expand Up @@ -220,6 +220,11 @@ class WorldMap : public Screen
*/
float get_height() const;

/**
* Mark all levels as solved or unsolved
*/
void set_levels_solved(bool solved, bool perfect);

private:
void get_level_title(LevelTile& level);
void get_level_target_time(LevelTile& level);
Expand Down

0 comments on commit bcc4442

Please sign in to comment.