diff --git a/src/drivers/Qt/GamePadConf.cpp b/src/drivers/Qt/GamePadConf.cpp index eee64188..ec1b7515 100644 --- a/src/drivers/Qt/GamePadConf.cpp +++ b/src/drivers/Qt/GamePadConf.cpp @@ -2,6 +2,7 @@ // #include #include +#include #include "Qt/GamePadConf.h" #include "Qt/main.h" @@ -12,6 +13,29 @@ #include "Qt/sdl-joystick.h" #include "Qt/fceuWrapper.h" +struct GamePadConfigLocalData_t +{ + std::string guid; + std::string profile; + + struct { + + char needsSave; + + } btn[GAMEPAD_NUM_BUTTONS]; + + GamePadConfigLocalData_t(void) + { + for (int i=0; iisConnected() ) { - char stmp[128]; sprintf( stmp, "%i: %s", i, js->getName() ); devSel->addItem( tr(stmp), i ); - } } } @@ -236,6 +260,16 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent) inputTimer->start( 33 ); // 30hz + for (int i=0; igetOption(prefix + "Profile", &lcl[i].profile ); + + lcl[i].guid.assign( GamePad[i].getGUID() ); + } + loadMapList(); } @@ -345,7 +379,17 @@ void GamePadConfDialog_t::updateCntrlrDpy(void) { strcpy( keyNameStr, ButtonName( &GamePad[portNum].bmap[i] ) ); } + keyName[i]->setText( tr(keyNameStr) ); + + //if ( lcl[portNum].btn[i].needsSave ) + //{ + // keyName[i]->setStyleSheet("color: red;"); + //} + //else + //{ + // keyName[i]->setStyleSheet("color: black;"); + //} } } //---------------------------------------------------- @@ -387,6 +431,9 @@ void GamePadConfDialog_t::deviceSelect(int index) } GamePad[portNum].setDeviceIndex( devIdx ); + lcl[portNum].guid.assign( GamePad[portNum].getGUID() ); + lcl[portNum].profile.assign("default"); + loadMapList(); updateCntrlrDpy(); @@ -429,6 +476,7 @@ void GamePadConfDialog_t::changeButton(int padNo, int x) keyName[x]->setText( keyNameStr ); button[x]->setText("Change"); + lcl[padNo].btn[x].needsSave = 1; ButtonConfigEnd (); @@ -440,11 +488,15 @@ void GamePadConfDialog_t::clearButton( int padNo, int x ) GamePad[padNo].bmap[x].ButtonNum = -1; keyName[x]->setText(""); + + lcl[padNo].btn[x].needsSave = 1; } //---------------------------------------------------- void GamePadConfDialog_t::closeEvent(QCloseEvent *event) { - //printf("GamePad Close Window Event\n"); + promptToSave(); + + printf("GamePad Close Window Event\n"); buttonConfigStatus = 0; done(0); event->accept(); @@ -452,7 +504,9 @@ void GamePadConfDialog_t::closeEvent(QCloseEvent *event) //---------------------------------------------------- void GamePadConfDialog_t::closeWindow(void) { - //printf("Close Window\n"); + promptToSave(); + + printf("Close Window\n"); buttonConfigStatus = 0; done(0); } @@ -567,6 +621,7 @@ void GamePadConfDialog_t::clearAllCallback(void) //---------------------------------------------------- void GamePadConfDialog_t::saveConfig(void) { + int i; char stmp[256]; std::string prefix, mapName; @@ -577,15 +632,27 @@ void GamePadConfDialog_t::saveConfig(void) g_config->setOption(prefix + "DeviceGUID", GamePad[portNum].getGUID() ); g_config->setOption(prefix + "Profile" , mapName.c_str() ); + + for (i=0; iaddItem( tr(name) ); + + mapSel->setCurrentIndex( mapSel->count() - 1 ); + saveConfig(); + + sprintf( stmp, "Mapping Created: %s/%s \n", GamePad[portNum].getGUID(), name ); + mapMsg->setText( tr(stmp) ); } //---------------------------------------------------- void GamePadConfDialog_t::newProfileCallback(void) @@ -689,6 +756,70 @@ void GamePadConfDialog_t::deleteProfileCallback(void) loadMapList(); } //---------------------------------------------------- +void GamePadConfDialog_t::promptToSave(void) +{ + int i,j,n; + std::string msg; + QMessageBox msgBox(this); + char saveRequired = 0; + char padNeedsSave[GAMEPAD_NUM_DEVICES]; + char stmp[256]; + + n=0; + for (i=0; i 1) ? 's':' '); + + msg.assign( stmp ); + + j=n; + for (i=0; i 1 ) + { + msg.append(", "); + } + else if ( j == 1 ) + { + msg.append(" and "); + } + } + } + msg.append("."); + + msgBox.setText( tr(msg.c_str()) ); + + msgBox.show(); + //msgBox.resize( 512, 128 ); + msgBox.exec(); +} +//---------------------------------------------------- void GamePadConfDialog_t::updatePeriodic(void) { for (int i=0; isetText( tr(txt) ); keyState[i]->setStyleSheet( style ); + + if ( lcl[portNum].btn[i].needsSave ) + { + keyName[i]->setStyleSheet("color: red;"); + } + else + { + keyName[i]->setStyleSheet("color: black;"); + } } } //---------------------------------------------------- diff --git a/src/drivers/Qt/GamePadConf.h b/src/drivers/Qt/GamePadConf.h index ba24b463..5efafeb3 100644 --- a/src/drivers/Qt/GamePadConf.h +++ b/src/drivers/Qt/GamePadConf.h @@ -62,6 +62,7 @@ class GamePadConfDialog_t : public QDialog void createNewProfile( const char *name ); void loadMapList(void); void saveConfig(void); + void promptToSave(void); public slots: void closeWindow(void); diff --git a/src/drivers/Qt/sdl-joystick.cpp b/src/drivers/Qt/sdl-joystick.cpp index 57c2f616..8e0ddcd3 100644 --- a/src/drivers/Qt/sdl-joystick.cpp +++ b/src/drivers/Qt/sdl-joystick.cpp @@ -742,7 +742,6 @@ int GamePad_t::saveMappingToFile( const char *filename, const char *txtMap ) //******************************************************************************** int GamePad_t::createProfile( const char *name ) { - char txtMap[256]; const char *guid = NULL; const char *baseDir = FCEUI_GetBaseDirectory(); std::string path; @@ -771,13 +770,11 @@ int GamePad_t::createProfile( const char *name ) dir.mkpath( QString::fromStdString(path) ); //printf("DIR: '%s'\n", path.c_str() ); - path += "/" + std::string(name) + ".txt"; + //path += "/" + std::string(name) + ".txt"; //printf("File: '%s'\n", path.c_str() ); - getDefaultMap( txtMap, guid ); - - saveMappingToFile( path.c_str(), txtMap ); + saveCurrentMapToFile( name ); return 0; }