G_PlayerInputAnalog: Only attempt default binds for menu if no binds are reachable by GetValueFromControlTable for that button

- GetValueFromControlTable: Return 0 only if a single G_KeyIsAvailable returns true for any bind
    - Otherwise returns NO_BINDS_REACHABLE -- #define'd as (-1)
    - Does not cover the `menucontrolreserved` check, which could maybe be moved to the opposite end of the function if it causes problems.
This commit is contained in:
toaster 2023-03-19 17:48:24 +00:00
parent 22294c2c4d
commit 1acf00daa6
2 changed files with 26 additions and 7 deletions

View file

@ -870,12 +870,12 @@ INT16 G_SoftwareClipAimingPitch(INT32 *aiming)
static INT32 G_GetValueFromControlTable(INT32 deviceID, INT32 deadzone, INT32 *controltable) static INT32 G_GetValueFromControlTable(INT32 deviceID, INT32 deadzone, INT32 *controltable)
{ {
INT32 i; INT32 i, failret = NO_BINDS_REACHABLE;
if (deviceID <= UNASSIGNED_DEVICE) if (deviceID <= UNASSIGNED_DEVICE)
{ {
// An invalid device can't have any binds! // An invalid device can't have any binds!
return 0; return failret;
} }
for (i = 0; i < MAXINPUTMAPPING; i++) for (i = 0; i < MAXINPUTMAPPING; i++)
@ -895,10 +895,12 @@ static INT32 G_GetValueFromControlTable(INT32 deviceID, INT32 deadzone, INT32 *c
{ {
return value; return value;
} }
failret = 0;
} }
// Not pressed. // Not pressed.
return 0; return failret;
} }
INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers) INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
@ -911,6 +913,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
INT32 value = -1; INT32 value = -1;
INT32 avail_gamepad_id = 0; INT32 avail_gamepad_id = 0;
INT32 i; INT32 i;
boolean bind_was_reachable = false;
if (p >= MAXSPLITSCREENPLAYERS) if (p >= MAXSPLITSCREENPLAYERS)
{ {
@ -952,6 +955,10 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
{ {
return value; return value;
} }
if (value != NO_BINDS_REACHABLE)
{
bind_was_reachable = true;
}
// If you're on gamepad in 1P, and you didn't have a gamepad bind for this, then try your keyboard binds. // If you're on gamepad in 1P, and you didn't have a gamepad bind for this, then try your keyboard binds.
if (main_player == true && keyboard_player == -1 && deviceID > KEYBOARD_MOUSE_DEVICE) if (main_player == true && keyboard_player == -1 && deviceID > KEYBOARD_MOUSE_DEVICE)
@ -961,6 +968,10 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
{ {
return value; return value;
} }
if (value != NO_BINDS_REACHABLE)
{
bind_was_reachable = true;
}
} }
if (in_menu == true) if (in_menu == true)
@ -997,10 +1008,16 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
{ {
return value; return value;
} }
if (value != NO_BINDS_REACHABLE)
{
bind_was_reachable = true;
}
} }
} }
} }
if (bind_was_reachable == false)
{
// Still nothing bound after everything. Try default gamepad controls. // Still nothing bound after everything. Try default gamepad controls.
value = G_GetValueFromControlTable(deviceID, deadzone, &(gamecontroldefault[gc][0])); value = G_GetValueFromControlTable(deviceID, deadzone, &(gamecontroldefault[gc][0]));
if (value > 0) if (value > 0)
@ -1008,6 +1025,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
return value; return value;
} }
} }
}
// Literally not bound at all, so it can't be pressed at all. // Literally not bound at all, so it can't be pressed at all.
return 0; return 0;

View file

@ -109,6 +109,7 @@ extern consvar_t cv_controlperkey;
#define MAXDEVICES (MAXGAMEPADS + 1) // Gamepads + keyboard & mouse #define MAXDEVICES (MAXGAMEPADS + 1) // Gamepads + keyboard & mouse
#define KEYBOARD_MOUSE_DEVICE (0) #define KEYBOARD_MOUSE_DEVICE (0)
#define UNASSIGNED_DEVICE (-1) #define UNASSIGNED_DEVICE (-1)
#define NO_BINDS_REACHABLE (-1)
extern INT32 gamekeydown[MAXDEVICES][NUMINPUTS]; extern INT32 gamekeydown[MAXDEVICES][NUMINPUTS];
// several key codes (or virtual key) per game control // several key codes (or virtual key) per game control