mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-27 06:42:23 +00:00
Add support for use back button as ESC, as example first button in SDL_GAMECONTROLLERCONFIG
This commit is contained in:
parent
4bfd1cb9d4
commit
61da3dffd1
4 changed files with 63 additions and 17 deletions
|
@ -73,6 +73,7 @@ static qboolean mlooking;
|
|||
static int joystick_yaw, joystick_pitch;
|
||||
static int joystick_forwardmove, joystick_sidemove;
|
||||
static int joystick_up;
|
||||
static int back_button_id = -1;
|
||||
static char last_hat = SDL_HAT_CENTERED;
|
||||
static qboolean left_trigger = false;
|
||||
static qboolean right_trigger = false;
|
||||
|
@ -523,6 +524,15 @@ IN_Update(void)
|
|||
#endif
|
||||
break;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
case SDL_CONTROLLERBUTTONDOWN: /* Handle Controller Back button */
|
||||
{
|
||||
qboolean down = (event.type == SDL_CONTROLLERBUTTONDOWN);
|
||||
if(event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) {
|
||||
Key_Event(K_JOY_BACK, down, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_CONTROLLERAXISMOTION: /* Handle Controller Motion */
|
||||
{
|
||||
char* direction_type;
|
||||
|
@ -635,6 +645,9 @@ IN_Update(void)
|
|||
case SDL_JOYBUTTONDOWN:
|
||||
{
|
||||
qboolean down = (event.type == SDL_JOYBUTTONDOWN);
|
||||
/* Ignore back button, we dont need event for such button */
|
||||
if (back_button_id == event.jbutton.button)
|
||||
return;
|
||||
if(event.jbutton.button <= (K_JOY32 - K_JOY1)) {
|
||||
Key_Event(event.jbutton.button + K_JOY1, down, true);
|
||||
}
|
||||
|
@ -824,6 +837,11 @@ IN_MLookUp(void)
|
|||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
/*
|
||||
* Shutdown haptic functionality
|
||||
*/
|
||||
static void IN_Haptic_Shutdown(void);
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/*
|
||||
* Init haptic effects
|
||||
|
@ -852,7 +870,9 @@ IN_Haptic_Effect_Init(int dir, int period, int magnitude, int length, int attack
|
|||
effect_id = SDL_HapticNewEffect(joystick_haptic, &haptic_effect);
|
||||
if (effect_id < 0)
|
||||
{
|
||||
Com_Printf ("SDL_HapticNewEffect failed: %s", SDL_GetError());
|
||||
Com_Printf ("SDL_HapticNewEffect failed: %s\n", SDL_GetError());
|
||||
Com_Printf ("Please try to rerun game. Effects will be disabled for now.\n");
|
||||
IN_Haptic_Shutdown();
|
||||
}
|
||||
return effect_id;
|
||||
}
|
||||
|
@ -1006,7 +1026,7 @@ IN_Haptic_Effect_Shutdown(int * effect_id)
|
|||
}
|
||||
|
||||
static void
|
||||
IN_Haptic_Effects_Shotdown(void)
|
||||
IN_Haptic_Effects_Shutdown(void)
|
||||
{
|
||||
for (int i=0; i<HAPTIC_EFFECT_LAST; i++)
|
||||
{
|
||||
|
@ -1030,7 +1050,7 @@ Haptic_Feedback(char *name)
|
|||
|
||||
if (last_haptic_volume != (int)(joy_haptic_magnitude->value * 255))
|
||||
{
|
||||
IN_Haptic_Effects_Shotdown();
|
||||
IN_Haptic_Effects_Shutdown();
|
||||
IN_Haptic_Effects_Init();
|
||||
}
|
||||
last_haptic_volume = joy_haptic_magnitude->value * 255;
|
||||
|
@ -1217,6 +1237,7 @@ IN_Init(void)
|
|||
|
||||
if(SDL_IsGameController(i))
|
||||
{
|
||||
SDL_GameControllerButtonBind backBind;
|
||||
controller = SDL_GameControllerOpen(i);
|
||||
Com_Printf ("Controller settings: %s\n", SDL_GameControllerMapping(controller));
|
||||
Com_Printf ("Controller axis: \n");
|
||||
|
@ -1235,6 +1256,12 @@ IN_Init(void)
|
|||
Com_Printf (" * triggerleft = %f\n", joy_axis_triggerleft_threshold->value);
|
||||
Com_Printf (" * triggerright = %f\n", joy_axis_triggerright_threshold->value);
|
||||
|
||||
backBind = SDL_GameControllerGetBindForButton(controller, SDL_CONTROLLER_BUTTON_BACK);
|
||||
|
||||
if (backBind.bindType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
|
||||
back_button_id = backBind.value.button;
|
||||
Com_Printf ("\nBack button JOY%d will be unbindable.\n", back_button_id+1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
@ -1244,7 +1271,7 @@ IN_Init(void)
|
|||
guid = SDL_JoystickGetDeviceGUID(i);
|
||||
SDL_JoystickGetGUIDString(guid, joystick_guid, 255);
|
||||
Com_Printf ("For use joystic as game contoller please set SDL_GAMECONTROLLERCONFIG:\n");
|
||||
Com_Printf ("e.g.: SDL_GAMECONTROLLERCONFIG='%s,%s,leftx:a0,lefty:a1,rightx:a2,righty:a3,...\n", joystick_guid, SDL_JoystickName(joystick));
|
||||
Com_Printf ("e.g.: SDL_GAMECONTROLLERCONFIG='%s,%s,leftx:a0,lefty:a1,rightx:a2,righty:a3,back:b1,...\n", joystick_guid, SDL_JoystickName(joystick));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1266,6 +1293,18 @@ IN_Init(void)
|
|||
/*
|
||||
* Shuts the backend down
|
||||
*/
|
||||
static void
|
||||
IN_Haptic_Shutdown(void)
|
||||
{
|
||||
if (joystick_haptic)
|
||||
{
|
||||
IN_Haptic_Effects_Shutdown();
|
||||
|
||||
SDL_HapticClose(joystick_haptic);
|
||||
joystick_haptic = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IN_Shutdown(void)
|
||||
{
|
||||
|
@ -1276,16 +1315,11 @@ IN_Shutdown(void)
|
|||
Com_Printf("Shutting down input.\n");
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (joystick_haptic)
|
||||
{
|
||||
IN_Haptic_Effects_Shotdown();
|
||||
|
||||
SDL_HapticClose(joystick_haptic);
|
||||
joystick_haptic = NULL;
|
||||
}
|
||||
IN_Haptic_Shutdown();
|
||||
|
||||
if (controller)
|
||||
{
|
||||
back_button_id = -1;
|
||||
SDL_GameControllerClose(controller);
|
||||
controller = NULL;
|
||||
}
|
||||
|
|
|
@ -147,6 +147,8 @@ keyname_t keynames[] = {
|
|||
{"TRIG_LEFT", K_TRIG_LEFT},
|
||||
{"TRIG_RIGHT", K_TRIG_RIGHT},
|
||||
|
||||
{"JOY_BACK", K_JOY_BACK},
|
||||
|
||||
{"AUX1", K_AUX1},
|
||||
{"AUX2", K_AUX2},
|
||||
{"AUX3", K_AUX3},
|
||||
|
@ -756,7 +758,7 @@ Key_Bind_f(void)
|
|||
}
|
||||
|
||||
/* don't allow binding escape or the special console keys */
|
||||
if(b == K_ESCAPE || b == '^' || b == '`' || b == '~')
|
||||
if(b == K_ESCAPE || b == '^' || b == '`' || b == '~' || b == K_JOY_BACK)
|
||||
{
|
||||
if(doneWithDefaultCfg)
|
||||
{
|
||||
|
@ -1102,7 +1104,7 @@ Key_Event(int key, qboolean down, qboolean special)
|
|||
}
|
||||
|
||||
/* Key is unbound */
|
||||
if ((key >= K_MOUSE1) && !keybindings[key] && (cls.key_dest != key_console))
|
||||
if ((key >= K_MOUSE1 && key != K_JOY_BACK) && !keybindings[key] && (cls.key_dest != key_console))
|
||||
{
|
||||
Com_Printf("%s is unbound, hit F4 to set.\n", Key_KeynumToString(key));
|
||||
}
|
||||
|
@ -1122,10 +1124,11 @@ Key_Event(int key, qboolean down, qboolean special)
|
|||
- moves one menu level up
|
||||
- closes the menu
|
||||
- closes the help computer
|
||||
- closes the chat window */
|
||||
- closes the chat window
|
||||
Fully same logic for K_JOY_BACK */
|
||||
if (!cls.disable_screen)
|
||||
{
|
||||
if (key == K_ESCAPE)
|
||||
if (key == K_ESCAPE || key == K_JOY_BACK)
|
||||
{
|
||||
if (!down)
|
||||
{
|
||||
|
|
|
@ -152,6 +152,9 @@ enum QKEYS {
|
|||
K_TRIG_LEFT,
|
||||
K_TRIG_RIGHT,
|
||||
|
||||
/* Can't be mapped to any action */
|
||||
K_JOY_BACK,
|
||||
|
||||
K_AUX1,
|
||||
K_AUX2,
|
||||
K_AUX3,
|
||||
|
|
|
@ -317,6 +317,10 @@ Key_GetMenuKey(int key)
|
|||
case K_KP_ENTER:
|
||||
case K_ENTER:
|
||||
return K_ENTER;
|
||||
|
||||
case K_ESCAPE:
|
||||
case K_JOY_BACK:
|
||||
return K_ESCAPE;
|
||||
}
|
||||
|
||||
return key;
|
||||
|
@ -4317,7 +4321,8 @@ M_Menu_PlayerConfig_f(void)
|
|||
static const char *
|
||||
M_Quit_Key(int key)
|
||||
{
|
||||
switch (key)
|
||||
int menu_key = Key_GetMenuKey(key);
|
||||
switch (menu_key)
|
||||
{
|
||||
case K_ESCAPE:
|
||||
case 'n':
|
||||
|
@ -4325,6 +4330,7 @@ M_Quit_Key(int key)
|
|||
M_PopMenu();
|
||||
break;
|
||||
|
||||
case K_ENTER:
|
||||
case 'Y':
|
||||
case 'y':
|
||||
cls.key_dest = key_console;
|
||||
|
|
Loading…
Reference in a new issue