Added option on how to handle new gamepad device detection. Can now choose to do nothing, prompt user, or auto reconfigure of button mappings when a new device is detected.

This commit is contained in:
harry 2024-02-18 16:04:00 -05:00
parent 9ed1dd481b
commit c62f62b497
7 changed files with 112 additions and 3 deletions

View File

@ -1382,4 +1382,37 @@ QString fceuGetOpcodeToolTip( uint8_t *opcode, int size )
return QString::fromStdString( text ); 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; i<cbx->count(); i++)
{
if ( pval == cbx->itemData(i).toInt() )
{
cbx->setCurrentIndex(i); break;
}
}
}
//---------------------------------------------------------------------------
void setComboBoxFromValue( QComboBox *cbx, int pval )
{
for (int i=0; i<cbx->count(); i++)
{
if ( pval == cbx->itemData(i).toInt() )
{
cbx->setCurrentIndex(i); break;
}
}
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -9,6 +9,7 @@
#include <QValidator> #include <QValidator>
#include <QDialog> #include <QDialog>
#include <QHelpEvent> #include <QHelpEvent>
#include <QComboBox>
#include <QCheckBox> #include <QCheckBox>
int getDirFromFile( const char *path, std::string &dir ); int getDirFromFile( const char *path, std::string &dir );
@ -93,3 +94,8 @@ class QCheckBoxRO : public QCheckBox
QString fceuGetOpcodeToolTip( uint8_t *opcode, int size ); QString fceuGetOpcodeToolTip( uint8_t *opcode, int size );
QDialog *fceuCustomToolTipShow( const QPoint &globalPos, QDialog *popup ); 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 );

View File

@ -66,7 +66,7 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent)
QPalette pal; QPalette pal;
QColor color; QColor color;
char stmp[256]; char stmp[256];
int fourscore, autoInputPreset; int fourscore, autoInputPreset, newDeviceBehavior;
pal = this->palette(); pal = this->palette();
@ -80,11 +80,23 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent)
nesInputFrame = new QGroupBox(tr("NES-Style Input Ports")); nesInputFrame = new QGroupBox(tr("NES-Style Input Ports"));
vbox1 = new QVBoxLayout(); vbox1 = new QVBoxLayout();
hbox = new QHBoxLayout(); newDeviceOptionBox = new QComboBox();
fourScoreEna = new QCheckBox(tr("Attach 4-Score (Implies four gamepads)")); fourScoreEna = new QCheckBox(tr("Attach 4-Score (Implies four gamepads)"));
port2Mic = new QCheckBox(tr("Replace Port 2 Start with Microphone")); port2Mic = new QCheckBox(tr("Replace Port 2 Start with Microphone"));
autoPreset = new QCheckBox(tr("Auto Load/Save Presets at ROM Open/Close")); 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); g_config->getOption("SDL.FourScore", &fourscore);
fourScoreEna->setChecked(fourscore); fourScoreEna->setChecked(fourscore);
port2Mic->setChecked(replaceP2StartWithMicrophone); port2Mic->setChecked(replaceP2StartWithMicrophone);
@ -92,6 +104,7 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent)
g_config->getOption("SDL.AutoInputPreset", &autoInputPreset); g_config->getOption("SDL.AutoInputPreset", &autoInputPreset);
autoPreset->setChecked(autoInputPreset); autoPreset->setChecked(autoInputPreset);
hbox = new QHBoxLayout();
hbox->addWidget(fourScoreEna); hbox->addWidget(fourScoreEna);
hbox->addWidget(port2Mic); hbox->addWidget(port2Mic);
vbox1->addLayout(hbox); vbox1->addLayout(hbox);
@ -240,6 +253,7 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent)
connect(port2Mic, SIGNAL(stateChanged(int)), this, SLOT(port2MicChanged(int))); connect(port2Mic, SIGNAL(stateChanged(int)), this, SLOT(port2MicChanged(int)));
connect(autoPreset, SIGNAL(stateChanged(int)), this, SLOT(autoPresetChanged(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[0], SIGNAL(activated(int)), this, SLOT(port1Select(int)));
connect(nesPortComboxBox[1], SIGNAL(activated(int)), this, SLOT(port2Select(int))); connect(nesPortComboxBox[1], SIGNAL(activated(int)), this, SLOT(port2Select(int)));
connect(expPortComboxBox, SIGNAL(activated(int)), this, SLOT(expSelect(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) void InputConfDialog_t::port1Select(int index)
{ {
//printf("Port 1 Number:%i \n", index); //printf("Port 1 Number:%i \n", index);

View File

@ -43,6 +43,7 @@ protected:
QComboBox *expPortComboxBox; QComboBox *expPortComboxBox;
QPushButton *loadConfigButton; QPushButton *loadConfigButton;
QPushButton *saveConfigButton; QPushButton *saveConfigButton;
QComboBox* newDeviceOptionBox;
int curNesInput[3]; int curNesInput[3];
int usrNesInput[3]; int usrNesInput[3];
@ -62,6 +63,7 @@ private slots:
void port1Select(int index); void port1Select(int index);
void port2Select(int index); void port2Select(int index);
void expSelect(int index); void expSelect(int index);
void newDeviceSettingsChange(int index);
void fourScoreChanged(int state); void fourScoreChanged(int state);
void port2MicChanged(int state); void port2MicChanged(int state);
void autoPresetChanged(int state); void autoPresetChanged(int state);

View File

@ -638,6 +638,7 @@ InitConfig()
config->addOption("SDL.AutofireOffFrames", 1); config->addOption("SDL.AutofireOffFrames", 1);
config->addOption("SDL.AutofireCustomOnFrames" , 1); config->addOption("SDL.AutofireCustomOnFrames" , 1);
config->addOption("SDL.AutofireCustomOffFrames", 1); config->addOption("SDL.AutofireCustomOffFrames", 1);
config->addOption("SDL.NewInputDeviceBehavior", 1);
// display input // display input
config->addOption("inputdisplay", "SDL.InputDisplay", 0); config->addOption("inputdisplay", "SDL.InputDisplay", 0);

View File

@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog> #include <QInputDialog>
#include <QApplication> #include <QApplication>
@ -1362,7 +1363,51 @@ pollEventsSDL()
break; break;
case SDL_JOYDEVICEADDED: 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; break;
case SDL_JOYDEVICEREMOVED: case SDL_JOYDEVICEREMOVED:
RemoveJoystick(event.jdevice.which); RemoveJoystick(event.jdevice.which);

View File

@ -98,4 +98,6 @@ extern GamePad_t GamePad[4];
jsDev_t *getJoystickDevice(int devNum); jsDev_t *getJoystickDevice(int devNum);
void initGamepadBindings();
#endif #endif