From: Ingo Ruhnke Date: Fri, 15 Aug 2014 07:43:41 +0000 (+0200) Subject: Added simple cheat menu to grow/fire/ice/shrink/... Tux X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1f40c3162dad16f31085234080f5fad3c4d7a8c7;p=supertux.git Added simple cheat menu to grow/fire/ice/shrink/... Tux --- diff --git a/src/control/controller.cpp b/src/control/controller.cpp index 6a3882e56..a25c39bdc 100644 --- a/src/control/controller.cpp +++ b/src/control/controller.cpp @@ -26,6 +26,7 @@ const char* Controller::controlNames[] = { "pause-menu", "menu-select", "menu-back", + "cheat-menu", "console", "peek-left", "peek-right", diff --git a/src/control/controller.hpp b/src/control/controller.hpp index b73695d5c..8d8543e6a 100644 --- a/src/control/controller.hpp +++ b/src/control/controller.hpp @@ -35,6 +35,7 @@ public: MENU_SELECT, MENU_BACK, + CHEAT_MENU, CONSOLE, PEEK_LEFT, diff --git a/src/control/game_controller_manager.cpp b/src/control/game_controller_manager.cpp index e7ca81d8a..4c9ccbf15 100644 --- a/src/control/game_controller_manager.cpp +++ b/src/control/game_controller_manager.cpp @@ -67,10 +67,11 @@ GameControllerManager::process_button_event(const SDL_ControllerButtonEvent& ev) break; case SDL_CONTROLLER_BUTTON_BACK: + set_control(Controller::CONSOLE, ev.state); break; case SDL_CONTROLLER_BUTTON_GUIDE: - set_control(Controller::CONSOLE, ev.state); + set_control(Controller::CHEAT_MENU, ev.state); break; case SDL_CONTROLLER_BUTTON_START: diff --git a/src/control/keyboard_manager.cpp b/src/control/keyboard_manager.cpp index d46e4f624..0fe55b68a 100644 --- a/src/control/keyboard_manager.cpp +++ b/src/control/keyboard_manager.cpp @@ -51,6 +51,7 @@ KeyboardManager::KeyboardManager(InputManager* parent) : keymap[SDLK_PAGEDOWN] = Controller::PEEK_RIGHT; keymap[SDLK_HOME] = Controller::PEEK_UP; keymap[SDLK_END] = Controller::PEEK_DOWN; + keymap[SDLK_TAB] = Controller::CHEAT_MENU; } KeyboardManager::~KeyboardManager() diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index 8fb7427e9..3ddedfcf7 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -417,7 +417,15 @@ GameSession::update(float elapsed_time) { // handle controller if(g_input_manager->get_controller()->pressed(Controller::PAUSE_MENU)) + { on_escape_press(); + } + + if(g_input_manager->get_controller()->pressed(Controller::CHEAT_MENU)) + { + game_pause = true; + MenuManager::instance().set_menu(MenuStorage::CHEAT_MENU); + } process_events(); MenuManager::instance().check_menu(); diff --git a/src/supertux/menu/cheat_menu.cpp b/src/supertux/menu/cheat_menu.cpp new file mode 100644 index 000000000..f31d80d47 --- /dev/null +++ b/src/supertux/menu/cheat_menu.cpp @@ -0,0 +1,109 @@ +// 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/cheat_menu.hpp" + +#include "gui/menu_item.hpp" +#include "gui/menu_manager.hpp" +#include "object/player.hpp" +#include "supertux/game_session.hpp" +#include "supertux/player_status.hpp" +#include "supertux/sector.hpp" +#include "util/gettext.hpp" + +CheatMenu::CheatMenu() +{ + 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_STAR, _("Bonus: Star")); + add_entry(MNID_SHRINK, _("Shrink Tux")); + add_entry(MNID_KILL, _("Kill Tux")); + add_entry(MNID_FINISH, _("Finish Level")); + add_hl(); + add_back(_("Back")); +} + +void +CheatMenu::menu_action(MenuItem* item) +{ + if (Sector::current()) + { + std::vector players = Sector::current()->get_players(); + Player* player = players.empty() ? nullptr : players[0]; + + switch(item->id) + { + case MNID_GROW: + if (player) + { + player->set_bonus(GROWUP_BONUS); + } + break; + + case MNID_FIRE: + if (player) + { + player->set_bonus(FIRE_BONUS); + } + break; + + case MNID_ICE: + if (player) + { + player->set_bonus(ICE_BONUS); + } + break; + + case MNID_STAR: + if (player) + { + player->make_invincible(); + } + break; + + case MNID_SHRINK: + if (player) + { + player->kill(false); + } + break; + + case MNID_KILL: + if (player) + { + player->kill(true); + } + break; + + case MNID_FINISH: + if (GameSession::current()) + { + GameSession::current()->finish(true); + } + break; + + default: + break; + } + } + + MenuManager::instance().clear_menu_stack(); +} + +/* EOF */ diff --git a/src/supertux/menu/cheat_menu.hpp b/src/supertux/menu/cheat_menu.hpp new file mode 100644 index 000000000..708b2d838 --- /dev/null +++ b/src/supertux/menu/cheat_menu.hpp @@ -0,0 +1,48 @@ +// 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_CHEAT_MENU_HPP +#define HEADER_SUPERTUX_SUPERTUX_MENU_CHEAT_MENU_HPP + +#include "gui/menu.hpp" + +class CheatMenu : public Menu +{ +private: + enum MenuIDs { + MNID_GROW, + MNID_FIRE, + MNID_ICE, + MNID_STAR, + MNID_SHRINK, + MNID_KILL, + MNID_FINISH + }; + +public: + CheatMenu(); + + void menu_action(MenuItem* item) override; + void check_menu() override {} + +private: + CheatMenu(const CheatMenu&) = delete; + CheatMenu& operator=(const CheatMenu&) = delete; +}; + +#endif + +/* EOF */ diff --git a/src/supertux/menu/menu_storage.cpp b/src/supertux/menu/menu_storage.cpp index a0706ffa0..da69440b0 100644 --- a/src/supertux/menu/menu_storage.cpp +++ b/src/supertux/menu/menu_storage.cpp @@ -18,6 +18,7 @@ #include "supertux/globals.hpp" #include "supertux/menu/addon_menu.hpp" +#include "supertux/menu/cheat_menu.hpp" #include "supertux/menu/contrib_menu.hpp" #include "supertux/menu/game_menu.hpp" #include "supertux/menu/joystick_menu.hpp" @@ -80,6 +81,9 @@ MenuStorage::create(MenuId menu_id) case GAME_MENU: return std::unique_ptr(new GameMenu); + case CHEAT_MENU: + return std::unique_ptr(new CheatMenu); + case CONTRIB_MENU: return std::unique_ptr(new ContribMenu); diff --git a/src/supertux/menu/menu_storage.hpp b/src/supertux/menu/menu_storage.hpp index 44aaf5160..d88e931d6 100644 --- a/src/supertux/menu/menu_storage.hpp +++ b/src/supertux/menu/menu_storage.hpp @@ -46,7 +46,8 @@ public: KEYBOARD_MENU, JOYSTICK_MENU, WORLDMAP_MENU, - GAME_MENU + GAME_MENU, + CHEAT_MENU }; public: