{
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: */
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;
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;
}
tux.input.up = UP;
else if (event.jbutton.button == JOY_B)
tux.input.fire = UP;
-
- if(show_menu)
- menuaction = MENU_ACTION_HIT;
+
break;
default:
while(SDL_PollEvent(&event))
if(event.type == SDL_KEYDOWN)
- menu_event(&event.key.keysym);
+ menu_event(event);
switch (highscore_menu->check())
{
key = event.key.keysym.sym;
if(show_menu)
{
- menu_event(&event.key.keysym);
+ menu_event(event);
if(key == SDLK_ESCAPE)
{
show_menu = false;
case MN_ACTION:
case MN_TEXTFIELD:
case MN_NUMFIELD:
+ case MN_CONTROLFIELD:
item[active_item].toggled = true;
break;
}
case MN_TEXTFIELD:
case MN_NUMFIELD:
+ case MN_CONTROLFIELD:
{
int input_pos = input_width/2;
int text_pos = (text_width + font_width)/2;
}
/* 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)
MN_DEACTIVE,
MN_TEXTFIELD,
MN_NUMFIELD,
+ MN_CONTROLFIELD,
MN_STRINGSELECT,
MN_LABEL,
- MN_HL /* horizontal line */
+ MN_HL, /* horizontal line */
};
class Menu;
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*/
#include "menu.h"
#include "gameloop.h"
#include "configfile.h"
+#include "scene.h"
#ifdef WIN32
#define mkdir(dir, mode) mkdir(dir)
{
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();
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);
while (SDL_PollEvent(&event))
{
+ menu_event(event);
if (event.type == SDL_QUIT)
{
/* Quit event - quit: */
key = event.key.keysym.sym;
/* Check for menu events */
- menu_event(&event.key.keysym);
+ //menu_event(event);
if (key == SDLK_ESCAPE)
{
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: */