Added WorldmapCheatMenu (grow/fire/snow/etc., mark levels as solved)
authorIngo Ruhnke <grumbel@gmail.com>
Fri, 15 Aug 2014 20:44:50 +0000 (22:44 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Fri, 15 Aug 2014 20:44:50 +0000 (22:44 +0200)
src/supertux/menu/menu_storage.cpp
src/supertux/menu/menu_storage.hpp
src/supertux/menu/worldmap_cheat_menu.cpp [new file with mode: 0644]
src/supertux/menu/worldmap_cheat_menu.hpp [new file with mode: 0644]
src/worldmap/level.cpp
src/worldmap/level.hpp
src/worldmap/worldmap.cpp
src/worldmap/worldmap.hpp

index da69440..daf0474 100644 (file)
@@ -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<Menu>(new WorldmapMenu);
 
+    case WORLDMAP_CHEAT_MENU:
+      return std::unique_ptr<Menu>(new WorldmapCheatMenu);
+
     case GAME_MENU:
       return std::unique_ptr<Menu>(new GameMenu);
 
index d88e931..dbd622d 100644 (file)
@@ -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 (file)
index 0000000..f566b07
--- /dev/null
@@ -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 */
diff --git a/src/supertux/menu/worldmap_cheat_menu.hpp b/src/supertux/menu/worldmap_cheat_menu.hpp
new file mode 100644 (file)
index 0000000..15433df
--- /dev/null
@@ -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 */
index dd4dbef..997f709 100644 (file)
@@ -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 */
index c71aa39..7c3ed78 100644 (file)
@@ -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"
@@ -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;
index 5b69ad2..12ffc5d 100644 (file)
@@ -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;
index d0d15d5..b0e56ac 100644 (file)
@@ -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);