Añadida la función checkAnyButtonPressed a la clase input
This commit is contained in:
@@ -21,6 +21,7 @@ Input::Input(std::string file)
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
|
||||||
|
gameInputs.clear();
|
||||||
gameInputs.push_back(input_fire_left);
|
gameInputs.push_back(input_fire_left);
|
||||||
gameInputs.push_back(input_fire_center);
|
gameInputs.push_back(input_fire_center);
|
||||||
gameInputs.push_back(input_fire_right);
|
gameInputs.push_back(input_fire_right);
|
||||||
@@ -28,6 +29,12 @@ Input::Input(std::string file)
|
|||||||
gameInputs.push_back(input_down);
|
gameInputs.push_back(input_down);
|
||||||
gameInputs.push_back(input_left);
|
gameInputs.push_back(input_left);
|
||||||
gameInputs.push_back(input_right);
|
gameInputs.push_back(input_right);
|
||||||
|
|
||||||
|
buttonInputs.clear();
|
||||||
|
buttonInputs.push_back(input_fire_left);
|
||||||
|
buttonInputs.push_back(input_fire_center);
|
||||||
|
buttonInputs.push_back(input_fire_right);
|
||||||
|
buttonInputs.push_back(input_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
// Actualiza el estado del objeto
|
||||||
@@ -195,6 +202,30 @@ bool Input::checkAnyInput(int device, int index)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si hay algún botón pulsado
|
||||||
|
bool Input::checkAnyButtonPressed()
|
||||||
|
{
|
||||||
|
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
|
for (auto bi : buttonInputs)
|
||||||
|
{
|
||||||
|
if (keyStates[keyBindings[bi].scancode] != 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < numGamepads; ++i)
|
||||||
|
{
|
||||||
|
if (SDL_GameControllerGetButton(connectedControllers[i], gameControllerBindings[bi].button) != 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Busca si hay un mando conectado
|
// Busca si hay un mando conectado
|
||||||
bool Input::discoverGameController()
|
bool Input::discoverGameController()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ enum inputs_e
|
|||||||
input_fire_left,
|
input_fire_left,
|
||||||
input_fire_center,
|
input_fire_center,
|
||||||
input_fire_right,
|
input_fire_right,
|
||||||
|
input_start,
|
||||||
|
|
||||||
// Inputs estandar
|
// Inputs estandar
|
||||||
input_window_fullscreen,
|
input_window_fullscreen,
|
||||||
@@ -70,6 +71,7 @@ private:
|
|||||||
std::vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
std::vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
||||||
std::vector<inputs_e> gameInputs; // Inputs usados para jugar, normalmente direcciones y botones
|
std::vector<inputs_e> gameInputs; // Inputs usados para jugar, normalmente direcciones y botones
|
||||||
|
std::vector<inputs_e> buttonInputs; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
||||||
int numGamepads; // Numero de mandos conectados
|
int numGamepads; // Numero de mandos conectados
|
||||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
||||||
bool verbose; // Indica si ha de mostrar mensajes
|
bool verbose; // Indica si ha de mostrar mensajes
|
||||||
@@ -95,6 +97,9 @@ public:
|
|||||||
// Comprueba si hay almenos un input activo
|
// Comprueba si hay almenos un input activo
|
||||||
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);
|
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);
|
||||||
|
|
||||||
|
// Comprueba si hay algún botón pulsado
|
||||||
|
bool checkAnyButtonPressed();
|
||||||
|
|
||||||
// Busca si hay un mando conectado
|
// Busca si hay un mando conectado
|
||||||
bool discoverGameController();
|
bool discoverGameController();
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ void Director::initInput()
|
|||||||
input->bindKey(input_fire_left, SDL_SCANCODE_Q);
|
input->bindKey(input_fire_left, SDL_SCANCODE_Q);
|
||||||
input->bindKey(input_fire_center, SDL_SCANCODE_W);
|
input->bindKey(input_fire_center, SDL_SCANCODE_W);
|
||||||
input->bindKey(input_fire_right, SDL_SCANCODE_E);
|
input->bindKey(input_fire_right, SDL_SCANCODE_E);
|
||||||
|
input->bindKey(input_start, SDL_SCANCODE_RETURN);
|
||||||
|
|
||||||
// Teclado - Otros
|
// Teclado - Otros
|
||||||
input->bindKey(input_accept, SDL_SCANCODE_RETURN);
|
input->bindKey(input_accept, SDL_SCANCODE_RETURN);
|
||||||
@@ -130,6 +131,7 @@ void Director::initInput()
|
|||||||
input->bindGameControllerButton(input_fire_left, SDL_CONTROLLER_BUTTON_X);
|
input->bindGameControllerButton(input_fire_left, SDL_CONTROLLER_BUTTON_X);
|
||||||
input->bindGameControllerButton(input_fire_center, SDL_CONTROLLER_BUTTON_Y);
|
input->bindGameControllerButton(input_fire_center, SDL_CONTROLLER_BUTTON_Y);
|
||||||
input->bindGameControllerButton(input_fire_right, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
input->bindGameControllerButton(input_fire_right, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
||||||
|
input->bindGameControllerButton(input_start, SDL_CONTROLLER_BUTTON_START);
|
||||||
|
|
||||||
// Mando - Otros
|
// Mando - Otros
|
||||||
input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_START);
|
input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_START);
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ void HiScoreTable::checkInput()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
else if (input->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ void Instructions::checkInput()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
else if (input->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ void Intro::checkInput()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
else if (input->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ void Logo::checkInput()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkAnyInput())
|
else if (input->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
|
|||||||
Reference in New Issue
Block a user