From d805b06e883e19e0222fcb13a88780f89b6b0546 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Sat, 27 Mar 2004 17:24:14 +0000 Subject: [PATCH] more kinds of menu_event are handled directly in the menu-code now. SVN-Revision: 393 --- src/gameloop.cpp | 23 +++------ src/high_scores.cpp | 2 +- src/leveleditor.cpp | 2 +- src/menu.cpp | 136 ++++++++++++++++++++++++++++++---------------------- src/menu.h | 5 +- src/setup.cpp | 9 ++++ src/title.cpp | 15 +----- 7 files changed, 100 insertions(+), 92 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index f2e454e27..ba8ec364a 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -130,6 +130,9 @@ void game_event(void) { while (SDL_PollEvent(&event)) { + /* Check for menu-events, if the menu is shown */ + if(show_menu) + menu_event(event); switch(event.type) { case SDL_QUIT: /* Quit event - quit: */ @@ -138,10 +141,6 @@ void game_event(void) case SDL_KEYDOWN: /* A keypress! */ key = event.key.keysym.sym; - /* Check for menu-events, if the menu is shown */ - if(show_menu) - menu_event(&event.key.keysym); - if(tux.key_event(key,DOWN)) break; @@ -266,16 +265,8 @@ void game_event(void) tux.input.down = UP; else tux.input.down = UP; - - /* Handle joystick for the menu */ - if(show_menu) - { - if(tux.input.down == DOWN) - menuaction = MENU_ACTION_DOWN; - else - menuaction = MENU_ACTION_UP; - } - break; + + break; default: break; } @@ -291,9 +282,7 @@ void game_event(void) tux.input.up = UP; else if (event.jbutton.button == JOY_B) tux.input.fire = UP; - - if(show_menu) - menuaction = MENU_ACTION_HIT; + break; default: diff --git a/src/high_scores.cpp b/src/high_scores.cpp index 9d6e2f1f0..c435ad112 100644 --- a/src/high_scores.cpp +++ b/src/high_scores.cpp @@ -115,7 +115,7 @@ void save_hs(int score) while(SDL_PollEvent(&event)) if(event.type == SDL_KEYDOWN) - menu_event(&event.key.keysym); + menu_event(event); switch (highscore_menu->check()) { diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index aeb44e9e4..4889c1786 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -860,7 +860,7 @@ void le_checkevents() key = event.key.keysym.sym; if(show_menu) { - menu_event(&event.key.keysym); + menu_event(event); if(key == SDLK_ESCAPE) { show_menu = false; diff --git a/src/menu.cpp b/src/menu.cpp index 5f6d56156..a69dcfdb9 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -214,6 +214,7 @@ Menu::action() case MN_ACTION: case MN_TEXTFIELD: case MN_NUMFIELD: + case MN_CONTROLFIELD: item[active_item].toggled = true; break; @@ -376,6 +377,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; @@ -517,76 +519,94 @@ void menu_process_current(void) } /* Check for menu event */ -void menu_event(SDL_keysym* keysym) +void menu_event(SDL_Event& event) { - SDLKey key = keysym->sym; - SDLMod keymod; - char ch[2]; - keymod = SDL_GetModState(); - - /* If the current unicode character is an ASCII character, - assign it to ch. */ - if ( (keysym->unicode & 0xFF80) == 0 ) + SDLKey key; + switch(event.type) { - ch[0] = keysym->unicode & 0x7F; - ch[1] = '\0'; - } - else - { - /* An International Character. */ - } + case SDL_KEYDOWN: + key = event.key.keysym.sym; + SDLMod keymod; + char ch[2]; + keymod = SDL_GetModState(); + + /* If the current unicode character is an ASCII character, + assign it to ch. */ + if ( (event.key.keysym.unicode & 0xFF80) == 0 ) + { + ch[0] = event.key.keysym.unicode & 0x7F; + ch[1] = '\0'; + } + else + { + /* An International Character. */ + } - switch(key) - { - case SDLK_UP: /* Menu Up */ - menuaction = MENU_ACTION_UP; - menu_change = true; - break; - case SDLK_DOWN: /* Menu Down */ - menuaction = MENU_ACTION_DOWN; - menu_change = true; - break; - case SDLK_LEFT: /* Menu Up */ - menuaction = MENU_ACTION_LEFT; - menu_change = true; - break; - case SDLK_RIGHT: /* Menu Down */ - menuaction = MENU_ACTION_RIGHT; - menu_change = true; - break; - case SDLK_SPACE: - if(current_menu->item[current_menu->active_item].kind == MN_TEXTFIELD) + switch(key) { - menuaction = MENU_ACTION_INPUT; + case SDLK_UP: /* Menu Up */ + menuaction = MENU_ACTION_UP; menu_change = true; - mn_input_char = ' '; break; - } - case SDLK_RETURN: /* Menu Hit */ - menuaction = MENU_ACTION_HIT; - menu_change = true; - break; - case SDLK_DELETE: - case SDLK_BACKSPACE: - menuaction = MENU_ACTION_REMOVE; - menu_change = true; - delete_character++; - break; - default: - if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH)) - { - menuaction = MENU_ACTION_INPUT; + case SDLK_DOWN: /* Menu Down */ + menuaction = MENU_ACTION_DOWN; menu_change = true; - mn_input_char = *ch; + break; + case SDLK_LEFT: /* Menu Up */ + menuaction = MENU_ACTION_LEFT; + menu_change = true; + break; + case SDLK_RIGHT: /* Menu Down */ + menuaction = MENU_ACTION_RIGHT; + menu_change = true; + break; + case SDLK_SPACE: + if(current_menu->item[current_menu->active_item].kind == MN_TEXTFIELD) + { + menuaction = MENU_ACTION_INPUT; + menu_change = true; + mn_input_char = ' '; + break; + } + case SDLK_RETURN: /* Menu Hit */ + menuaction = MENU_ACTION_HIT; + menu_change = true; + break; + case SDLK_DELETE: + case SDLK_BACKSPACE: + menuaction = MENU_ACTION_REMOVE; + menu_change = true; + delete_character++; + break; + default: + if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH)) + { + menuaction = MENU_ACTION_INPUT; + menu_change = true; + mn_input_char = *ch; + } + else + { + mn_input_char = '\0'; + } + break; } - else + break; + case SDL_JOYAXISMOTION: + if(event.jaxis.axis == JOY_Y) { - mn_input_char = '\0'; + if (event.jaxis.value > 1024) + menuaction = MENU_ACTION_DOWN; + else if (event.jaxis.value < -1024) + menuaction = MENU_ACTION_UP; } break; + case SDL_JOYBUTTONDOWN: + menuaction = MENU_ACTION_HIT; + break; + default: + break; } - - /* FIXME: NO JOYSTICK SUPPORT */ /*#ifdef JOY_YES else if (event.type == SDL_JOYBUTTONDOWN) diff --git a/src/menu.h b/src/menu.h index 7f50c6f7c..15d4e08c4 100644 --- a/src/menu.h +++ b/src/menu.h @@ -27,9 +27,10 @@ enum MenuItemKind { MN_DEACTIVE, MN_TEXTFIELD, MN_NUMFIELD, + MN_CONTROLFIELD, MN_STRINGSELECT, MN_LABEL, - MN_HL /* horizontal line */ + MN_HL, /* horizontal line */ }; class Menu; @@ -116,7 +117,7 @@ void menu_reset(void); void menu_process_current(void); /* Check for a menu event */ -void menu_event(SDL_keysym* keysym); +void menu_event(SDL_Event& event); #endif /*SUPERTUX_MENU_H*/ diff --git a/src/setup.cpp b/src/setup.cpp index 039edc7d7..8b5a52dd0 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -38,6 +38,7 @@ #include "menu.h" #include "gameloop.h" #include "configfile.h" +#include "scene.h" #ifdef WIN32 #define mkdir(dir, mode) mkdir(dir) @@ -352,6 +353,7 @@ void st_menu(void) { main_menu = new Menu(); options_menu = new Menu(); + options_controls_menu = new Menu(); load_game_menu = new Menu(); save_game_menu = new Menu(); game_menu = new Menu(); @@ -381,8 +383,15 @@ void st_menu(void) options_menu->additem(MN_DEACTIVE,"Music ",use_music,0); } options_menu->additem(MN_TOGGLE,"Show FPS ",show_fps,0); + options_menu->additem(MN_GOTO,"Controls ",0,options_controls_menu); options_menu->additem(MN_HL,"",0,0); options_menu->additem(MN_BACK,"Back",0,0); + + options_controls_menu->additem(MN_LABEL,"Controls",0,0); + options_controls_menu->additem(MN_HL,"",0,0); + options_controls_menu->additem(MN_CONTROLFIELD,"Move Right",tux.keymap.right,0); + options_controls_menu->additem(MN_HL,"",0,0); + options_controls_menu->additem(MN_BACK,"Back",0,0); load_game_menu->additem(MN_LABEL,"Load Game",0,0); load_game_menu->additem(MN_HL,"",0,0); diff --git a/src/title.cpp b/src/title.cpp index d41c35d9a..c1bda33be 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -134,6 +134,7 @@ int title(void) while (SDL_PollEvent(&event)) { + menu_event(event); if (event.type == SDL_QUIT) { /* Quit event - quit: */ @@ -146,7 +147,7 @@ int title(void) key = event.key.keysym.sym; /* Check for menu events */ - menu_event(&event.key.keysym); + //menu_event(event); if (key == SDLK_ESCAPE) { @@ -155,18 +156,6 @@ int title(void) quit = 1; } } - else if (event.type == SDL_JOYAXISMOTION && event.jaxis.axis == JOY_Y) - { - if (event.jaxis.value > 1024) - menuaction = MENU_ACTION_DOWN; - else if (event.jaxis.value < -1024) - menuaction = MENU_ACTION_UP; - } - else if (event.type == SDL_JOYBUTTONDOWN) - { - /* Joystick button: Continue: */ - menuaction = MENU_ACTION_HIT; - } } /* Draw the background: */ -- 2.11.0