From bcc444220e4b3a383bbf51757a71dae1f39361ed Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Fri, 15 Aug 2014 22:44:50 +0200 Subject: [PATCH] Added WorldmapCheatMenu (grow/fire/snow/etc., mark levels as solved) --- src/supertux/menu/menu_storage.cpp | 4 ++ src/supertux/menu/menu_storage.hpp | 1 + src/supertux/menu/worldmap_cheat_menu.cpp | 110 ++++++++++++++++++++++++++++++ src/supertux/menu/worldmap_cheat_menu.hpp | 49 +++++++++++++ src/worldmap/level.cpp | 31 +++++++++ src/worldmap/level.hpp | 7 ++ src/worldmap/worldmap.cpp | 17 +++++ src/worldmap/worldmap.hpp | 5 ++ 8 files changed, 224 insertions(+) create mode 100644 src/supertux/menu/worldmap_cheat_menu.cpp create mode 100644 src/supertux/menu/worldmap_cheat_menu.hpp diff --git a/src/supertux/menu/menu_storage.cpp b/src/supertux/menu/menu_storage.cpp index da69440b0..daf0474fe 100644 --- a/src/supertux/menu/menu_storage.cpp +++ b/src/supertux/menu/menu_storage.cpp @@ -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; @@ -78,6 +79,9 @@ MenuStorage::create(MenuId menu_id) case WORLDMAP_MENU: return std::unique_ptr(new WorldmapMenu); + case WORLDMAP_CHEAT_MENU: + return std::unique_ptr(new WorldmapCheatMenu); + case GAME_MENU: return std::unique_ptr(new GameMenu); diff --git a/src/supertux/menu/menu_storage.hpp b/src/supertux/menu/menu_storage.hpp index d88e931d6..dbd622d30 100644 --- a/src/supertux/menu/menu_storage.hpp +++ b/src/supertux/menu/menu_storage.hpp @@ -46,6 +46,7 @@ public: KEYBOARD_MENU, JOYSTICK_MENU, WORLDMAP_MENU, + WORLDMAP_CHEAT_MENU, GAME_MENU, CHEAT_MENU }; diff --git a/src/supertux/menu/worldmap_cheat_menu.cpp b/src/supertux/menu/worldmap_cheat_menu.cpp new file mode 100644 index 000000000..f566b0748 --- /dev/null +++ b/src/supertux/menu/worldmap_cheat_menu.cpp @@ -0,0 +1,110 @@ +// SuperTux +// Copyright (C) 2014 Ingo Ruhnke +// +// 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 . + +#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 */ diff --git a/src/supertux/menu/worldmap_cheat_menu.hpp b/src/supertux/menu/worldmap_cheat_menu.hpp new file mode 100644 index 000000000..15433df37 --- /dev/null +++ b/src/supertux/menu/worldmap_cheat_menu.hpp @@ -0,0 +1,49 @@ +// SuperTux +// Copyright (C) 2014 Ingo Ruhnke +// +// 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 . + +#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 */ diff --git a/src/worldmap/level.cpp b/src/worldmap/level.cpp index dd4dbef12..997f70994 100644 --- a/src/worldmap/level.cpp +++ b/src/worldmap/level.cpp @@ -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 */ diff --git a/src/worldmap/level.hpp b/src/worldmap/level.hpp index c71aa393a..7c3ed78c6 100644 --- a/src/worldmap/level.hpp +++ b/src/worldmap/level.hpp @@ -22,6 +22,7 @@ #include #include "math/vector.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/game_object.hpp" #include "supertux/statistics.hpp" #include "video/surface.hpp" @@ -39,6 +40,12 @@ public: 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; diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 5b69ad238..12ffc5de9 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -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()); @@ -953,6 +960,16 @@ WorldMap::leave() } 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() { using namespace scripting; diff --git a/src/worldmap/worldmap.hpp b/src/worldmap/worldmap.hpp index d0d15d576..b0e56acd0 100644 --- a/src/worldmap/worldmap.hpp +++ b/src/worldmap/worldmap.hpp @@ -220,6 +220,11 @@ public: */ 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); -- 2.11.0