mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Move bind-search logic to g_input
This commit is contained in:
parent
1c50c3510d
commit
0b9c5c7415
3 changed files with 39 additions and 31 deletions
|
|
@ -1121,6 +1121,42 @@ INT32 G_CheckDoubleUsage(INT32 keynum, INT32 playernum, boolean modify)
|
|||
return result;
|
||||
}
|
||||
|
||||
INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
||||
{
|
||||
profile_t *ourProfile = PR_GetLocalPlayerProfile(player);
|
||||
if (ourProfile == NULL)
|
||||
ourProfile = PR_GetLocalPlayerProfile(0);
|
||||
|
||||
INT32 device = G_GetDeviceForPlayer(player); // TODO: Respond to what device player is CURRENTLY using
|
||||
if (device == -1) // No registered device = you can't possibly be using a gamepad
|
||||
device = KEYBOARD_MOUSE_DEVICE;
|
||||
|
||||
INT32 bestbind = -1; // Bind that matches our input device
|
||||
INT32 anybind = -1; // Bind that doesn't match, but is at least for this control
|
||||
|
||||
INT32 bindindex = 3;
|
||||
|
||||
while (bindindex >= 0) // Prefer earlier binds
|
||||
{
|
||||
INT32 possiblecontrol = ourProfile->controls[control][bindindex];
|
||||
|
||||
// if (device is gamepad) == (bound control is in gamepad range) - e.g. if bind matches device
|
||||
if ((device != KEYBOARD_MOUSE_DEVICE) == (possiblecontrol >= KEY_JOY1 && possiblecontrol < JOYINPUTEND))
|
||||
{
|
||||
bestbind = possiblecontrol;
|
||||
anybind = possiblecontrol;
|
||||
}
|
||||
else
|
||||
{
|
||||
anybind = possiblecontrol;
|
||||
}
|
||||
|
||||
bindindex--;
|
||||
}
|
||||
|
||||
return (bestbind != -1) ? bestbind : anybind; // If we couldn't find a device-appropriate bind, try to at least use something
|
||||
}
|
||||
|
||||
static void setcontrol(UINT8 player)
|
||||
{
|
||||
INT32 numctrl;
|
||||
|
|
|
|||
|
|
@ -205,6 +205,8 @@ void G_ApplyControlScheme(UINT8 splitplayer, INT32 (*fromcontrols)[MAXINPUTMAPPI
|
|||
void G_SaveKeySetting(FILE *f, INT32 (*fromcontrolsa)[MAXINPUTMAPPING], INT32 (*fromcontrolsb)[MAXINPUTMAPPING], INT32 (*fromcontrolsc)[MAXINPUTMAPPING], INT32 (*fromcontrolsd)[MAXINPUTMAPPING]);
|
||||
INT32 G_CheckDoubleUsage(INT32 keynum, INT32 playernum, boolean modify);
|
||||
|
||||
INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -153,38 +153,8 @@ Draw::TextElement& Draw::TextElement::parse(std::string_view raw)
|
|||
{
|
||||
// Grab our local controls
|
||||
UINT8 localplayer = stplyr - players;
|
||||
profile_t *ourProfile = PR_GetLocalPlayerProfile(localplayer);
|
||||
if (ourProfile == NULL)
|
||||
ourProfile = PR_GetLocalPlayerProfile(0);
|
||||
|
||||
INT32 device = G_GetDeviceForPlayer(localplayer); // TODO: Respond to what device player is CURRENTLY using
|
||||
if (device == -1) // No registered device = you can't possibly be using a gamepad
|
||||
device = KEYBOARD_MOUSE_DEVICE;
|
||||
|
||||
INT32 bestbind = -1; // Bind that matches our input device
|
||||
INT32 anybind = -1; // Bind that doesn't match, but is at least for this control
|
||||
|
||||
INT32 control = 3;
|
||||
|
||||
while (control >= 0) // Prefer earlier binds
|
||||
{
|
||||
INT32 possiblecontrol = ourProfile->controls[(INT32)id->second][control];
|
||||
|
||||
// if (device is gamepad) == (bound control is in gamepad range) - e.g. if bind matches device
|
||||
if ((device != KEYBOARD_MOUSE_DEVICE) == (possiblecontrol >= KEY_JOY1 && possiblecontrol < JOYINPUTEND))
|
||||
{
|
||||
bestbind = possiblecontrol;
|
||||
anybind = possiblecontrol;
|
||||
}
|
||||
else
|
||||
{
|
||||
anybind = possiblecontrol;
|
||||
}
|
||||
|
||||
control--;
|
||||
}
|
||||
|
||||
INT32 bind = (bestbind != -1) ? bestbind : anybind; // If we couldn't find a device-appropriate bind, try to at least use something
|
||||
INT32 bind = G_FindPlayerBindForGameControl(localplayer, id->second);
|
||||
|
||||
if (auto pretty = prettyinputs.find(bind); pretty != prettyinputs.end()) // Gamepad direction or keyboard arrow, use something nice-looking
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue