For Qt GUI, added option to have up to 3 alternate gamepad button bindings in addition to the primary mapping.
This commit is contained in:
parent
f76df49bf8
commit
da084fb184
|
@ -137,6 +137,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
||||||
mainWidget = new QWidget();
|
mainWidget = new QWidget();
|
||||||
|
|
||||||
portNum = 0;
|
portNum = 0;
|
||||||
|
configIndex = 0;
|
||||||
buttonConfigStatus = 1;
|
buttonConfigStatus = 1;
|
||||||
|
|
||||||
inputTimer = new QTimer(this);
|
inputTimer = new QTimer(this);
|
||||||
|
@ -295,9 +296,24 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
||||||
g_config->getOption("SDL.Input.EnableOppositeDirectionals", &opposite_dirs);
|
g_config->getOption("SDL.Input.EnableOppositeDirectionals", &opposite_dirs);
|
||||||
udlr_chkbox->setChecked(opposite_dirs);
|
udlr_chkbox->setChecked(opposite_dirs);
|
||||||
|
|
||||||
|
confTabBar = new QTabBar();
|
||||||
frame2 = new QGroupBox(tr("Current Active Button Mappings:"));
|
frame2 = new QGroupBox(tr("Current Active Button Mappings:"));
|
||||||
grid = new QGridLayout();
|
grid = new QGridLayout();
|
||||||
|
|
||||||
|
confTabBar->addTab( tr("Pri") );
|
||||||
|
confTabBar->addTab( tr("Alt 1") );
|
||||||
|
confTabBar->addTab( tr("Alt 2") );
|
||||||
|
confTabBar->addTab( tr("Alt 3") );
|
||||||
|
|
||||||
|
confTabBar->setTabToolTip( 0, tr("Primary Button Map") );
|
||||||
|
confTabBar->setTabToolTip( 1, tr("Alternate Button Map #1") );
|
||||||
|
confTabBar->setTabToolTip( 2, tr("Alternate Button Map #2") );
|
||||||
|
confTabBar->setTabToolTip( 3, tr("Alternate Button Map #3") );
|
||||||
|
|
||||||
|
confTabBar->setCurrentIndex(0);
|
||||||
|
|
||||||
|
connect( confTabBar, SIGNAL(currentChanged(int)), this, SLOT(btnConfigChanged(int)) );
|
||||||
|
|
||||||
//grid-> setHorizontalSpacing(10);
|
//grid-> setHorizontalSpacing(10);
|
||||||
|
|
||||||
frame2->setLayout(grid);
|
frame2->setLayout(grid);
|
||||||
|
@ -391,6 +407,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
||||||
vbox1->addWidget(frame1);
|
vbox1->addWidget(frame1);
|
||||||
vbox1->addLayout(hbox2);
|
vbox1->addLayout(hbox2);
|
||||||
|
|
||||||
|
vbox2->addWidget(confTabBar);
|
||||||
vbox2->addWidget(frame2);
|
vbox2->addWidget(frame2);
|
||||||
vbox2->addLayout(hbox1);
|
vbox2->addLayout(hbox1);
|
||||||
|
|
||||||
|
@ -705,14 +722,14 @@ void GamePadConfDialog_t::updateCntrlrDpy(void)
|
||||||
|
|
||||||
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
||||||
{
|
{
|
||||||
if (GamePad[portNum].bmap[i].ButtType == BUTTC_KEYBOARD)
|
if (GamePad[portNum].bmap[configIndex][i].ButtType == BUTTC_KEYBOARD)
|
||||||
{
|
{
|
||||||
snprintf(keyNameStr, sizeof(keyNameStr), "%s",
|
snprintf(keyNameStr, sizeof(keyNameStr), "%s",
|
||||||
SDL_GetKeyName(GamePad[portNum].bmap[i].ButtonNum));
|
SDL_GetKeyName(GamePad[portNum].bmap[configIndex][i].ButtonNum));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(keyNameStr, ButtonName(&GamePad[portNum].bmap[i]));
|
strcpy(keyNameStr, ButtonName(&GamePad[portNum].bmap[configIndex][i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
keyName[i]->setText(tr(keyNameStr));
|
keyName[i]->setText(tr(keyNameStr));
|
||||||
|
@ -819,14 +836,14 @@ void GamePadConfDialog_t::changeButton(int padNo, int x)
|
||||||
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[x], &buttonConfigStatus);
|
DWaitButton(NULL, &GamePad[padNo].bmap[configIndex][x], &buttonConfigStatus);
|
||||||
|
|
||||||
button[x]->setText("Change");
|
button[x]->setText("Change");
|
||||||
button[x]->setStyleSheet(NULL);
|
button[x]->setStyleSheet(NULL);
|
||||||
|
|
||||||
if (buttonConfigStatus != 0)
|
if (buttonConfigStatus != 0)
|
||||||
{
|
{
|
||||||
keyNameStr = ButtonName(&GamePad[padNo].bmap[x]);
|
keyNameStr = ButtonName(&GamePad[padNo].bmap[configIndex][x]);
|
||||||
keyName[x]->setText( tr(keyNameStr) );
|
keyName[x]->setText( tr(keyNameStr) );
|
||||||
lcl[padNo].btn[x].needsSave = 1;
|
lcl[padNo].btn[x].needsSave = 1;
|
||||||
}
|
}
|
||||||
|
@ -838,7 +855,7 @@ void GamePadConfDialog_t::changeButton(int padNo, int x)
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
void GamePadConfDialog_t::clearButton(int padNo, int x)
|
void GamePadConfDialog_t::clearButton(int padNo, int x)
|
||||||
{
|
{
|
||||||
GamePad[padNo].bmap[x].ButtonNum = -1;
|
GamePad[padNo].bmap[configIndex][x].ButtonNum = -1;
|
||||||
|
|
||||||
//keyName[x]->setText( tr("") );
|
//keyName[x]->setText( tr("") );
|
||||||
keyName[x]->clear();
|
keyName[x]->clear();
|
||||||
|
@ -996,6 +1013,13 @@ void GamePadConfDialog_t::clearAllCallback(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
void GamePadConfDialog_t::btnConfigChanged(int idx)
|
||||||
|
{
|
||||||
|
configIndex = idx;
|
||||||
|
|
||||||
|
updateCntrlrDpy();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
void GamePadConfDialog_t::saveConfig(void)
|
void GamePadConfDialog_t::saveConfig(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -1592,7 +1616,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
painter.fillRect(cBtn, black);
|
painter.fillRect(cBtn, black);
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[4].state)
|
if (GamePad[portNum].bmapState[4])
|
||||||
{
|
{
|
||||||
painter.fillRect(upBtn, green);
|
painter.fillRect(upBtn, green);
|
||||||
}
|
}
|
||||||
|
@ -1601,7 +1625,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.fillRect(upBtn, black);
|
painter.fillRect(upBtn, black);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[5].state)
|
if (GamePad[portNum].bmapState[5])
|
||||||
{
|
{
|
||||||
painter.fillRect(dnBtn, green);
|
painter.fillRect(dnBtn, green);
|
||||||
}
|
}
|
||||||
|
@ -1610,7 +1634,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.fillRect(dnBtn, black);
|
painter.fillRect(dnBtn, black);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[6].state)
|
if (GamePad[portNum].bmapState[6])
|
||||||
{
|
{
|
||||||
painter.fillRect(lBtn, green);
|
painter.fillRect(lBtn, green);
|
||||||
}
|
}
|
||||||
|
@ -1619,7 +1643,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.fillRect(lBtn, black);
|
painter.fillRect(lBtn, black);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[7].state)
|
if (GamePad[portNum].bmapState[7])
|
||||||
{
|
{
|
||||||
painter.fillRect(rBtn, green);
|
painter.fillRect(rBtn, green);
|
||||||
}
|
}
|
||||||
|
@ -1637,7 +1661,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
selBtn.setRect(x + (bw / 3), y, bw, bh);
|
selBtn.setRect(x + (bw / 3), y, bw, bh);
|
||||||
stBtn.setRect(x + (5 * bw) / 3, y, bw, bh);
|
stBtn.setRect(x + (5 * bw) / 3, y, bw, bh);
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[2].state)
|
if (GamePad[portNum].bmapState[2])
|
||||||
{
|
{
|
||||||
painter.fillRect(selBtn, green);
|
painter.fillRect(selBtn, green);
|
||||||
}
|
}
|
||||||
|
@ -1646,7 +1670,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.fillRect(selBtn, gray);
|
painter.fillRect(selBtn, gray);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[3].state)
|
if (GamePad[portNum].bmapState[3])
|
||||||
{
|
{
|
||||||
painter.fillRect(stBtn, green);
|
painter.fillRect(stBtn, green);
|
||||||
}
|
}
|
||||||
|
@ -1689,7 +1713,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
bBtn.setRect(x + ws, y, bw, bh);
|
bBtn.setRect(x + ws, y, bw, bh);
|
||||||
aBtn.setRect(x + bw + (2 * ws), y, bw, bh);
|
aBtn.setRect(x + bw + (2 * ws), y, bw, bh);
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[9].state)
|
if (GamePad[portNum].bmapState[9])
|
||||||
{
|
{
|
||||||
painter.setBrush(Qt::green);
|
painter.setBrush(Qt::green);
|
||||||
}
|
}
|
||||||
|
@ -1701,7 +1725,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.drawEllipse(tbBtn);
|
painter.drawEllipse(tbBtn);
|
||||||
drawLetterOnButton(painter, tbBtn, black, 'B');
|
drawLetterOnButton(painter, tbBtn, black, 'B');
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[8].state)
|
if (GamePad[portNum].bmapState[8])
|
||||||
{
|
{
|
||||||
painter.setBrush(Qt::green);
|
painter.setBrush(Qt::green);
|
||||||
}
|
}
|
||||||
|
@ -1713,7 +1737,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.drawEllipse(taBtn);
|
painter.drawEllipse(taBtn);
|
||||||
drawLetterOnButton(painter, taBtn, black, 'A');
|
drawLetterOnButton(painter, taBtn, black, 'A');
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[1].state)
|
if (GamePad[portNum].bmapState[1])
|
||||||
{
|
{
|
||||||
painter.setBrush(Qt::green);
|
painter.setBrush(Qt::green);
|
||||||
}
|
}
|
||||||
|
@ -1725,7 +1749,7 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
painter.drawEllipse(bBtn);
|
painter.drawEllipse(bBtn);
|
||||||
drawLetterOnButton(painter, bBtn, black, 'B');
|
drawLetterOnButton(painter, bBtn, black, 'B');
|
||||||
|
|
||||||
if (GamePad[portNum].bmap[0].state)
|
if (GamePad[portNum].bmapState[0])
|
||||||
{
|
{
|
||||||
painter.setBrush(Qt::green);
|
painter.setBrush(Qt::green);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QTabBar>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
@ -178,6 +179,7 @@ protected:
|
||||||
QLabel *keyState[GAMEPAD_NUM_BUTTONS];
|
QLabel *keyState[GAMEPAD_NUM_BUTTONS];
|
||||||
GamePadConfigButton_t *button[GAMEPAD_NUM_BUTTONS];
|
GamePadConfigButton_t *button[GAMEPAD_NUM_BUTTONS];
|
||||||
GamePadView_t *gpView;
|
GamePadView_t *gpView;
|
||||||
|
QTabBar *confTabBar;
|
||||||
|
|
||||||
QPushButton *newKeyBindBtn;
|
QPushButton *newKeyBindBtn;
|
||||||
QPushButton *editKeyBindBtn;
|
QPushButton *editKeyBindBtn;
|
||||||
|
@ -185,6 +187,7 @@ protected:
|
||||||
QTreeWidget *keyBindTree;
|
QTreeWidget *keyBindTree;
|
||||||
|
|
||||||
int portNum;
|
int portNum;
|
||||||
|
int configIndex;
|
||||||
int buttonConfigStatus;
|
int buttonConfigStatus;
|
||||||
int changeSeqStatus; // status of sequentally changing buttons mechanism
|
int changeSeqStatus; // status of sequentally changing buttons mechanism
|
||||||
// 0 - we can start new change process
|
// 0 - we can start new change process
|
||||||
|
@ -231,6 +234,7 @@ private slots:
|
||||||
void clearButton8(void);
|
void clearButton8(void);
|
||||||
void clearButton9(void);
|
void clearButton9(void);
|
||||||
void clearAllCallback(void);
|
void clearAllCallback(void);
|
||||||
|
void btnConfigChanged(int index);
|
||||||
void ena4score(int state);
|
void ena4score(int state);
|
||||||
void oppDirEna(int state);
|
void oppDirEna(int state);
|
||||||
void portSelect(int index);
|
void portSelect(int index);
|
||||||
|
|
|
@ -1412,9 +1412,10 @@ UpdateGamepad(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 JS = 0;
|
uint32 JS = 0;
|
||||||
int x;
|
int x,c;
|
||||||
int wg;
|
int wg;
|
||||||
bool fire;
|
bool fire;
|
||||||
|
char btns[GAMEPAD_NUM_BUTTONS];
|
||||||
|
|
||||||
int opposite_dirs;
|
int opposite_dirs;
|
||||||
g_config->getOption("SDL.Input.EnableOppositeDirectionals", &opposite_dirs);
|
g_config->getOption("SDL.Input.EnableOppositeDirectionals", &opposite_dirs);
|
||||||
|
@ -1424,59 +1425,71 @@ UpdateGamepad(void)
|
||||||
{
|
{
|
||||||
bool left = false;
|
bool left = false;
|
||||||
bool up = false;
|
bool up = false;
|
||||||
// a, b, select, start, up, down, left, right
|
memset( btns, 0, sizeof(btns) );
|
||||||
for (x = 0; x < 8; x++)
|
|
||||||
|
for (c = 0; c < GamePad_t::NUM_CONFIG; c++)
|
||||||
{
|
{
|
||||||
if (DTestButton(&GamePad[wg].bmap[x]))
|
// a, b, select, start, up, down, left, right
|
||||||
|
for (x = 0; x < 8; x++)
|
||||||
{
|
{
|
||||||
//printf("GamePad%i Button Hit: %i \n", wg, x );
|
if (DTestButton(&GamePad[wg].bmap[c][x]))
|
||||||
if (opposite_dirs == 0)
|
|
||||||
{
|
{
|
||||||
// test for left+right and up+down
|
btns[x] = 1;
|
||||||
if (x == 4)
|
//printf("GamePad%i Button Hit: %i \n", wg, x );
|
||||||
|
if (opposite_dirs == 0)
|
||||||
{
|
{
|
||||||
up = true;
|
// test for left+right and up+down
|
||||||
|
if (x == 4)
|
||||||
|
{
|
||||||
|
up = true;
|
||||||
|
}
|
||||||
|
if ((x == 5) && (up == true))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (x == 6)
|
||||||
|
{
|
||||||
|
left = true;
|
||||||
|
}
|
||||||
|
if ((x == 7) && (left == true))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((x == 5) && (up == true))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (x == 6)
|
|
||||||
{
|
|
||||||
left = true;
|
|
||||||
}
|
|
||||||
if ((x == 7) && (left == true))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
JS |= (1 << x) << (wg << 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int four_button_exit;
|
|
||||||
g_config->getOption("SDL.ABStartSelectExit", &four_button_exit);
|
|
||||||
// if a+b+start+select is pressed, exit
|
|
||||||
if (four_button_exit && JS == 15)
|
|
||||||
{
|
|
||||||
FCEUI_printf("all buttons pressed, exiting\n");
|
|
||||||
CloseGame();
|
|
||||||
FCEUI_Kill();
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// rapid-fire a, rapid-fire b
|
|
||||||
for (x = 0; x < 2; x++)
|
|
||||||
{
|
|
||||||
if (DTestButton(&GamePad[wg].bmap[8 + x]))
|
|
||||||
{
|
|
||||||
fire = GetAutoFireState(x);
|
|
||||||
|
|
||||||
if (fire)
|
|
||||||
{
|
|
||||||
JS |= (1 << x) << (wg << 3);
|
JS |= (1 << x) << (wg << 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int four_button_exit;
|
||||||
|
g_config->getOption("SDL.ABStartSelectExit", &four_button_exit);
|
||||||
|
// if a+b+start+select is pressed, exit
|
||||||
|
if (four_button_exit && JS == 15)
|
||||||
|
{
|
||||||
|
FCEUI_printf("all buttons pressed, exiting\n");
|
||||||
|
CloseGame();
|
||||||
|
FCEUI_Kill();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// rapid-fire a, rapid-fire b
|
||||||
|
for (x = 0; x < 2; x++)
|
||||||
|
{
|
||||||
|
if (DTestButton(&GamePad[wg].bmap[c][8 + x]))
|
||||||
|
{
|
||||||
|
fire = GetAutoFireState(x);
|
||||||
|
|
||||||
|
if (fire)
|
||||||
|
{
|
||||||
|
JS |= (1 << x) << (wg << 3);
|
||||||
|
}
|
||||||
|
btns[8+x] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x = 0; x < GAMEPAD_NUM_BUTTONS; x++)
|
||||||
|
{
|
||||||
|
GamePad[wg].bmapState[x] = btns[x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2768,7 +2781,7 @@ void UpdateInput(Config *config)
|
||||||
// Definitions from main.h:
|
// Definitions from main.h:
|
||||||
// GamePad defaults
|
// GamePad defaults
|
||||||
const char *GamePadNames[GAMEPAD_NUM_BUTTONS] = {"A", "B", "Select", "Start",
|
const char *GamePadNames[GAMEPAD_NUM_BUTTONS] = {"A", "B", "Select", "Start",
|
||||||
"Up", "Down", "Left", "Right", "TurboA", "TurboB"};
|
"Up", "Down", "Left", "Right", "TurboA", "TurboB"};
|
||||||
const char *DefaultGamePadDevice[GAMEPAD_NUM_DEVICES] =
|
const char *DefaultGamePadDevice[GAMEPAD_NUM_DEVICES] =
|
||||||
{"Keyboard", "None", "None", "None"};
|
{"Keyboard", "None", "None", "None"};
|
||||||
const int DefaultGamePad[GAMEPAD_NUM_DEVICES][GAMEPAD_NUM_BUTTONS] =
|
const int DefaultGamePad[GAMEPAD_NUM_DEVICES][GAMEPAD_NUM_BUTTONS] =
|
||||||
|
|
|
@ -236,23 +236,28 @@ void nesGamePadMap_t::clearMapping(void)
|
||||||
guid[0] = 0;
|
guid[0] = 0;
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
os[0] = 0;
|
os[0] = 0;
|
||||||
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
|
||||||
|
for (int c = 0; c < 4; c++)
|
||||||
{
|
{
|
||||||
btn[i][0] = 0;
|
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
||||||
|
{
|
||||||
|
conf[c].btn[i][0] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
int nesGamePadMap_t::parseMapping(const char *map)
|
int nesGamePadMap_t::parseMapping(const char *map)
|
||||||
{
|
{
|
||||||
int i, j, k, bIdx;
|
int i, j, k, c, bIdx;
|
||||||
char id[32][64];
|
char id[32][64];
|
||||||
char val[32][64];
|
char val[32][64];
|
||||||
|
|
||||||
clearMapping();
|
//clearMapping();
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
k = 0;
|
k = 0;
|
||||||
|
c = 0;
|
||||||
|
|
||||||
while (map[i])
|
while (map[i])
|
||||||
{
|
{
|
||||||
|
@ -304,7 +309,11 @@ int nesGamePadMap_t::parseMapping(const char *map)
|
||||||
//printf(" '%s' = '%s' %i \n", id[i], val[i], bIdx );
|
//printf(" '%s' = '%s' %i \n", id[i], val[i], bIdx );
|
||||||
if (bIdx >= 0)
|
if (bIdx >= 0)
|
||||||
{
|
{
|
||||||
strcpy(btn[bIdx], val[i]);
|
strcpy( conf[c].btn[bIdx], val[i]);
|
||||||
|
}
|
||||||
|
else if (strcmp(id[i], "config") == 0)
|
||||||
|
{
|
||||||
|
c = atoi(val[i]);
|
||||||
}
|
}
|
||||||
else if (strcmp(id[i], "platform") == 0)
|
else if (strcmp(id[i], "platform") == 0)
|
||||||
{
|
{
|
||||||
|
@ -319,12 +328,15 @@ GamePad_t::GamePad_t(void)
|
||||||
devIdx = -1;
|
devIdx = -1;
|
||||||
portNum = 0;
|
portNum = 0;
|
||||||
|
|
||||||
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
for (int c = 0; c < NUM_CONFIG; c++)
|
||||||
{
|
{
|
||||||
bmap[i].ButtType = BUTTC_KEYBOARD;
|
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
||||||
bmap[i].DeviceNum = -1;
|
{
|
||||||
bmap[i].ButtonNum = -1;
|
bmap[c][i].ButtType = BUTTC_KEYBOARD;
|
||||||
bmap[i].state = 0;
|
bmap[c][i].DeviceNum = -1;
|
||||||
|
bmap[c][i].ButtonNum = -1;
|
||||||
|
bmap[c][i].state = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
|
@ -548,95 +560,20 @@ int GamePad_t::convText2ButtConfig( const char *txt, ButtConfig *bmap )
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
int GamePad_t::setMapping(nesGamePadMap_t *gpm)
|
int GamePad_t::setMapping(nesGamePadMap_t *gpm)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
for (int c = 0; c < NUM_CONFIG; c++)
|
||||||
{
|
{
|
||||||
bmap[i].ButtType = BUTTC_KEYBOARD;
|
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
||||||
bmap[i].DeviceNum = -1;
|
|
||||||
bmap[i].ButtonNum = -1;
|
|
||||||
|
|
||||||
if (gpm->btn[i][0] == 0)
|
|
||||||
{
|
{
|
||||||
continue;
|
bmap[c][i].ButtType = BUTTC_KEYBOARD;
|
||||||
|
bmap[c][i].DeviceNum = -1;
|
||||||
|
bmap[c][i].ButtonNum = -1;
|
||||||
|
|
||||||
|
if (gpm->conf[c].btn[i][0] == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
convText2ButtConfig( gpm->conf[c].btn[i], &bmap[c][i] );
|
||||||
}
|
}
|
||||||
convText2ButtConfig( gpm->btn[i], &bmap[i] );
|
|
||||||
|
|
||||||
//if (gpm->btn[i][0] == 'k')
|
|
||||||
//{
|
|
||||||
// SDL_Keycode key;
|
|
||||||
|
|
||||||
// bmap[i].ButtType = BUTTC_KEYBOARD;
|
|
||||||
// bmap[i].DeviceNum = -1;
|
|
||||||
|
|
||||||
// key = SDL_GetKeyFromName(&gpm->btn[i][1]);
|
|
||||||
|
|
||||||
// if (key != SDLK_UNKNOWN)
|
|
||||||
// {
|
|
||||||
// bmap[i].ButtonNum = key;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// bmap[i].ButtonNum = -1;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//else if ((gpm->btn[i][0] == 'b') && isdigit(gpm->btn[i][1]))
|
|
||||||
//{
|
|
||||||
// bmap[i].ButtType = BUTTC_JOYSTICK;
|
|
||||||
// bmap[i].DeviceNum = devIdx;
|
|
||||||
// bmap[i].ButtonNum = atoi(&gpm->btn[i][1]);
|
|
||||||
//}
|
|
||||||
//else if ((gpm->btn[i][0] == 'h') && isdigit(gpm->btn[i][1]) &&
|
|
||||||
// (gpm->btn[i][2] == '.') && isdigit(gpm->btn[i][3]))
|
|
||||||
//{
|
|
||||||
// int hatIdx, hatVal;
|
|
||||||
|
|
||||||
// hatIdx = gpm->btn[i][1] - '0';
|
|
||||||
// hatVal = atoi(&gpm->btn[i][3]);
|
|
||||||
|
|
||||||
// bmap[i].ButtType = BUTTC_JOYSTICK;
|
|
||||||
// bmap[i].DeviceNum = devIdx;
|
|
||||||
// bmap[i].ButtonNum = 0x2000 | ((hatIdx & 0x1F) << 8) | (hatVal & 0xFF);
|
|
||||||
//}
|
|
||||||
//else if ((gpm->btn[i][0] == 'a') || (gpm->btn[i][1] == 'a'))
|
|
||||||
//{
|
|
||||||
// int l = 0, axisIdx = 0, axisSign = 0;
|
|
||||||
|
|
||||||
// l = 0;
|
|
||||||
// if (gpm->btn[i][l] == '-')
|
|
||||||
// {
|
|
||||||
// axisSign = 1;
|
|
||||||
// l++;
|
|
||||||
// }
|
|
||||||
// else if (gpm->btn[i][l] == '+')
|
|
||||||
// {
|
|
||||||
// axisSign = 0;
|
|
||||||
// l++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (gpm->btn[i][l] == 'a')
|
|
||||||
// {
|
|
||||||
// l++;
|
|
||||||
// }
|
|
||||||
// if (isdigit(gpm->btn[i][l]))
|
|
||||||
// {
|
|
||||||
// axisIdx = atoi(&gpm->btn[i][l]);
|
|
||||||
|
|
||||||
// while (isdigit(gpm->btn[i][l]))
|
|
||||||
// l++;
|
|
||||||
// }
|
|
||||||
// if (gpm->btn[i][l] == '-')
|
|
||||||
// {
|
|
||||||
// axisSign = 1;
|
|
||||||
// l++;
|
|
||||||
// }
|
|
||||||
// else if (gpm->btn[i][l] == '+')
|
|
||||||
// {
|
|
||||||
// axisSign = 0;
|
|
||||||
// l++;
|
|
||||||
// }
|
|
||||||
// bmap[i].ButtType = BUTTC_JOYSTICK;
|
|
||||||
// bmap[i].DeviceNum = devIdx;
|
|
||||||
// bmap[i].ButtonNum = 0x8000 | (axisSign ? 0x4000 : 0) | (axisIdx & 0xFF);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -651,14 +588,12 @@ int GamePad_t::setMapping(const char *map)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
int GamePad_t::getMapFromFile(const char *filename, char *out)
|
int GamePad_t::getMapFromFile(const char *filename, nesGamePadMap_t *gpm)
|
||||||
{
|
{
|
||||||
int i = 0, j = 0;
|
int i = 0;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char line[256];
|
char line[256];
|
||||||
|
|
||||||
out[0] = 0;
|
|
||||||
|
|
||||||
fp = ::fopen(filename, "r");
|
fp = ::fopen(filename, "r");
|
||||||
|
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
|
@ -682,27 +617,15 @@ int GamePad_t::getMapFromFile(const char *filename, char *out)
|
||||||
continue; // need at least 32 chars for a valid line entry
|
continue; // need at least 32 chars for a valid line entry
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
|
||||||
while (isspace(line[i]))
|
while (isspace(line[i]))
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
while (line[i] != 0)
|
gpm->parseMapping( &line[i] );
|
||||||
{
|
|
||||||
out[j] = line[i];
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
out[j] = 0;
|
|
||||||
|
|
||||||
if (j < 34)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
::fclose(fp);
|
::fclose(fp);
|
||||||
|
|
||||||
return (j < 34);
|
return 0;
|
||||||
}
|
}
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
int GamePad_t::deleteHotKeyMappings(void)
|
int GamePad_t::deleteHotKeyMappings(void)
|
||||||
|
@ -842,13 +765,11 @@ int GamePad_t::loadHotkeyMapFromFile(const char *filename)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
int GamePad_t::getDefaultMap(char *out, const char *guid)
|
int GamePad_t::getDefaultMap(const char *guid)
|
||||||
{
|
{
|
||||||
char txtMap[256];
|
|
||||||
const char *baseDir = FCEUI_GetBaseDirectory();
|
const char *baseDir = FCEUI_GetBaseDirectory();
|
||||||
std::string path;
|
std::string path;
|
||||||
|
nesGamePadMap_t gpm;
|
||||||
out[0] = 0;
|
|
||||||
|
|
||||||
if (devIdx < 0)
|
if (devIdx < 0)
|
||||||
{
|
{
|
||||||
|
@ -868,10 +789,10 @@ int GamePad_t::getDefaultMap(char *out, const char *guid)
|
||||||
|
|
||||||
path = std::string(baseDir) + "/input/" + std::string(guid) + "/default.txt";
|
path = std::string(baseDir) + "/input/" + std::string(guid) + "/default.txt";
|
||||||
|
|
||||||
if (getMapFromFile(path.c_str(), txtMap) == 0)
|
if (getMapFromFile(path.c_str(), &gpm) == 0)
|
||||||
{
|
{
|
||||||
printf("Using Mapping From File: %s\n", path.c_str());
|
//printf("Using Mapping From File: %s\n", path.c_str());
|
||||||
strcpy(out, txtMap);
|
setMapping(&gpm);
|
||||||
loadHotkeyMapFromFile( path.c_str() );
|
loadHotkeyMapFromFile( path.c_str() );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -887,7 +808,9 @@ int GamePad_t::getDefaultMap(char *out, const char *guid)
|
||||||
if (sdlMapping == NULL)
|
if (sdlMapping == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strcpy(out, sdlMapping);
|
gpm.parseMapping(sdlMapping);
|
||||||
|
|
||||||
|
setMapping(&gpm);
|
||||||
|
|
||||||
SDL_free(sdlMapping);
|
SDL_free(sdlMapping);
|
||||||
|
|
||||||
|
@ -900,9 +823,9 @@ int GamePad_t::getDefaultMap(char *out, const char *guid)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < GAMEPAD_NUM_BUTTONS; x++)
|
for (int x = 0; x < GAMEPAD_NUM_BUTTONS; x++)
|
||||||
{
|
{
|
||||||
bmap[x].ButtType = BUTTC_KEYBOARD;
|
bmap[0][x].ButtType = BUTTC_KEYBOARD;
|
||||||
bmap[x].DeviceNum = 0;
|
bmap[0][x].DeviceNum = 0;
|
||||||
bmap[x].ButtonNum = DefaultGamePad[portNum][x];
|
bmap[0][x].ButtonNum = DefaultGamePad[portNum][x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -911,20 +834,14 @@ int GamePad_t::getDefaultMap(char *out, const char *guid)
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
int GamePad_t::loadDefaults(void)
|
int GamePad_t::loadDefaults(void)
|
||||||
{
|
{
|
||||||
char txtMap[256];
|
getDefaultMap();
|
||||||
|
|
||||||
if (getDefaultMap(txtMap) == 0)
|
|
||||||
{
|
|
||||||
//printf("Map:%s\n", txtMap );
|
|
||||||
setMapping(txtMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
int GamePad_t::loadProfile(const char *name, const char *guid)
|
int GamePad_t::loadProfile(const char *name, const char *guid)
|
||||||
{
|
{
|
||||||
char txtMap[256];
|
nesGamePadMap_t gpm;
|
||||||
const char *baseDir = FCEUI_GetBaseDirectory();
|
const char *baseDir = FCEUI_GetBaseDirectory();
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
|
@ -949,9 +866,9 @@ int GamePad_t::loadProfile(const char *name, const char *guid)
|
||||||
|
|
||||||
//printf("Using File: %s\n", path.c_str() );
|
//printf("Using File: %s\n", path.c_str() );
|
||||||
|
|
||||||
if (getMapFromFile(path.c_str(), txtMap) == 0)
|
if (getMapFromFile(path.c_str(), &gpm) == 0)
|
||||||
{
|
{
|
||||||
setMapping(txtMap);
|
setMapping( &gpm );
|
||||||
loadHotkeyMapFromFile( path.c_str() );
|
loadHotkeyMapFromFile( path.c_str() );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -961,7 +878,7 @@ int GamePad_t::loadProfile(const char *name, const char *guid)
|
||||||
//********************************************************************************
|
//********************************************************************************
|
||||||
int GamePad_t::saveCurrentMapToFile(const char *name)
|
int GamePad_t::saveCurrentMapToFile(const char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i,c;
|
||||||
char stmp[256];
|
char stmp[256];
|
||||||
const char *guid = NULL;
|
const char *guid = NULL;
|
||||||
const char *baseDir = FCEUI_GetBaseDirectory();
|
const char *baseDir = FCEUI_GetBaseDirectory();
|
||||||
|
@ -988,50 +905,57 @@ int GamePad_t::saveCurrentMapToFile(const char *name)
|
||||||
|
|
||||||
path += "/" + std::string(name) + ".txt";
|
path += "/" + std::string(name) + ".txt";
|
||||||
|
|
||||||
output.assign(guid);
|
for (c = 0; c < NUM_CONFIG; c++)
|
||||||
output.append(",");
|
|
||||||
output.append(name);
|
|
||||||
output.append(",");
|
|
||||||
|
|
||||||
for (i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
|
||||||
{
|
{
|
||||||
if (bmap[i].ButtType == BUTTC_KEYBOARD)
|
output.append(guid);
|
||||||
|
output.append(",");
|
||||||
|
output.append(name);
|
||||||
|
output.append(",");
|
||||||
|
output.append("config:");
|
||||||
|
sprintf( stmp, "%i,", c );
|
||||||
|
output.append(stmp);
|
||||||
|
|
||||||
|
for (i = 0; i < GAMEPAD_NUM_BUTTONS; i++)
|
||||||
{
|
{
|
||||||
sprintf(stmp, "k%s", SDL_GetKeyName(bmap[i].ButtonNum));
|
if (bmap[c][i].ButtType == BUTTC_KEYBOARD)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (bmap[i].ButtonNum & 0x2000)
|
|
||||||
{
|
{
|
||||||
/* Hat "button" */
|
sprintf(stmp, "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum));
|
||||||
sprintf(stmp, "h%i.%i",
|
|
||||||
(bmap[i].ButtonNum >> 8) & 0x1F, bmap[i].ButtonNum & 0xFF);
|
|
||||||
}
|
|
||||||
else if (bmap[i].ButtonNum & 0x8000)
|
|
||||||
{
|
|
||||||
/* Axis "button" */
|
|
||||||
sprintf(stmp, "%ca%i",
|
|
||||||
(bmap[i].ButtonNum & 0x4000) ? '-' : '+', bmap[i].ButtonNum & 0x3FFF);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Button */
|
if (bmap[c][i].ButtonNum & 0x2000)
|
||||||
sprintf(stmp, "b%i", bmap[i].ButtonNum);
|
{
|
||||||
|
/* Hat "button" */
|
||||||
|
sprintf(stmp, "h%i.%i",
|
||||||
|
(bmap[c][i].ButtonNum >> 8) & 0x1F, bmap[c][i].ButtonNum & 0xFF);
|
||||||
|
}
|
||||||
|
else if (bmap[c][i].ButtonNum & 0x8000)
|
||||||
|
{
|
||||||
|
/* Axis "button" */
|
||||||
|
sprintf(stmp, "%ca%i",
|
||||||
|
(bmap[c][i].ButtonNum & 0x4000) ? '-' : '+', bmap[c][i].ButtonNum & 0x3FFF);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Button */
|
||||||
|
sprintf(stmp, "b%i", bmap[c][i].ButtonNum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
output.append(buttonNames[i]);
|
||||||
|
output.append(":");
|
||||||
|
output.append(stmp);
|
||||||
|
output.append(",");
|
||||||
}
|
}
|
||||||
output.append(buttonNames[i]);
|
output.append("\n");
|
||||||
output.append(":");
|
|
||||||
output.append(stmp);
|
|
||||||
output.append(",");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (it=gpKeySeqList.begin(); it!=gpKeySeqList.end(); it++)
|
for (it=gpKeySeqList.begin(); it!=gpKeySeqList.end(); it++)
|
||||||
{
|
{
|
||||||
gamepad_function_key_t *fk = *it;
|
gamepad_function_key_t *fk = *it;
|
||||||
|
|
||||||
printf("hk[0]=%i hk[1]=%i keySeq[0]=%s keySeq[1]=%s bmap[0].buttType=%i bmap[1].buttType=%i\n",
|
//printf("hk[0]=%i hk[1]=%i keySeq[0]=%s keySeq[1]=%s bmap[0].buttType=%i bmap[1].buttType=%i\n",
|
||||||
fk->hk[0], fk->hk[1], fk->keySeq[0].name.c_str(), fk->keySeq[1].name.c_str(),
|
// fk->hk[0], fk->hk[1], fk->keySeq[0].name.c_str(), fk->keySeq[1].name.c_str(),
|
||||||
fk->bmap[0].ButtType, fk->bmap[1].ButtType );
|
// fk->bmap[0].ButtType, fk->bmap[1].ButtType );
|
||||||
|
|
||||||
if ( fk->bmap[1].ButtType >= 0 )
|
if ( fk->bmap[1].ButtType >= 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,9 +15,12 @@ struct nesGamePadMap_t
|
||||||
{
|
{
|
||||||
char guid[64];
|
char guid[64];
|
||||||
char name[128];
|
char name[128];
|
||||||
char btn[GAMEPAD_NUM_BUTTONS][32];
|
|
||||||
char os[64];
|
char os[64];
|
||||||
|
|
||||||
|
struct {
|
||||||
|
char btn[GAMEPAD_NUM_BUTTONS][32];
|
||||||
|
} conf[4];
|
||||||
|
|
||||||
nesGamePadMap_t(void);
|
nesGamePadMap_t(void);
|
||||||
~nesGamePadMap_t(void);
|
~nesGamePadMap_t(void);
|
||||||
|
|
||||||
|
@ -55,7 +58,11 @@ private:
|
||||||
class GamePad_t
|
class GamePad_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ButtConfig bmap[GAMEPAD_NUM_BUTTONS];
|
static const int NUM_CONFIG = 4;
|
||||||
|
|
||||||
|
ButtConfig bmap[NUM_CONFIG][GAMEPAD_NUM_BUTTONS];
|
||||||
|
|
||||||
|
char bmapState[GAMEPAD_NUM_BUTTONS];
|
||||||
|
|
||||||
GamePad_t(void);
|
GamePad_t(void);
|
||||||
~GamePad_t(void);
|
~GamePad_t(void);
|
||||||
|
@ -72,8 +79,8 @@ public:
|
||||||
int setMapping(nesGamePadMap_t *map);
|
int setMapping(nesGamePadMap_t *map);
|
||||||
|
|
||||||
int createProfile(const char *name);
|
int createProfile(const char *name);
|
||||||
int getMapFromFile(const char *filename, char *out);
|
int getMapFromFile(const char *filename, nesGamePadMap_t *gpm);
|
||||||
int getDefaultMap(char *out, const char *guid = NULL);
|
int getDefaultMap(const char *guid = NULL);
|
||||||
int saveMappingToFile(const char *filename, const char *txtMap);
|
int saveMappingToFile(const char *filename, const char *txtMap);
|
||||||
int saveCurrentMapToFile(const char *filename);
|
int saveCurrentMapToFile(const char *filename);
|
||||||
int deleteMapping(const char *name);
|
int deleteMapping(const char *name);
|
||||||
|
|
Loading…
Reference in New Issue