Working on support for various controllers

This commit is contained in:
2021-08-31 21:30:55 +02:00
parent 42c0f19c68
commit cf072424c6

View File

@@ -138,15 +138,21 @@ void Title::init(bool demo, Uint8 subsection)
if (!mInput->gameControllerFound()) if (!mInput->gameControllerFound())
{ {
mOptions->input[0].id = 0;
mOptions->input[0].name = "KEYBOARD";
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
mOptions->input[1].id = 0;
mOptions->input[1].name = "GAME CONTROLLER";
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
} }
checkInputDevices();
mDeviceIndex[0] = 0; checkInputDevices();
mDeviceIndex[0] = mAvailableInputDevices.size();
mDeviceIndex[1] = 0; mDeviceIndex[1] = 0;
// Inicializa el bitmap de Coffee // Inicializa el bitmap de Coffee
mCoffeeBitmap->init(mTitleTexture, mRenderer); mCoffeeBitmap->init(mTitleTexture, mRenderer);
mCoffeeBitmap->setId(0); mCoffeeBitmap->setId(0);
@@ -917,24 +923,26 @@ void Title::runDemoGame()
// Modifica las opciones para los controles de los jugadores // Modifica las opciones para los controles de los jugadores
bool Title::updatePlayerInputs(int numPlayer) bool Title::updatePlayerInputs(int numPlayer)
{ {
const int numDevices = mInput->getNumControllers(); const int numDevices = mAvailableInputDevices.size();
// Si no hay mandos se deja todo de manera prefijada // Si no hay mandos se deja todo de manera prefijada
if (numDevices == 0) if (!mInput->gameControllerFound())
{ {
mDeviceIndex[0] = 0; mDeviceIndex[0] = 0;
mDeviceIndex[1] = 0; mDeviceIndex[1] = 0;
mOptions->input[0].id = -1; mOptions->input[0].id = -1;
mOptions->input[0].name = "KEYBOARD"; mOptions->input[0].name = "KEYBOARD";
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
mOptions->input[1].id = 0; mOptions->input[1].id = 0;
mOptions->input[0].name = "GAME CONTROLLER"; mOptions->input[1].name = "GAME CONTROLLER";
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
return true; return true;
} }
else // Si hay mas de un dispositivo, se recorre el vector else // Si hay mas de un dispositivo, se recorre el vector
{ {
// Incrementa el indice // Incrementa el indice
if (mDeviceIndex[numPlayer] < numDevices - 1) if (mDeviceIndex[numPlayer] < numDevices - 1)
mDeviceIndex[numPlayer]++; mDeviceIndex[numPlayer]++;
@@ -948,7 +956,7 @@ bool Title::updatePlayerInputs(int numPlayer)
mDeviceIndex[0] = mDeviceIndex[1]; mDeviceIndex[0] = mDeviceIndex[1];
mDeviceIndex[1] = temp; mDeviceIndex[1] = temp;
} }
// Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador // Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador
mOptions->input[0] = mAvailableInputDevices[mDeviceIndex[0]]; mOptions->input[0] = mAvailableInputDevices[mDeviceIndex[0]];
mOptions->input[1] = mAvailableInputDevices[mDeviceIndex[1]]; mOptions->input[1] = mAvailableInputDevices[mDeviceIndex[1]];