Skip to content

Commit

Permalink
Fixed Input panel would not correctly keep selected gamepad
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Dec 30, 2020
1 parent 0be55c7 commit 0675c7b
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/osdep/gui/PanelInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#define MAX_PORTSUBMODES 16
static int portsubmodes[MAX_PORTSUBMODES];
static int retroarch_kb = 0;
static int joysticks = 0;
static int mice = 0;

static const int mousespeed_values[] = { 50, 75, 100, 125, 150 };
static const int digital_joymousespeed_values[] = { 2, 5, 10, 15, 20 };
Expand Down Expand Up @@ -139,14 +142,11 @@ class InputPortsActionListener : public gcn::ActionListener
auto v = id->getSelected();
if (v >= 0)
{
auto max = JSEM_LASTKBD + inputdevice_get_device_total(IDTYPE_JOYSTICK);
auto max = JSEM_LASTKBD + joysticks;
if (i < 2)
max += inputdevice_get_device_total(IDTYPE_MOUSE);
max += mice;
v -= 1;
if (v < 0) {
*port = JPORT_NONE;
}
else if (v >= max + MAX_JPORTS_CUSTOM) {
if (v < 0 || v >= max + MAX_JPORTS_CUSTOM) {
*port = JPORT_NONE;
}
else if (v >= max) {
Expand All @@ -155,8 +155,8 @@ class InputPortsActionListener : public gcn::ActionListener
else if (v < JSEM_LASTKBD) {
*port = JSEM_KBDLAYOUT + (int)v;
}
else if (v >= JSEM_LASTKBD + inputdevice_get_device_total(IDTYPE_JOYSTICK)) {
*port = JSEM_MICE + (int)v - inputdevice_get_device_total(IDTYPE_JOYSTICK) - JSEM_LASTKBD;
else if (v >= JSEM_LASTKBD + joysticks) {
*port = JSEM_MICE + (int)v - joysticks - JSEM_LASTKBD;
}
else {
*port = JSEM_JOYS + (int)v - JSEM_LASTKBD;
Expand Down Expand Up @@ -278,6 +278,10 @@ static InputActionListener* inputActionListener;

void InitPanelInput(const struct _ConfigCategory& category)
{
retroarch_kb = get_retroarch_kb_num();
joysticks = inputdevice_get_device_total(IDTYPE_JOYSTICK);
mice = inputdevice_get_device_total(IDTYPE_MOUSE);

if (ctrlPortList.getNumberOfElements() == 0)
{
auto idx = 0;
Expand All @@ -300,23 +304,22 @@ void InitPanelInput(const struct _ConfigCategory& category)
ctrlPortList.add_element("Keyrah Layout (Cursor, Space/RAlt=Fire, RShift=2nd Fire)");
portListIDs[idx] = JSEM_KBDLAYOUT + 3;

const auto retroarch_kb = get_retroarch_kb_num();
for (auto j = 0; j < retroarch_kb; j++)
for (auto j = 0; j < 4; j++)
{
auto element = "Retroarch KBD as Joystick Player" + std::to_string(j + 1);
ctrlPortList.add_element(element.c_str());
idx++;
portListIDs[idx] = JSEM_KBDLAYOUT + j + 4;
}

for (auto j = 0; j < inputdevice_get_device_total(IDTYPE_JOYSTICK); j++)
for (auto j = 0; j < joysticks; j++)
{
ctrlPortList.add_element(inputdevice_get_device_name(IDTYPE_JOYSTICK, j));
idx++;
portListIDs[idx] = JSEM_JOYS + j;
}

for (auto j = 0; j < inputdevice_get_device_total(IDTYPE_MOUSE); j++)
for (auto j = 0; j < mice; j++)
{
ctrlPortList.add_element(inputdevice_get_device_name(IDTYPE_MOUSE, j));
idx++;
Expand Down

0 comments on commit 0675c7b

Please # to comment.