X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=69d7a2120a6fe78f2c7536f16954c2fb4908cc2d;hb=c104460647804f7fb64c02cb4619d18d1abba23c;hp=6dbb1e7154fd6823a9e5d7ebcfaebbfb9c0830d4;hpb=a00af4d54f7f23fe9ed4ae7e3244895c4acc0158;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 6dbb1e71..69d7a212 100644 --- a/src/events.c +++ b/src/events.c @@ -247,6 +247,15 @@ void HandleOtherEvents(Event *event) break; #if defined(TARGET_SDL) +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONDOWN: + case SDL_CONTROLLERBUTTONUP: + HandleSpecialGameControllerButtons(event); + /* FALL THROUGH */ + case SDL_CONTROLLERDEVICEADDED: + case SDL_CONTROLLERDEVICEREMOVED: + case SDL_CONTROLLERAXISMOTION: +#endif case SDL_JOYAXISMOTION: case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: @@ -343,6 +352,13 @@ void ClearEventQueue() ClearPlayerAction(); break; +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONUP: + HandleJoystickEvent(&event); + ClearPlayerAction(); + break; +#endif + default: HandleOtherEvents(&event); break; @@ -382,6 +398,13 @@ void SleepWhileUnmapped() key_joystick_mapping = 0; break; +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONUP: + HandleJoystickEvent(&event); + key_joystick_mapping = 0; + break; +#endif + case EVENT_MAPNOTIFY: window_unmapped = FALSE; break; @@ -1930,23 +1953,30 @@ static int HandleJoystickForAllPlayers() { int i; int result = 0; + boolean no_joysticks_configured = TRUE; + boolean use_as_joystick_nr = (game_status != GAME_MODE_PLAYING); + static byte joy_action_last[MAX_PLAYERS]; + + for (i = 0; i < MAX_PLAYERS; i++) + if (setup.input[i].use_joystick) + no_joysticks_configured = FALSE; + + /* if no joysticks configured, map connected joysticks to players */ + if (no_joysticks_configured) + use_as_joystick_nr = TRUE; for (i = 0; i < MAX_PLAYERS; i++) { byte joy_action = 0; - /* - if (!setup.input[i].use_joystick) - continue; - */ - - joy_action = Joystick(i); + joy_action = JoystickExt(i, use_as_joystick_nr); result |= joy_action; - if (!setup.input[i].use_joystick) - continue; + if ((setup.input[i].use_joystick || no_joysticks_configured) && + joy_action != joy_action_last[i]) + stored_player[i].action = joy_action; - stored_player[i].action = joy_action; + joy_action_last[i] = joy_action; } return result; @@ -1982,10 +2012,23 @@ void HandleJoystick() case GAME_MODE_INFO: { static unsigned int joystickmove_delay = 0; + static unsigned int joystickmove_delay_value = GADGET_FRAME_DELAY; + static int joystick_last = 0; if (joystick && !button && - !DelayReached(&joystickmove_delay, GADGET_FRAME_DELAY)) + !DelayReached(&joystickmove_delay, joystickmove_delay_value)) + { + /* delay joystick actions if buttons/axes continually pressed */ newbutton = dx = dy = 0; + } + else + { + /* start with longer delay, then continue with shorter delay */ + if (joystick != joystick_last) + joystickmove_delay_value = GADGET_FRAME_DELAY_FIRST; + else + joystickmove_delay_value = GADGET_FRAME_DELAY; + } if (game_status == GAME_MODE_TITLE) HandleTitleScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); @@ -1999,6 +2042,9 @@ void HandleJoystick() HandleSetupScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); else if (game_status == GAME_MODE_INFO) HandleInfoScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); + + joystick_last = joystick; + break; } @@ -2017,9 +2063,39 @@ void HandleJoystick() return; } + if (tape.recording && tape.pausing) + { + if (joystick & JOY_ACTION) + TapeTogglePause(TAPE_TOGGLE_MANUAL); + } + break; default: break; } } + +void HandleSpecialGameControllerButtons(Event *event) +{ +#if defined(TARGET_SDL2) + switch (event->type) + { + case SDL_CONTROLLERBUTTONDOWN: + if (event->cbutton.button == SDL_CONTROLLER_BUTTON_START) + HandleKey(KSYM_space, KEY_PRESSED); + else if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK) + HandleKey(KSYM_Escape, KEY_PRESSED); + + break; + + case SDL_CONTROLLERBUTTONUP: + if (event->cbutton.button == SDL_CONTROLLER_BUTTON_START) + HandleKey(KSYM_space, KEY_RELEASED); + else if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK) + HandleKey(KSYM_Escape, KEY_RELEASED); + + break; + } +#endif +}