Added load/save input preset file logic for Qt GUI.
This commit is contained in:
parent
f541822557
commit
85cee7fd4a
|
@ -8,6 +8,7 @@
|
|||
#include <SDL.h>
|
||||
#include <QHeaderView>
|
||||
#include <QCloseEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QGroupBox>
|
||||
|
||||
#include "Qt/main.h"
|
||||
|
@ -135,7 +136,7 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent)
|
|||
|
||||
sprintf( stmp, "border: 2px solid #%02X%02X%02X", color.red(), color.green(), color.blue() );
|
||||
|
||||
printf("%s\n", stmp);
|
||||
//printf("%s\n", stmp);
|
||||
nesPortLabel[0]->setAlignment(Qt::AlignCenter);
|
||||
nesPortLabel[1]->setAlignment(Qt::AlignCenter);
|
||||
expPortLabel->setAlignment(Qt::AlignCenter);
|
||||
|
@ -200,6 +201,9 @@ InputConfDialog_t::InputConfDialog_t(QWidget *parent)
|
|||
connect( nesPortConfButton[0], SIGNAL(clicked(void)), this, SLOT(port1Configure(void)) );
|
||||
connect( nesPortConfButton[1], SIGNAL(clicked(void)), this, SLOT(port2Configure(void)) );
|
||||
|
||||
connect( loadConfigButton, SIGNAL(clicked(void)), this, SLOT(openLoadPresetFile(void)) );
|
||||
connect( saveConfigButton, SIGNAL(clicked(void)), this, SLOT(openSavePresetFile(void)) );
|
||||
|
||||
updatePortLabels();
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -277,6 +281,30 @@ void InputConfDialog_t::updatePortLabels(void)
|
|||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void InputConfDialog_t::updatePortComboBoxes(void)
|
||||
{
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
getInputSelection( i, &curNesInput[i], &usrNesInput[i] );
|
||||
|
||||
for (int j=0; j<nesPortComboxBox[i]->count(); j++)
|
||||
{
|
||||
if ( nesPortComboxBox[i]->itemData(j).toInt() == usrNesInput[i] )
|
||||
{
|
||||
nesPortComboxBox[i]->setCurrentIndex( j );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j=0; j<expPortComboxBox->count(); j++)
|
||||
{
|
||||
if ( expPortComboxBox->itemData(j).toInt() == usrNesInput[2] )
|
||||
{
|
||||
expPortComboxBox->setCurrentIndex( j );
|
||||
}
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void InputConfDialog_t::port1Select(int index)
|
||||
{
|
||||
//printf("Port 1 Number:%i \n", index);
|
||||
|
@ -323,13 +351,117 @@ void InputConfDialog_t::port2Configure(void)
|
|||
openPortConfig(1);
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
//void InputConfDialog_t::keyPressEvent(QKeyEvent *event)
|
||||
//{
|
||||
// //printf("Hotkey Window Key Press: 0x%x \n", event->key() );
|
||||
//}
|
||||
////----------------------------------------------------------------------------
|
||||
//void InputConfDialog_t::keyReleaseEvent(QKeyEvent *event)
|
||||
//{
|
||||
// //printf("Hotkey Window Key Release: 0x%x \n", event->key() );
|
||||
//}
|
||||
void InputConfDialog_t::openLoadPresetFile(void)
|
||||
{
|
||||
int ret, useNativeFileDialogVal;
|
||||
QString filename;
|
||||
std::string last;
|
||||
std::string path;
|
||||
const char *baseDir;
|
||||
QFileDialog dialog(this, tr("Load Preset From File") );
|
||||
QDir dir;
|
||||
|
||||
baseDir = FCEUI_GetBaseDirectory();
|
||||
|
||||
path = std::string(baseDir) + "/input/presets/";
|
||||
|
||||
dir.mkpath( QString::fromStdString(path) );
|
||||
|
||||
dialog.setFileMode(QFileDialog::ExistingFile);
|
||||
|
||||
dialog.setNameFilter(tr("Preset File (*.pre *.PRE) ;; All files (*)"));
|
||||
|
||||
dialog.setViewMode(QFileDialog::List);
|
||||
dialog.setFilter( QDir::AllEntries | QDir::AllDirs | QDir::Hidden );
|
||||
dialog.setLabelText( QFileDialog::Accept, tr("Load") );
|
||||
|
||||
dialog.setDirectory( tr(path.c_str()) );
|
||||
|
||||
// Check config option to use native file dialog or not
|
||||
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
|
||||
|
||||
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
|
||||
|
||||
dialog.show();
|
||||
ret = dialog.exec();
|
||||
|
||||
if ( ret )
|
||||
{
|
||||
QStringList fileList;
|
||||
fileList = dialog.selectedFiles();
|
||||
|
||||
if ( fileList.size() > 0 )
|
||||
{
|
||||
filename = fileList[0];
|
||||
}
|
||||
}
|
||||
|
||||
if ( filename.isNull() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
qDebug() << "selected file path : " << filename.toUtf8();
|
||||
|
||||
fceuWrapperLock();
|
||||
loadInputSettingsFromFile( filename.toStdString().c_str() );
|
||||
fceuWrapperUnLock();
|
||||
|
||||
updatePortLabels();
|
||||
updatePortComboBoxes();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void InputConfDialog_t::openSavePresetFile(void)
|
||||
{
|
||||
int ret, useNativeFileDialogVal;
|
||||
QString filename;
|
||||
std::string path;
|
||||
const char *baseDir;
|
||||
QFileDialog dialog(this, tr("Save Preset to File") );
|
||||
QDir dir;
|
||||
|
||||
baseDir = FCEUI_GetBaseDirectory();
|
||||
|
||||
path = std::string(baseDir) + "/input/presets/";
|
||||
|
||||
dir.mkpath( QString::fromStdString(path) );
|
||||
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
|
||||
dialog.setNameFilter(tr("Preset Files (*.pre *.PRE) ;; All files (*)"));
|
||||
|
||||
dialog.setViewMode(QFileDialog::List);
|
||||
dialog.setFilter( QDir::AllEntries | QDir::AllDirs | QDir::Hidden );
|
||||
dialog.setLabelText( QFileDialog::Accept, tr("Save") );
|
||||
dialog.setDefaultSuffix( tr(".pre") );
|
||||
|
||||
dialog.setDirectory( tr(path.c_str()) );
|
||||
|
||||
// Check config option to use native file dialog or not
|
||||
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
|
||||
|
||||
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
|
||||
|
||||
dialog.show();
|
||||
ret = dialog.exec();
|
||||
|
||||
if ( ret )
|
||||
{
|
||||
QStringList fileList;
|
||||
fileList = dialog.selectedFiles();
|
||||
|
||||
if ( fileList.size() > 0 )
|
||||
{
|
||||
filename = fileList[0];
|
||||
}
|
||||
}
|
||||
|
||||
if ( filename.isNull() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
qDebug() << "selected file path : " << filename.toUtf8();
|
||||
|
||||
saveInputSettingsToFile( filename.toStdString().c_str() );
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -29,8 +29,6 @@ class InputConfDialog_t : public QDialog
|
|||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
//void keyPressEvent(QKeyEvent *event);
|
||||
//void keyReleaseEvent(QKeyEvent *event);
|
||||
|
||||
QCheckBox *fourScoreEna;
|
||||
QCheckBox *port2Mic;
|
||||
|
@ -50,6 +48,7 @@ class InputConfDialog_t : public QDialog
|
|||
private:
|
||||
void setInputs(void);
|
||||
void updatePortLabels(void);
|
||||
void updatePortComboBoxes(void);
|
||||
void openPortConfig(int portNum);
|
||||
|
||||
public slots:
|
||||
|
@ -60,6 +59,8 @@ class InputConfDialog_t : public QDialog
|
|||
void port1Select(int index);
|
||||
void port2Select(int index);
|
||||
void expSelect(int index);
|
||||
void openLoadPresetFile(void);
|
||||
void openSavePresetFile(void);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -2060,6 +2060,125 @@ static int stdPortInputDecode( const char *s )
|
|||
return ret;
|
||||
}
|
||||
|
||||
static const char *expPortInputEncode( int v )
|
||||
{
|
||||
const char *s;
|
||||
|
||||
switch ( v )
|
||||
{
|
||||
default:
|
||||
case SIFC_NONE:
|
||||
s = "SIFC_NONE";
|
||||
break;
|
||||
case SIFC_ARKANOID:
|
||||
s = "SIFC_ARKANOID";
|
||||
break;
|
||||
case SIFC_SHADOW:
|
||||
s = "SIFC_SHADOW";
|
||||
break;
|
||||
case SIFC_HYPERSHOT:
|
||||
s = "SIFC_HYPERSHOT";
|
||||
break;
|
||||
case SIFC_FKB:
|
||||
s = "SIFC_FKB";
|
||||
break;
|
||||
case SIFC_MAHJONG:
|
||||
s = "SIFC_MAHJONG";
|
||||
break;
|
||||
case SIFC_QUIZKING:
|
||||
s = "SIFC_QUIZKING";
|
||||
break;
|
||||
case SIFC_FTRAINERA:
|
||||
s = "SIFC_FTRAINERA";
|
||||
break;
|
||||
case SIFC_FTRAINERB:
|
||||
s = "SIFC_FTRAINERB";
|
||||
break;
|
||||
case SIFC_OEKAKIDS:
|
||||
s = "SIFC_OEKAKIDS";
|
||||
break;
|
||||
case SIFC_TOPRIDER:
|
||||
s = "SIFC_TOPRIDER";
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static int expPortInputDecode( const char *s )
|
||||
{
|
||||
int ret = SIFC_NONE;
|
||||
|
||||
if ( s[0] == 0 )
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ( isdigit(s[0]) )
|
||||
{
|
||||
ret = atoi(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( strcmp( s, "SIFC_ARKANOID" ) == 0 )
|
||||
{
|
||||
ret = SIFC_ARKANOID;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_SHADOW" ) == 0 )
|
||||
{
|
||||
ret = SIFC_SHADOW;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_HYPERSHOT" ) == 0 )
|
||||
{
|
||||
ret = SIFC_HYPERSHOT;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_FKB" ) == 0 )
|
||||
{
|
||||
ret = SIFC_FKB;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_MAHJONG" ) == 0 )
|
||||
{
|
||||
ret = SIFC_MAHJONG;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_QUIZKING" ) == 0 )
|
||||
{
|
||||
ret = SIFC_QUIZKING;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_FTRAINERA" ) == 0 )
|
||||
{
|
||||
ret = SIFC_FTRAINERA;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_FTRAINERB" ) == 0 )
|
||||
{
|
||||
ret = SIFC_FTRAINERB;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_OEKAKIDS" ) == 0 )
|
||||
{
|
||||
ret = SIFC_OEKAKIDS;
|
||||
}
|
||||
else if ( strcmp( s, "SIFC_TOPRIDER" ) == 0 )
|
||||
{
|
||||
ret = SIFC_TOPRIDER;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool boolDecode( const char *s )
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
if ( isdigit(s[0]) )
|
||||
{
|
||||
ret = atoi(s) != 0;
|
||||
}
|
||||
else if ( strcasecmp( s, "true" ) == 0 )
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int saveInputSettingsToFile( const char *filename )
|
||||
{
|
||||
QDir dir;
|
||||
|
@ -2099,7 +2218,7 @@ int saveInputSettingsToFile( const char *filename )
|
|||
fprintf( fp, "# Input Port Settings\n");
|
||||
fprintf( fp, "InputTypePort1 = %s \n", stdPortInputEncode( CurInputType[0] ) );
|
||||
fprintf( fp, "InputTypePort2 = %s \n", stdPortInputEncode( CurInputType[1] ) );
|
||||
fprintf( fp, "InputTypeExpPort = %i \n", CurInputType[2] );
|
||||
fprintf( fp, "InputTypeExpPort = %s \n", expPortInputEncode( CurInputType[2] ) );
|
||||
fprintf( fp, "Enable4Score = %i \n", (eoptions & EO_FOURSCORE) ? 1 : 0 );
|
||||
fprintf( fp, "EnableMicPort2 = %i \n", replaceP2StartWithMicrophone );
|
||||
|
||||
|
@ -2199,15 +2318,27 @@ int loadInputSettingsFromFile( const char *filename )
|
|||
{
|
||||
CurInputType[1] = UsrInputType[1] = stdPortInputDecode( val );
|
||||
}
|
||||
else if ( strcmp( id, "InputTypeExpPort" ) == 0 )
|
||||
{
|
||||
CurInputType[2] = UsrInputType[2] = expPortInputDecode( val );
|
||||
}
|
||||
else if ( strcmp( id, "Enable4Score" ) == 0 )
|
||||
{
|
||||
if ( boolDecode( val ) )
|
||||
{
|
||||
eoptions &= ~EO_FOURSCORE;
|
||||
}
|
||||
else
|
||||
{
|
||||
eoptions |= EO_FOURSCORE;
|
||||
}
|
||||
}
|
||||
else if ( strcmp( id, "EnableMicPort2" ) == 0 )
|
||||
{
|
||||
replaceP2StartWithMicrophone = boolDecode( val );
|
||||
}
|
||||
}
|
||||
|
||||
//fprintf( fp, "# Input Port Settings\n");
|
||||
//fprintf( fp, "InputTypePort1 = %i \n", CurInputType[0] );
|
||||
//fprintf( fp, "InputTypePort2 = %i \n", CurInputType[1] );
|
||||
//fprintf( fp, "InputTypeExpPort = %i \n", CurInputType[2] );
|
||||
//fprintf( fp, "Enable4Score = %i \n", (eoptions & EO_FOURSCORE) ? 1 : 0 );
|
||||
//fprintf( fp, "EnableMicPort2 = %i \n", replaceP2StartWithMicrophone );
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue