Added checks to Qt GUI to prevent user from mapping joystick buttons to the keyboard device. Added warning popups to indicate to user what is wrong.

This commit is contained in:
mjbudd77 2021-08-03 20:48:54 -04:00
parent 10f5988e62
commit 8d7f2032fc
2 changed files with 90 additions and 13 deletions

View File

@ -826,9 +826,10 @@ void GamePadConfDialog_t::oppDirEna(int state)
//---------------------------------------------------- //----------------------------------------------------
void GamePadConfDialog_t::changeButton(int padNo, int x) void GamePadConfDialog_t::changeButton(int padNo, int x)
{ {
//char buf[256]; int devIdx;
//std::string prefix; ButtConfig bmap;
const char *keyNameStr; const char *keyNameStr;
bool mappingValid = true;
if (buttonConfigStatus == 2) if (buttonConfigStatus == 2)
{ {
@ -837,21 +838,67 @@ void GamePadConfDialog_t::changeButton(int padNo, int x)
} }
buttonConfigStatus = 2; buttonConfigStatus = 2;
devIdx = GamePad[padNo].getDeviceIndex();
bmap = GamePad[padNo].bmap[configIndex][x];
ButtonConfigBegin(); ButtonConfigBegin();
button[x]->setText("Waiting"); button[x]->setText("Waiting");
button[x]->setStyleSheet("background-color: green; color: white;"); button[x]->setStyleSheet("background-color: green; color: white;");
DWaitButton(NULL, &GamePad[padNo].bmap[configIndex][x], &buttonConfigStatus); DWaitButton(NULL, &bmap, &buttonConfigStatus);
button[x]->setText("Change"); button[x]->setText("Change");
button[x]->setStyleSheet(NULL); button[x]->setStyleSheet(NULL);
if ( devIdx < 0 )
{ // keyboard
if ( bmap.ButtType == BUTTC_JOYSTICK )
{
QMessageBox::warning( this, tr("Mapping Error"),
tr("Keyboard devices cannot accept joystick button mappings."),
QMessageBox::Cancel, QMessageBox::Cancel );
mappingValid = false;
}
}
else
{ // Joystick/Gamepad
if ( bmap.ButtType == BUTTC_JOYSTICK )
{
jsDev_t *js1 = getJoystickDevice(devIdx);
jsDev_t *js2 = getJoystickDevice(bmap.DeviceNum);
if ( (js1 == NULL) || (js2 == NULL) )
{
mappingValid = false;
}
else
{
if ( (devIdx != bmap.DeviceNum) &&
( strcmp( js1->getGUID(), js2->getGUID() ) != 0 ) )
{
char stmp[256];
sprintf( stmp, "Joystick device GUID MisMatch\n\nSelected device is: \n\t%s\n\nbut button mapping is from: \n\t%s",
js1->getName(), js2->getName() );
QMessageBox::warning( this, tr("Mapping Error"), tr(stmp),
QMessageBox::Cancel, QMessageBox::Cancel );
mappingValid = false;
}
}
}
}
if (buttonConfigStatus != 0) if (buttonConfigStatus != 0)
{ {
keyNameStr = ButtonName(&GamePad[padNo].bmap[configIndex][x]); if ( mappingValid )
keyName[x]->setText( tr(keyNameStr) ); {
lcl[padNo].btn[x].needsSave = 1; GamePad[padNo].bmap[configIndex][x] = bmap;
keyNameStr = ButtonName(&GamePad[padNo].bmap[configIndex][x]);
keyName[x]->setText( tr(keyNameStr) );
lcl[padNo].btn[x].needsSave = 1;
}
} }
ButtonConfigEnd(); ButtonConfigEnd();
@ -882,7 +929,11 @@ void GamePadConfDialog_t::closeEvent(QCloseEvent *event)
event->ignore(); event->ignore();
return; return;
} }
promptToSave(); if ( promptToSave() == QMessageBox::Cancel )
{
event->ignore();
return;
}
printf("GamePad Close Window Event\n"); printf("GamePad Close Window Event\n");
buttonConfigStatus = 0; buttonConfigStatus = 0;
@ -903,7 +954,10 @@ void GamePadConfDialog_t::closeWindow(void)
return; return;
} }
promptToSave(); if ( promptToSave() == QMessageBox::Cancel )
{
return;
}
printf("Close Window\n"); printf("Close Window\n");
buttonConfigStatus = 0; buttonConfigStatus = 0;
@ -1026,6 +1080,19 @@ void GamePadConfDialog_t::btnConfigChanged(int idx)
updateCntrlrDpy(); updateCntrlrDpy();
} }
//---------------------------------------------------- //----------------------------------------------------
void GamePadConfDialog_t::saveAll(void)
{
int prevPort = portNum;
for (int i=0; i<4; i++)
{
portSelect(i);
saveProfileCallback();
}
portSelect(prevPort);
}
//----------------------------------------------------
void GamePadConfDialog_t::saveConfig(void) void GamePadConfDialog_t::saveConfig(void)
{ {
int i; int i;
@ -1172,9 +1239,9 @@ void GamePadConfDialog_t::deleteProfileCallback(void)
loadMapList(); loadMapList();
} }
//---------------------------------------------------- //----------------------------------------------------
void GamePadConfDialog_t::promptToSave(void) int GamePadConfDialog_t::promptToSave(void)
{ {
int i, j, n; int i, j, n, ret;
std::string msg; std::string msg;
QMessageBox msgBox(this); QMessageBox msgBox(this);
char saveRequired = 0; char saveRequired = 0;
@ -1200,7 +1267,7 @@ void GamePadConfDialog_t::promptToSave(void)
if (!saveRequired) if (!saveRequired)
{ {
return; return 0;
} }
sprintf(stmp, "Warning: Gamepad mappings have not been saved for port%c ", (n > 1) ? 's' : ' '); sprintf(stmp, "Warning: Gamepad mappings have not been saved for port%c ", (n > 1) ? 's' : ' ');
@ -1233,7 +1300,16 @@ void GamePadConfDialog_t::promptToSave(void)
msgBox.setIcon(QMessageBox::Warning); msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(tr(msg.c_str())); msgBox.setText(tr(msg.c_str()));
msgBox.exec(); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Ignore | QMessageBox::Cancel);
msgBox.setDefaultButton( QMessageBox::Save );
ret = msgBox.exec();
if ( ret == QMessageBox::Save )
{
saveAll();
}
return ret;
} }
//---------------------------------------------------- //----------------------------------------------------
void GamePadConfDialog_t::newKeyBindingCallback(void) void GamePadConfDialog_t::newKeyBindingCallback(void)

View File

@ -207,7 +207,7 @@ private:
void createNewProfile(const char *name); void createNewProfile(const char *name);
void loadMapList(void); void loadMapList(void);
void saveConfig(void); void saveConfig(void);
void promptToSave(void); int promptToSave(void);
void openFuncEditWindow( int mode, gamepad_function_key_t *k ); void openFuncEditWindow( int mode, gamepad_function_key_t *k );
public slots: public slots:
@ -251,6 +251,7 @@ private slots:
void advBindingViewChanged(bool state); void advBindingViewChanged(bool state);
void advOptResizeDone(void); void advOptResizeDone(void);
void advOptWidthChange(const QVariant &value); void advOptWidthChange(const QVariant &value);
void saveAll(void);
}; };
int openGamePadConfWindow(QWidget *parent); int openGamePadConfWindow(QWidget *parent);