Browse Source

GameController: Add separate D-Pad bindings

1. Adds separate D-Pad bindings so that they don't conflict with arrow
   keys on the keyboard.
2. Also adds some basic defaults for gamepad buttons.
pull/2/head
Gleb Mazovetskiy 4 years ago committed by Alibek Omarov
parent
commit
3e8e751dc7
  1. 44
      engine/client/keys.c
  2. 12
      engine/keydefs.h
  3. 7
      engine/platform/sdl/events.c

44
engine/client/keys.c

@ -98,26 +98,32 @@ keyname_t keynames[] = @@ -98,26 +98,32 @@ keyname_t keynames[] =
{"KP_PLUS", K_KP_PLUS, "" },
{"PAUSE", K_PAUSE, "pause" },
{"A_BUTTON", K_A_BUTTON, ""}, // they match xbox controller
{"B_BUTTON", K_B_BUTTON, ""},
{"X_BUTTON", K_X_BUTTON, ""},
{"Y_BUTTON", K_Y_BUTTON, ""},
{"L1_BUTTON", K_L1_BUTTON, ""},
{"R1_BUTTON", K_R1_BUTTON, ""},
{"BACK", K_BACK_BUTTON, ""},
// Gamepad
// A/B X/Y names match the Xbox controller layout
{"A_BUTTON", K_A_BUTTON, "+jump"},
{"B_BUTTON", K_B_BUTTON, "+use"},
{"X_BUTTON", K_X_BUTTON, "+reload"}, // Flashlight
{"Y_BUTTON", K_Y_BUTTON, "impulse 100"},
{"BACK", K_BACK_BUTTON, "cancelselect"}, // Menu
{"MODE", K_MODE_BUTTON, ""},
{"START", K_START_BUTTON, ""},
{"STICK1", K_LSTICK, ""},
{"STICK2", K_RSTICK, ""},
{"L2_BUTTON", K_L2_BUTTON, ""}, // in case...
{"R2_BUTTON", K_R2_BUTTON, ""},
{"START", K_START_BUTTON, "pause"},
{"STICK1", K_LSTICK, "+speed"},
{"STICK2", K_RSTICK, "+duck"},
{"L1_BUTTON", K_L1_BUTTON, "+duck"},
{"R1_BUTTON", K_R1_BUTTON, "+attack"},
{"DPAD_UP", K_DPAD_UP, "impulse 201"}, // Spray
{"DPAD_DOWN", K_DPAD_DOWN, "lastinv"},
{"DPAD_LEFT", K_DPAD_LEFT, "invprev"},
{"DPAD_RIGHT", K_DPAD_RIGHT, "invnext"},
{"L2_BUTTON", K_L2_BUTTON, "+speed"},
{"R2_BUTTON", K_R2_BUTTON, "+attack2"},
{"LTRIGGER" , K_JOY1 , "+speed"}, // L2 in SDL2
{"RTRIGGER" , K_JOY2 , "+attack2"}, // R2 in SDL2
{"JOY3" , K_JOY3 , ""},
{"JOY4" , K_JOY4 , ""},
{"C_BUTTON", K_C_BUTTON, ""},
{"Z_BUTTON", K_Z_BUTTON, ""},
{"AUX16", K_AUX16, ""}, // generic
{"AUX17", K_AUX17, ""},
{"AUX18", K_AUX18, ""},
{"AUX19", K_AUX19, ""},
{"AUX20", K_AUX20, ""},
{"AUX20", K_AUX20, ""}, // generic
{"AUX21", K_AUX21, ""},
{"AUX22", K_AUX22, ""},
{"AUX23", K_AUX23, ""},
@ -130,10 +136,6 @@ keyname_t keynames[] = @@ -130,10 +136,6 @@ keyname_t keynames[] =
{"AUX30", K_AUX30, ""},
{"AUX31", K_AUX31, ""},
{"AUX32", K_AUX32, ""},
{"LTRIGGER" , K_JOY1 , ""},
{"RTRIGGER" , K_JOY2 , ""},
{"JOY3" , K_JOY3 , ""},
{"JOY4" , K_JOY4 , ""},
// raw semicolon seperates commands
{"SEMICOLON", ';', "" },

12
engine/keydefs.h

@ -77,8 +77,8 @@ @@ -77,8 +77,8 @@
//
// joystick buttons
//
#define K_JOY1 203
#define K_JOY2 204
#define K_JOY1 203 // LTRIGGER (L2)
#define K_JOY2 204 // RTRIGGER (R2)
#define K_JOY3 205
#define K_JOY4 206
@ -132,9 +132,17 @@ @@ -132,9 +132,17 @@
#define K_Z_BUTTON K_AUX15
#define K_AUX16 222
#define K_DPAD_UP K_AUX16
#define K_AUX17 223
#define K_DPAD_DOWN K_AUX17
#define K_AUX18 224
#define K_DPAD_LEFT K_AUX18
#define K_AUX19 225
#define K_DPAD_RIGHT K_AUX19
#define K_AUX20 226
#define K_AUX21 227
#define K_AUX22 228

7
engine/platform/sdl/events.c

@ -550,17 +550,16 @@ static void SDLash_EventFilter( SDL_Event *event ) @@ -550,17 +550,16 @@ static void SDLash_EventFilter( SDL_Event *event )
{
static int sdlControllerButtonToEngine[] =
{
K_AUX16, // invalid
K_A_BUTTON, K_B_BUTTON, K_X_BUTTON, K_Y_BUTTON,
K_BACK_BUTTON, K_MODE_BUTTON, K_START_BUTTON,
K_LSTICK, K_RSTICK,
K_L1_BUTTON, K_R1_BUTTON,
K_UPARROW, K_DOWNARROW, K_LEFTARROW, K_RIGHTARROW
K_DPAD_UP, K_DPAD_DOWN, K_DPAD_LEFT, K_DPAD_RIGHT
};
// TODO: Use joyinput funcs, for future multiple gamepads support
if( Joy_IsActive() )
Key_Event( sdlControllerButtonToEngine[event->cbutton.button + 1], event->cbutton.state );
if( Joy_IsActive() && event->cbutton.button != SDL_CONTROLLER_BUTTON_INVALID )
Key_Event( sdlControllerButtonToEngine[event->cbutton.button], event->cbutton.state );
break;
}

Loading…
Cancel
Save