diff --git a/src/m_menu.c b/src/m_menu.c index 319ba0f8..f961062b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2461,44 +2461,42 @@ boolean M_Responder(event_t *ev) // (but still allow shift keyup so caps doesn't get stuck) return false; } + else if (ev->type == ev_keydown) + { + ch = ev->data1; + + // added 5-2-98 remap virtual keys (mouse & joystick buttons) + switch (ch) + { + case KEY_MOUSE1: + //case KEY_JOY1: + //case KEY_JOY1 + 2: + ch = KEY_ENTER; + break; + /*case KEY_JOY1 + 3: // Brake can function as 'n' for message boxes now. + ch = 'n'; + break;*/ + case KEY_MOUSE1 + 1: + //case KEY_JOY1 + 1: + ch = KEY_BACKSPACE; + break; + case KEY_HAT1: + ch = KEY_UPARROW; + break; + case KEY_HAT1 + 1: + ch = KEY_DOWNARROW; + break; + case KEY_HAT1 + 2: + ch = KEY_LEFTARROW; + break; + case KEY_HAT1 + 3: + ch = KEY_RIGHTARROW; + break; + } + } else if (menuactive) { - if (ev->type == ev_keydown) - { - ch = ev->data1; - - // added 5-2-98 remap virtual keys (mouse & joystick buttons) - switch (ch) - { - case KEY_MOUSE1: - case KEY_JOY1: - ch = KEY_ENTER; - break; - case KEY_JOY1 + 3: - ch = 'n'; - break; - case KEY_MOUSE1 + 1: - case KEY_JOY1 + 1: - ch = KEY_ESCAPE; - break; - case KEY_JOY1 + 2: - ch = KEY_BACKSPACE; - break; - case KEY_HAT1: - ch = KEY_UPARROW; - break; - case KEY_HAT1 + 1: - ch = KEY_DOWNARROW; - break; - case KEY_HAT1 + 2: - ch = KEY_LEFTARROW; - break; - case KEY_HAT1 + 3: - ch = KEY_RIGHTARROW; - break; - } - } - else if (ev->type == ev_joystick && ev->data1 == 0 && joywait < I_GetTime()) + if (ev->type == ev_joystick && ev->data1 == 0 && joywait < I_GetTime()) { const INT32 jdeadzone = JOYAXISRANGE/4; if (ev->data3 != INT32_MAX) @@ -2579,6 +2577,8 @@ boolean M_Responder(event_t *ev) return false; else if (ch == gamecontrol[gc_systemmenu][0] || ch == gamecontrol[gc_systemmenu][1]) // allow remappable ESC key ch = KEY_ESCAPE; + else if (ch == gamecontrol[gc_accelerate][0] || ch == gamecontrol[gc_accelerate][1]) + ch = KEY_ENTER; // F-Keys if (!menuactive) @@ -2655,6 +2655,9 @@ boolean M_Responder(event_t *ev) return false; } + if (ch == gamecontrol[gc_brake][0] || ch == gamecontrol[gc_brake][1]) // do this here, otherwise brake opens the menu mid-game + ch = KEY_ESCAPE; + routine = currentMenu->menuitems[itemOn].itemaction; // Handle menuitems which need a specific key handling @@ -2789,6 +2792,7 @@ boolean M_Responder(event_t *ev) return true; case KEY_ESCAPE: + //case KEY_JOY1 + 2: noFurtherInput = true; currentMenu->lastOn = itemOn; if (currentMenu->prevMenu) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 2256446d..d06d5659 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -193,11 +193,12 @@ static char returnWadPath[256]; */ static void JoyReset(SDLJoyInfo_t *JoySet) { - if (JoySet->dev) - { + if (JoySet->gamepad) + SDL_GameControllerClose(JoySet->gamepad); + else if (JoySet->dev) SDL_JoystickClose(JoySet->dev); - } JoySet->dev = NULL; + JoySet->gamepad = NULL; JoySet->oldjoy = -1; JoySet->axises = JoySet->buttons = JoySet->hats = JoySet->balls = 0; //JoySet->scale @@ -1051,9 +1052,10 @@ static int joy_open(const char *fname) { int joyindex = atoi(fname); int num_joy = 0; + int num_gc = 0; int i; - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0) { CONS_Printf(M_GetText("Joystick subsystem not started\n")); return -1; @@ -1073,7 +1075,14 @@ static int joy_open(const char *fname) { CONS_Printf(M_GetText("Found %d joysticks on this system\n"), num_joy); for (i = 0; i < num_joy; i++) - CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); + { + if (SDL_IsGameController(i)) + { + num_gc++; + CONS_Printf("#%d/(%s) GC\n", i + 1, SDL_GameControllerNameForIndex(i)); + } + CONS_Printf("#%d/(%s)\n", i + 1, SDL_JoystickNameForIndex(i)); + } if (num_joy < joyindex) { @@ -1089,8 +1098,13 @@ static int joy_open(const char *fname) return 0; } } - - JoyInfo.dev = SDL_JoystickOpen(joyindex-1); + if (SDL_IsGameController(joyindex - 1)) + { + JoyInfo.gamepad = SDL_GameControllerOpen(joyindex - 1); + JoyInfo.dev = SDL_GameControllerGetJoystick(JoyInfo.gamepad); + } + else + JoyInfo.dev = SDL_JoystickOpen(joyindex-1); if (JoyInfo.dev == NULL) { @@ -1968,14 +1982,14 @@ static int joy_open4(const char *fname) void I_InitJoystick(void) { //I_ShutdownJoystick(); - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); if (M_CheckParm("-nojoy")) return; - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0) { CONS_Printf("Initing joy system\n"); - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1) { CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); return; @@ -1999,7 +2013,7 @@ void I_InitJoystick(void) void I_InitJoystick2(void) { //I_ShutdownJoystick2(); - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); if (M_CheckParm("-nojoy")) return; @@ -2068,12 +2082,12 @@ static void I_ShutdownInput(void) I_ShutdownJoystick(); I_ShutdownJoystick2(); - if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == SDL_INIT_GAMECONTROLLER) { CONS_Printf("Shutting down joy system\n"); JoyReset(&JoyInfo3); JoyReset(&JoyInfo4); - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); I_OutputMsg("I_Joystick: SDL's Joystick system has been shutdown\n"); } } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5aeee947..1162cc7a 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -72,6 +72,7 @@ #include "../console.h" #include "../command.h" #include "sdlmain.h" +#include "../i_system.h" #ifdef HWRENDER #include "../hardware/hw_main.h" #include "../hardware/hw_drv.h" diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 001de92f..398d156d 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -39,6 +39,8 @@ typedef struct SDLJoyInfo_s { /// Joystick handle SDL_Joystick *dev; + /// GameController handle + SDL_GameController *gamepad; /// number of old joystick int oldjoy; /// number of axies