Añadida la función checkAnyButtonPressed a la clase input

This commit is contained in:
2024-07-05 14:25:24 +02:00
parent 62f3c42e7b
commit c3c33135a7
7 changed files with 43 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ Input::Input(std::string file)
verbose = true;
enabled = true;
gameInputs.clear();
gameInputs.push_back(input_fire_left);
gameInputs.push_back(input_fire_center);
gameInputs.push_back(input_fire_right);
@@ -28,6 +29,12 @@ Input::Input(std::string file)
gameInputs.push_back(input_down);
gameInputs.push_back(input_left);
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
@@ -195,6 +202,30 @@ bool Input::checkAnyInput(int device, int index)
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
bool Input::discoverGameController()
{
@@ -244,7 +275,7 @@ bool Input::discoverGameController()
connectedControllers.push_back(pad);
const std::string separator(" #");
std::string name = SDL_GameControllerNameForIndex(i);
//name.resize(25);
// name.resize(25);
name = name + separator + std::to_string(i);
if (verbose)
{

View File

@@ -24,6 +24,7 @@ enum inputs_e
input_fire_left,
input_fire_center,
input_fire_right,
input_start,
// Inputs estandar
input_window_fullscreen,
@@ -70,6 +71,7 @@ private:
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<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
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
bool verbose; // Indica si ha de mostrar mensajes
@@ -95,6 +97,9 @@ public:
// Comprueba si hay almenos un input activo
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
bool discoverGameController();