00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "supertux/menu/keyboard_menu.hpp"
00019
00020 #include "util/gettext.hpp"
00021 #include "supertux/gameconfig.hpp"
00022 #include "supertux/globals.hpp"
00023
00024 KeyboardMenu::KeyboardMenu(JoystickKeyboardController* _controller) :
00025 controller(_controller)
00026 {
00027 add_label(_("Setup Keyboard"));
00028 add_hl();
00029 add_controlfield(Controller::UP, _("Up"));
00030 add_controlfield(Controller::DOWN, _("Down"));
00031 add_controlfield(Controller::LEFT, _("Left"));
00032 add_controlfield(Controller::RIGHT, _("Right"));
00033 add_controlfield(Controller::JUMP, _("Jump"));
00034 add_controlfield(Controller::ACTION, _("Action"));
00035 add_controlfield(Controller::PEEK_LEFT, _("Peek Left"));
00036 add_controlfield(Controller::PEEK_RIGHT, _("Peek Right"));
00037 add_controlfield(Controller::PEEK_UP, _("Peek Up"));
00038 add_controlfield(Controller::PEEK_DOWN, _("Peek Down"));
00039 if (g_config->console_enabled) {
00040 add_controlfield(Controller::CONSOLE, _("Console"));
00041 }
00042 add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up_kbd);
00043 add_hl();
00044 add_back(_("Back"));
00045 update();
00046 }
00047
00048 KeyboardMenu::~KeyboardMenu()
00049 {}
00050
00051 std::string
00052 KeyboardMenu::get_key_name(SDLKey key)
00053 {
00054 switch(key) {
00055 case SDLK_UNKNOWN:
00056 return _("None");
00057 case SDLK_UP:
00058 return _("Up cursor");
00059 case SDLK_DOWN:
00060 return _("Down cursor");
00061 case SDLK_LEFT:
00062 return _("Left cursor");
00063 case SDLK_RIGHT:
00064 return _("Right cursor");
00065 case SDLK_RETURN:
00066 return _("Return");
00067 case SDLK_SPACE:
00068 return _("Space");
00069 case SDLK_RSHIFT:
00070 return _("Right Shift");
00071 case SDLK_LSHIFT:
00072 return _("Left Shift");
00073 case SDLK_RCTRL:
00074 return _("Right Control");
00075 case SDLK_LCTRL:
00076 return _("Left Control");
00077 case SDLK_RALT:
00078 return _("Right Alt");
00079 case SDLK_LALT:
00080 return _("Left Alt");
00081 default:
00082 return SDL_GetKeyName((SDLKey) key);
00083 }
00084 }
00085
00086 void
00087 KeyboardMenu::menu_action(MenuItem* item)
00088 {
00089 if(item->id >= 0 && item->id < Controller::CONTROLCOUNT){
00090 item->change_input(_("Press Key"));
00091 controller->wait_for_key = item->id;
00092 } else if( item->id == Controller::CONTROLCOUNT) {
00093 controller->jump_with_up_kbd = item->toggled;
00094 }
00095 }
00096
00097 void
00098 KeyboardMenu::update()
00099 {
00100
00101 get_item_by_id((int) Controller::UP).change_input(get_key_name(
00102 controller->reversemap_key(Controller::UP)));
00103 get_item_by_id((int) Controller::DOWN).change_input(get_key_name(
00104 controller->reversemap_key(Controller::DOWN)));
00105 get_item_by_id((int) Controller::LEFT).change_input(get_key_name(
00106 controller->reversemap_key(Controller::LEFT)));
00107 get_item_by_id((int) Controller::RIGHT).change_input(get_key_name(
00108 controller->reversemap_key(Controller::RIGHT)));
00109 get_item_by_id((int) Controller::JUMP).change_input(get_key_name(
00110 controller->reversemap_key(Controller::JUMP)));
00111 get_item_by_id((int) Controller::ACTION).change_input(get_key_name(
00112 controller->reversemap_key(Controller::ACTION)));
00113 get_item_by_id((int) Controller::PEEK_LEFT).change_input(get_key_name(
00114 controller->reversemap_key(Controller::PEEK_LEFT)));
00115 get_item_by_id((int) Controller::PEEK_RIGHT).change_input(get_key_name(
00116 controller->reversemap_key(Controller::PEEK_RIGHT)));
00117 get_item_by_id((int) Controller::PEEK_UP).change_input(get_key_name(
00118 controller->reversemap_key(Controller::PEEK_UP)));
00119 get_item_by_id((int) Controller::PEEK_DOWN).change_input(get_key_name(
00120 controller->reversemap_key(Controller::PEEK_DOWN)));
00121 if (g_config->console_enabled) {
00122 get_item_by_id((int) Controller::CONSOLE).change_input(get_key_name(
00123 controller->reversemap_key(Controller::CONSOLE)));
00124 }
00125 get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_kbd;
00126 }
00127
00128