Added logic to show state of mapped buttons on game pad config page.
This commit is contained in:
parent
e50d6e22ed
commit
b815fbfe47
|
@ -78,6 +78,8 @@ consoleWin_t::~consoleWin_t(void)
|
|||
{
|
||||
nes_shm->runEmulator = 0;
|
||||
|
||||
gameTimer->stop();
|
||||
|
||||
if ( gamePadConfWin != NULL )
|
||||
{
|
||||
gamePadConfWin->closeWindow();
|
||||
|
|
|
@ -28,6 +28,10 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
|||
portNum = 0;
|
||||
buttonConfigStatus = 1;
|
||||
|
||||
inputTimer = new QTimer( this );
|
||||
|
||||
connect( inputTimer, &QTimer::timeout, this, &GamePadConfDialog_t::updatePeriodic );
|
||||
|
||||
setWindowTitle( tr("GamePad Config") );
|
||||
|
||||
hbox1 = new QHBoxLayout();
|
||||
|
@ -35,7 +39,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
|||
hbox3 = new QHBoxLayout();
|
||||
hbox4 = new QHBoxLayout();
|
||||
|
||||
label = new QLabel(tr("Port:"));
|
||||
label = new QLabel(tr("Console Port:"));
|
||||
portSel = new QComboBox();
|
||||
hbox1->addWidget( label );
|
||||
hbox1->addWidget( portSel );
|
||||
|
@ -105,13 +109,17 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
|||
|
||||
buttonName = new QLabel(tr(text));
|
||||
keyName[i] = new QLabel();
|
||||
keyState[i] = new QLabel( tr("F") );
|
||||
label = new QLabel( tr("State:") );
|
||||
button[i] = new GamePadConfigButton_t(i);
|
||||
clearButton[i] = new QPushButton( tr("Clear") );
|
||||
|
||||
grid->addWidget( buttonName , i, 0, Qt::AlignCenter );
|
||||
grid->addWidget( keyName[i] , i, 1, Qt::AlignCenter );
|
||||
grid->addWidget( button[i] , i, 2, Qt::AlignCenter );
|
||||
grid->addWidget( clearButton[i], i, 3, Qt::AlignCenter );
|
||||
grid->addWidget( label , i, 2, Qt::AlignCenter );
|
||||
grid->addWidget( keyState[i] , i, 3, Qt::AlignCenter );
|
||||
grid->addWidget( button[i] , i, 4, Qt::AlignCenter );
|
||||
grid->addWidget( clearButton[i], i, 5, Qt::AlignCenter );
|
||||
}
|
||||
updateCntrlrDpy();
|
||||
|
||||
|
@ -166,11 +174,13 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
|
|||
|
||||
setLayout( mainLayout );
|
||||
|
||||
inputTimer->start( 33 ); // 30hz
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
GamePadConfDialog_t::~GamePadConfDialog_t(void)
|
||||
{
|
||||
inputTimer->stop();
|
||||
buttonConfigStatus = 0;
|
||||
}
|
||||
void GamePadConfDialog_t::keyPressEvent(QKeyEvent *event)
|
||||
|
@ -485,6 +495,26 @@ void GamePadConfDialog_t::loadDefaults(void)
|
|||
updateCntrlrDpy();
|
||||
}
|
||||
//----------------------------------------------------
|
||||
void GamePadConfDialog_t::updatePeriodic(void)
|
||||
{
|
||||
for (int i=0; i<GAMEPAD_NUM_BUTTONS; i++)
|
||||
{
|
||||
const char *txt, *style;
|
||||
if ( GamePad[portNum].bmap[i].state )
|
||||
{
|
||||
txt = " T ";
|
||||
style = "background-color: green; color: white;";
|
||||
}
|
||||
else
|
||||
{
|
||||
txt = " F ";
|
||||
style = "background-color: red; color: white;";
|
||||
}
|
||||
keyState[i]->setText( tr(txt) );
|
||||
keyState[i]->setStyleSheet( style );
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------
|
||||
GamePadConfigButton_t::GamePadConfigButton_t(int i)
|
||||
{
|
||||
idx = i;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QFrame>
|
||||
#include <QTimer>
|
||||
#include <QGroupBox>
|
||||
|
||||
#include "Qt/main.h"
|
||||
|
@ -37,11 +38,13 @@ class GamePadConfDialog_t : public QDialog
|
|||
~GamePadConfDialog_t(void);
|
||||
|
||||
protected:
|
||||
QTimer *inputTimer;
|
||||
QComboBox *portSel;
|
||||
QComboBox *devSel;
|
||||
QComboBox *profSel;
|
||||
QLabel *guidLbl;
|
||||
QLabel *keyName[GAMEPAD_NUM_BUTTONS];
|
||||
QLabel *keyState[GAMEPAD_NUM_BUTTONS];
|
||||
GamePadConfigButton_t *button[GAMEPAD_NUM_BUTTONS];
|
||||
|
||||
int portNum;
|
||||
|
@ -84,5 +87,6 @@ class GamePadConfDialog_t : public QDialog
|
|||
void oppDirEna(int state);
|
||||
void portSelect(int index);
|
||||
void deviceSelect(int index);
|
||||
void updatePeriodic(void);
|
||||
|
||||
};
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
#include "Qt/config.h"
|
||||
|
||||
|
||||
#include "Qt/sdl-video.h"
|
||||
#include "Qt/sdl.h"
|
||||
#include "Qt/sdl-video.h"
|
||||
#include "Qt/sdl-joystick.h"
|
||||
|
||||
#include "common/cheat.h"
|
||||
#include "../../movie.h"
|
||||
|
@ -49,8 +50,8 @@ extern bool bindSavestate, frameAdvanceLagSkip, lagCounterDisplay;
|
|||
/* UsrInputType[] is user-specified. CurInputType[] is current
|
||||
(game loading can override user settings)
|
||||
*/
|
||||
static int UsrInputType[NUM_INPUT_DEVICES];
|
||||
static int CurInputType[NUM_INPUT_DEVICES];
|
||||
static int UsrInputType[NUM_INPUT_DEVICES] = { SI_GAMEPAD, SI_GAMEPAD, SI_NONE };
|
||||
static int CurInputType[NUM_INPUT_DEVICES] = { SI_GAMEPAD, SI_GAMEPAD, SI_NONE };
|
||||
static int cspec = 0;
|
||||
static int buttonConfigInProgress = 0;
|
||||
|
||||
|
@ -1007,8 +1008,13 @@ DTestButton (ButtConfig * bc)
|
|||
{
|
||||
if (g_keyState[SDL_GetScancodeFromKey (bc->ButtonNum)])
|
||||
{
|
||||
bc->state = 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bc->state = 0;
|
||||
}
|
||||
}
|
||||
else if (bc->ButtType == BUTTC_JOYSTICK)
|
||||
{
|
||||
|
@ -1021,26 +1027,26 @@ DTestButton (ButtConfig * bc)
|
|||
}
|
||||
|
||||
|
||||
#define MK(x) {BUTTC_KEYBOARD,0,MKK(x)}
|
||||
#define MK(x) {BUTTC_KEYBOARD,0,MKK(x),0}
|
||||
//#define MK2(x1,x2) {BUTTC_KEYBOARD,0,MKK(x1)}
|
||||
#define MKZ() {0,0,-1}
|
||||
#define MKZ() {0,0,-1,0}
|
||||
#define GPZ() {MKZ(), MKZ(), MKZ(), MKZ()}
|
||||
|
||||
ButtConfig GamePadConfig[ GAMEPAD_NUM_DEVICES ][ GAMEPAD_NUM_BUTTONS ] =
|
||||
{
|
||||
/* Gamepad 1 */
|
||||
{MK (KP_3), MK (KP_2), MK (SLASH), MK (ENTER),
|
||||
MK (w), MK (z), MK (a), MK (s), MKZ (), MKZ ()},
|
||||
|
||||
/* Gamepad 2 */
|
||||
GPZ (),
|
||||
|
||||
/* Gamepad 3 */
|
||||
GPZ (),
|
||||
|
||||
/* Gamepad 4 */
|
||||
GPZ ()
|
||||
};
|
||||
//ButtConfig GamePadConfig[ GAMEPAD_NUM_DEVICES ][ GAMEPAD_NUM_BUTTONS ] =
|
||||
//{
|
||||
///* Gamepad 1 */
|
||||
// {MK (KP_3), MK (KP_2), MK (SLASH), MK (ENTER),
|
||||
// MK (w), MK (z), MK (a), MK (s), MKZ (), MKZ ()},
|
||||
//
|
||||
// /* Gamepad 2 */
|
||||
// GPZ (),
|
||||
//
|
||||
// /* Gamepad 3 */
|
||||
// GPZ (),
|
||||
//
|
||||
// /* Gamepad 4 */
|
||||
// GPZ ()
|
||||
//};
|
||||
|
||||
/**
|
||||
* Update the status of the gamepad input devices.
|
||||
|
@ -1072,7 +1078,7 @@ UpdateGamepad(void)
|
|||
// a, b, select, start, up, down, left, right
|
||||
for (x = 0; x < 8; x++)
|
||||
{
|
||||
if (DTestButton (&GamePadConfig[wg][x]))
|
||||
if (DTestButton (&GamePad[wg].bmap[x]))
|
||||
{
|
||||
//printf("GamePad%i Button Hit: %i \n", wg, x );
|
||||
if(opposite_dirs == 0)
|
||||
|
@ -1110,7 +1116,7 @@ UpdateGamepad(void)
|
|||
{
|
||||
for (x = 0; x < 2; x++)
|
||||
{
|
||||
if (DTestButton (&GamePadConfig[wg][8 + x]))
|
||||
if (DTestButton (&GamePad[wg].bmap[8 + x]))
|
||||
{
|
||||
JS |= (1 << x) << (wg << 3);
|
||||
}
|
||||
|
@ -2063,15 +2069,16 @@ UpdateInput (Config * config)
|
|||
type = 0;
|
||||
}
|
||||
|
||||
config->getOption (prefix + "DeviceNum", &devnum);
|
||||
for (unsigned int j = 0; j < GAMEPAD_NUM_BUTTONS; j++)
|
||||
{
|
||||
config->getOption (prefix + GamePadNames[j], &button);
|
||||
//FIXME
|
||||
//config->getOption (prefix + "DeviceNum", &devnum);
|
||||
//for (unsigned int j = 0; j < GAMEPAD_NUM_BUTTONS; j++)
|
||||
//{
|
||||
// config->getOption (prefix + GamePadNames[j], &button);
|
||||
|
||||
GamePadConfig[i][j].ButtType = type;
|
||||
GamePadConfig[i][j].DeviceNum = devnum;
|
||||
GamePadConfig[i][j].ButtonNum = button;
|
||||
}
|
||||
// GamePadConfig[i][j].ButtType = type;
|
||||
// GamePadConfig[i][j].DeviceNum = devnum;
|
||||
// GamePadConfig[i][j].ButtonNum = button;
|
||||
//}
|
||||
}
|
||||
|
||||
// PowerPad 0 - 1
|
||||
|
|
|
@ -17,6 +17,7 @@ struct ButtConfig
|
|||
int ButtType; //[MAXBUTTCONFIG];
|
||||
int DeviceNum; //[MAXBUTTCONFIG];
|
||||
int ButtonNum; //[MAXBUTTCONFIG];
|
||||
int state;
|
||||
//uint32_t NumC;
|
||||
//uint64 DeviceID[MAXBUTTCONFIG]; /* TODO */
|
||||
};
|
||||
|
|
|
@ -337,10 +337,17 @@ DTestButtonJoy(ButtConfig *bc)
|
|||
if (bc->ButtonNum & 0x2000)
|
||||
{
|
||||
/* Hat "button" */
|
||||
if(SDL_JoystickGetHat( js,
|
||||
if (SDL_JoystickGetHat( js,
|
||||
((bc->ButtonNum >> 8) & 0x1F)) &
|
||||
(bc->ButtonNum&0xFF))
|
||||
{
|
||||
bc->state = 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bc->state = 0;
|
||||
}
|
||||
}
|
||||
else if (bc->ButtonNum & 0x8000)
|
||||
{
|
||||
|
@ -348,16 +355,30 @@ DTestButtonJoy(ButtConfig *bc)
|
|||
int pos;
|
||||
pos = SDL_JoystickGetAxis( js,
|
||||
bc->ButtonNum & 16383);
|
||||
if ((bc->ButtonNum & 0x4000) && pos <= -16383) {
|
||||
return 1;
|
||||
} else if (!(bc->ButtonNum & 0x4000) && pos >= 16363) {
|
||||
if ((bc->ButtonNum & 0x4000) && pos <= -16383)
|
||||
{
|
||||
bc->state = 1;
|
||||
return 1;
|
||||
}
|
||||
else if (!(bc->ButtonNum & 0x4000) && pos >= 16363)
|
||||
{
|
||||
bc->state = 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bc->state = 0;
|
||||
}
|
||||
}
|
||||
else if(SDL_JoystickGetButton( js,
|
||||
else if (SDL_JoystickGetButton( js,
|
||||
bc->ButtonNum))
|
||||
{
|
||||
bc->state = 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bc->state = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -11,6 +11,14 @@
|
|||
|
||||
#define MAX_JOYSTICKS 32
|
||||
|
||||
struct nesGamePadMap_t
|
||||
{
|
||||
char guid[64];
|
||||
char name[128];
|
||||
char btn[GAMEPAD_NUM_BUTTONS];
|
||||
char os[64];
|
||||
};
|
||||
|
||||
struct jsDev_t
|
||||
{
|
||||
SDL_Joystick *js;
|
||||
|
|
Loading…
Reference in New Issue