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

12
engine/keydefs.h

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

7
engine/platform/sdl/events.c

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

Loading…
Cancel
Save