2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>,
3 // 2007 Ingo Ruhnke <grumbel@gmail.com>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "supertux/menu/keyboard_menu.hpp"
20 #include "control/keyboard_manager.hpp"
21 #include "supertux/gameconfig.hpp"
22 #include "supertux/globals.hpp"
23 #include "util/gettext.hpp"
25 KeyboardMenu::KeyboardMenu(InputManager& input_manager) :
26 m_input_manager(input_manager)
28 add_label(_("Setup Keyboard"));
30 add_controlfield(Controller::UP, _("Up"));
31 add_controlfield(Controller::DOWN, _("Down"));
32 add_controlfield(Controller::LEFT, _("Left"));
33 add_controlfield(Controller::RIGHT, _("Right"));
34 add_controlfield(Controller::JUMP, _("Jump"));
35 add_controlfield(Controller::ACTION, _("Action"));
36 add_controlfield(Controller::PEEK_LEFT, _("Peek Left"));
37 add_controlfield(Controller::PEEK_RIGHT, _("Peek Right"));
38 add_controlfield(Controller::PEEK_UP, _("Peek Up"));
39 add_controlfield(Controller::PEEK_DOWN, _("Peek Down"));
40 if (g_config->console_enabled) {
41 add_controlfield(Controller::CONSOLE, _("Console"));
43 add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), g_config->keyboard_config.jump_with_up_kbd);
49 KeyboardMenu::~KeyboardMenu()
53 KeyboardMenu::get_key_name(SDL_Keycode key)
59 return _("Up cursor");
61 return _("Down cursor");
63 return _("Left cursor");
65 return _("Right cursor");
71 return _("Right Shift");
73 return _("Left Shift");
75 return _("Right Control");
77 return _("Left Control");
79 return _("Right Alt");
83 return _("Right Command");
85 return _("Left Command");
87 return SDL_GetKeyName((SDL_Keycode) key);
92 KeyboardMenu::menu_action(MenuItem* item)
94 if(item->id >= 0 && item->id < Controller::CONTROLCOUNT){
95 item->change_input(_("Press Key"));
96 m_input_manager.keyboard_manager->wait_for_key = item->id;
97 } else if( item->id == Controller::CONTROLCOUNT) {
98 g_config->keyboard_config.jump_with_up_kbd = item->toggled;
103 KeyboardMenu::refresh()
105 KeyboardConfig& kbd_cfg = g_config->keyboard_config;
107 get_item_by_id((int) Controller::UP)
108 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::UP)));
109 get_item_by_id((int) Controller::DOWN)
110 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::DOWN)));
111 get_item_by_id((int) Controller::LEFT)
112 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::LEFT)));
113 get_item_by_id((int) Controller::RIGHT)
114 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::RIGHT)));
115 get_item_by_id((int) Controller::JUMP)
116 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::JUMP)));
117 get_item_by_id((int) Controller::ACTION)
118 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::ACTION)));
119 get_item_by_id((int) Controller::PEEK_LEFT)
120 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::PEEK_LEFT)));
121 get_item_by_id((int) Controller::PEEK_RIGHT)
122 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::PEEK_RIGHT)));
123 get_item_by_id((int) Controller::PEEK_UP)
124 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::PEEK_UP)));
125 get_item_by_id((int) Controller::PEEK_DOWN)
126 .change_input(get_key_name(kbd_cfg.reversemap_key(Controller::PEEK_DOWN)));
128 if (g_config->console_enabled)
130 get_item_by_id((int) Controller::CONSOLE).change_input(get_key_name(
131 kbd_cfg.reversemap_key(Controller::CONSOLE)));
133 get_item_by_id(Controller::CONTROLCOUNT).toggled = kbd_cfg.jump_with_up_kbd;