From 62c7184852705b067674e8c8832ce2a3675974f3 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Wed, 21 Apr 2004 17:45:17 +0000 Subject: [PATCH] Made the keys to be displayed when typed and also save them to the file. Still to fix: display keys when menu is shown. SVN-Revision: 614 --- src/configfile.cpp | 13 +++++++++++++ src/menu.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/configfile.cpp b/src/configfile.cpp index c415d136b..df637ec25 100644 --- a/src/configfile.cpp +++ b/src/configfile.cpp @@ -23,6 +23,7 @@ #include "setup.h" #include "globals.h" #include "lispreader.h" +#include "player.h" #ifdef WIN32 const char * config_filename = "/st_config.dat"; @@ -97,6 +98,12 @@ void loadconfig(void) reader.read_int ("joystick-b", &joystick_keymap.b_button); reader.read_int ("joystick-start", &joystick_keymap.start_button); reader.read_int ("joystick-deadzone", &joystick_keymap.dead_zone); + + reader.read_int ("keyboard-jump", &keymap.jump); + reader.read_int ("keyboard-duck", &keymap.duck); + reader.read_int ("keyboard-left", &keymap.left); + reader.read_int ("keyboard-right", &keymap.right); + reader.read_int ("keyboard-fire", &keymap.fire); } void saveconfig (void) @@ -127,6 +134,12 @@ void saveconfig (void) fprintf(config, "\t(joystick-start %d)\n", joystick_keymap.start_button); fprintf(config, "\t(joystick-deadzone %d)\n", joystick_keymap.dead_zone); + fprintf(config, "\t(keyboard-jump %d)\n", keymap.jump); + fprintf(config, "\t(keyboard-duck %d)\n", keymap.duck); + fprintf(config, "\t(keyboard-left %d)\n", keymap.left); + fprintf(config, "\t(keyboard-right %d)\n", keymap.right); + fprintf(config, "\t(keyboard-fire %d)\n", keymap.fire); + fprintf(config, ")\n"); } } diff --git a/src/menu.cpp b/src/menu.cpp index 1cfb5a0f4..079e85d9e 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -443,6 +443,7 @@ Menu::draw_item(int index, // Position of the current item in the menu } case MN_TEXTFIELD: case MN_NUMFIELD: + case MN_CONTROLFIELD: { int input_pos = input_width/2; int text_pos = (text_width + font_width)/2; @@ -463,10 +464,10 @@ Menu::draw_item(int index, // Position of the current item in the menu A_HMIDDLE, A_VMIDDLE, shadow_size); break; } - case MN_CONTROLFIELD: - { +// case MN_CONTROLFIELD: +// { /* display key */ // FIXME: the key number is not that obvious to the user :P - char str[12]; +/* char str[12]; sprintf(str, "%i", *pitem.int_p); input_width = strlen(str) * font_width; @@ -488,7 +489,7 @@ Menu::draw_item(int index, // Position of the current item in the menu x_pos - (input_width + font_width)/2, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); break; - } + }*/ case MN_STRINGSELECT: { int list_pos_2 = list_width + font_width; @@ -619,6 +620,52 @@ Menu::event(SDL_Event& event) if(item[active_item].kind == MN_CONTROLFIELD) { *item[active_item].int_p = event.key.keysym.unicode; + if(ch[0] != '\0') + strcpy(item[active_item].input, ch); + else + switch(key) + { + case SDLK_UP: + strcpy(item[active_item].input, "Up cursor"); + break; + case SDLK_DOWN: + strcpy(item[active_item].input, "Down cursor"); + break; + case SDLK_LEFT: + strcpy(item[active_item].input, "Left cursor"); + break; + case SDLK_RIGHT: + strcpy(item[active_item].input, "Right cursor"); + break; + case SDLK_RETURN: + strcpy(item[active_item].input, "Return"); + break; + case SDLK_SPACE: + strcpy(item[active_item].input, "Space"); + break; + case SDLK_RSHIFT: + strcpy(item[active_item].input, "Right Shift"); + break; + case SDLK_LSHIFT: + strcpy(item[active_item].input, "Left Shift"); + break; + case SDLK_RCTRL: + strcpy(item[active_item].input, "Right Control"); + break; + case SDLK_LCTRL: + strcpy(item[active_item].input, "Left Control"); + break; + case SDLK_RALT: + strcpy(item[active_item].input, "Right Alt"); + break; + case SDLK_LALT: + strcpy(item[active_item].input, "Left Alt"); + break; + default: + strcpy(item[active_item].input, "?"); + break; + } + menuaction = MENU_ACTION_DOWN; return; } -- 2.11.0