diff --git a/src/drivers/Qt/ConsoleUtilities.cpp b/src/drivers/Qt/ConsoleUtilities.cpp index fac6d5ec..05a9883f 100644 --- a/src/drivers/Qt/ConsoleUtilities.cpp +++ b/src/drivers/Qt/ConsoleUtilities.cpp @@ -1382,4 +1382,37 @@ QString fceuGetOpcodeToolTip( uint8_t *opcode, int size ) return QString::fromStdString( text ); } +//---------------------------------------------------- +void setCheckBoxFromProperty( QCheckBox *cbx, const char *property ) +{ + int pval; + g_config->getOption (property, &pval); + + cbx->setCheckState( pval ? Qt::Checked : Qt::Unchecked ); +} +//---------------------------------------------------- +void setComboBoxFromProperty( QComboBox *cbx, const char *property ) +{ + int i, pval; + g_config->getOption (property, &pval); + + for (i=0; icount(); i++) + { + if ( pval == cbx->itemData(i).toInt() ) + { + cbx->setCurrentIndex(i); break; + } + } +} +//--------------------------------------------------------------------------- +void setComboBoxFromValue( QComboBox *cbx, int pval ) +{ + for (int i=0; icount(); i++) + { + if ( pval == cbx->itemData(i).toInt() ) + { + cbx->setCurrentIndex(i); break; + } + } +} //--------------------------------------------------------------------------- diff --git a/src/drivers/Qt/ConsoleUtilities.h b/src/drivers/Qt/ConsoleUtilities.h index bbcefc07..06ad2872 100644 --- a/src/drivers/Qt/ConsoleUtilities.h +++ b/src/drivers/Qt/ConsoleUtilities.h @@ -9,6 +9,7 @@ #include #include #include +#include #include int getDirFromFile( const char *path, std::string &dir ); @@ -93,3 +94,8 @@ class QCheckBoxRO : public QCheckBox QString fceuGetOpcodeToolTip( uint8_t *opcode, int size ); QDialog *fceuCustomToolTipShow( const QPoint &globalPos, QDialog *popup ); + +//---------------------------------------------------- +void setCheckBoxFromProperty( QCheckBox *cbx, const char *property ); +void setComboBoxFromProperty( QComboBox *cbx, const char *property ); +void setComboBoxFromValue( QComboBox *cbx, int pval ); diff --git a/src/drivers/Qt/InputConf.cpp b/src/drivers/Qt/InputConf.cpp index 98e4a4b8..27476882 100644 --- a/src/drivers/Qt/InputConf.cpp +++ b/src/drivers/Qt/InputConf.cpp @@ -66,7 +66,7 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent) QPalette pal; QColor color; char stmp[256]; - int fourscore, autoInputPreset; + int fourscore, autoInputPreset, newDeviceBehavior; pal = this->palette(); @@ -80,11 +80,23 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent) nesInputFrame = new QGroupBox(tr("NES-Style Input Ports")); vbox1 = new QVBoxLayout(); - hbox = new QHBoxLayout(); + newDeviceOptionBox = new QComboBox(); fourScoreEna = new QCheckBox(tr("Attach 4-Score (Implies four gamepads)")); port2Mic = new QCheckBox(tr("Replace Port 2 Start with Microphone")); autoPreset = new QCheckBox(tr("Auto Load/Save Presets at ROM Open/Close")); + hbox = new QHBoxLayout(); + hbox->addWidget( new QLabel(tr("On New Gamepad Device Detection:")), 1); + hbox->addWidget(newDeviceOptionBox, 3); + vbox1->addLayout(hbox); + + newDeviceOptionBox->addItem("Do nothing", 0); + newDeviceOptionBox->addItem("Prompt User for Reconfigure", 1); + newDeviceOptionBox->addItem("Auto Reconfigure", 2); + + g_config->getOption("SDL.NewInputDeviceBehavior", &newDeviceBehavior); + setComboBoxFromValue( newDeviceOptionBox, newDeviceBehavior ); + g_config->getOption("SDL.FourScore", &fourscore); fourScoreEna->setChecked(fourscore); port2Mic->setChecked(replaceP2StartWithMicrophone); @@ -92,6 +104,7 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent) g_config->getOption("SDL.AutoInputPreset", &autoInputPreset); autoPreset->setChecked(autoInputPreset); + hbox = new QHBoxLayout(); hbox->addWidget(fourScoreEna); hbox->addWidget(port2Mic); vbox1->addLayout(hbox); @@ -240,6 +253,7 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent) connect(port2Mic, SIGNAL(stateChanged(int)), this, SLOT(port2MicChanged(int))); connect(autoPreset, SIGNAL(stateChanged(int)), this, SLOT(autoPresetChanged(int))); + connect(newDeviceOptionBox , SIGNAL(activated(int)), this, SLOT(newDeviceSettingsChange(int))); connect(nesPortComboxBox[0], SIGNAL(activated(int)), this, SLOT(port1Select(int))); connect(nesPortComboxBox[1], SIGNAL(activated(int)), this, SLOT(port2Select(int))); connect(expPortComboxBox, SIGNAL(activated(int)), this, SLOT(expSelect(int))); @@ -362,6 +376,12 @@ void InputConfDialog_t::updatePortComboBoxes(void) } } //---------------------------------------------------------------------------- +void InputConfDialog_t::newDeviceSettingsChange(int index) +{ + g_config->setOption("SDL.NewInputDeviceBehavior", newDeviceOptionBox->itemData(index).toInt()); + g_config->save(); +} +//---------------------------------------------------------------------------- void InputConfDialog_t::port1Select(int index) { //printf("Port 1 Number:%i \n", index); diff --git a/src/drivers/Qt/InputConf.h b/src/drivers/Qt/InputConf.h index aa9d3d48..331afb74 100644 --- a/src/drivers/Qt/InputConf.h +++ b/src/drivers/Qt/InputConf.h @@ -43,6 +43,7 @@ protected: QComboBox *expPortComboxBox; QPushButton *loadConfigButton; QPushButton *saveConfigButton; + QComboBox* newDeviceOptionBox; int curNesInput[3]; int usrNesInput[3]; @@ -62,6 +63,7 @@ private slots: void port1Select(int index); void port2Select(int index); void expSelect(int index); + void newDeviceSettingsChange(int index); void fourScoreChanged(int state); void port2MicChanged(int state); void autoPresetChanged(int state); diff --git a/src/drivers/Qt/config.cpp b/src/drivers/Qt/config.cpp index 50442ffb..e68b3f9e 100644 --- a/src/drivers/Qt/config.cpp +++ b/src/drivers/Qt/config.cpp @@ -638,6 +638,7 @@ InitConfig() config->addOption("SDL.AutofireOffFrames", 1); config->addOption("SDL.AutofireCustomOnFrames" , 1); config->addOption("SDL.AutofireCustomOffFrames", 1); + config->addOption("SDL.NewInputDeviceBehavior", 1); // display input config->addOption("inputdisplay", "SDL.InputDisplay", 0); diff --git a/src/drivers/Qt/input.cpp b/src/drivers/Qt/input.cpp index d91a7420..d4a3533e 100644 --- a/src/drivers/Qt/input.cpp +++ b/src/drivers/Qt/input.cpp @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include #include @@ -1362,7 +1363,51 @@ pollEventsSDL() break; case SDL_JOYDEVICEADDED: - AddJoystick(event.jdevice.which); + { + int devIdx = AddJoystick(event.jdevice.which); + if (devIdx >= 0) + { + int newDeviceBehavior = 0; + g_config->getOption("SDL.NewInputDeviceBehavior", &newDeviceBehavior); + + if (newDeviceBehavior == 1) + { + bool wasPaused = FCEUI_EmulationPaused() ? true : false; + + jsDev_t* jsDev = getJoystickDevice(devIdx); + + QString msg = "A new joystick/gamepad device has been detected.\n"; + + if (jsDev != nullptr) + { + msg += QString("\nDevice ") + QString::number(devIdx) + QString(": "); + msg += QString(jsDev->getName()) + "\n"; + } + msg += "\nDo you wish to reload button bindings?"; + QMessageBox msgBox(QMessageBox::Question, QObject::tr("New Device Detected"), msg, + QMessageBox::No | QMessageBox::Yes, consoleWindow); + + msgBox.setDefaultButton( QMessageBox::Yes ); + + FCEUI_SetEmulationPaused( EMULATIONPAUSED_PAUSED ); + + int answer = msgBox.exec(); + + if ( answer == QMessageBox::Yes ) + { + initGamepadBindings(); + } + if (!wasPaused) + { + FCEUI_SetEmulationPaused(0); + } + } + else if (newDeviceBehavior == 2) + { + initGamepadBindings(); + } + } + } break; case SDL_JOYDEVICEREMOVED: RemoveJoystick(event.jdevice.which); diff --git a/src/drivers/Qt/sdl-joystick.h b/src/drivers/Qt/sdl-joystick.h index e2f9b54c..a192cedf 100644 --- a/src/drivers/Qt/sdl-joystick.h +++ b/src/drivers/Qt/sdl-joystick.h @@ -98,4 +98,6 @@ extern GamePad_t GamePad[4]; jsDev_t *getJoystickDevice(int devNum); +void initGamepadBindings(); + #endif