Compare commits

...

4 Commits

2 changed files with 52 additions and 4 deletions

View File

@@ -11,11 +11,13 @@ Input::Input(string file, bool verbose)
keyBindings_t kb;
kb.scancode = 0;
kb.active = false;
keyBindings.clear();
keyBindings.resize(INPUT_TOTAL, kb);
GameControllerBindings_t gcb;
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
gcb.active = false;
gameControllerBindings.clear();
gameControllerBindings.resize(INPUT_TOTAL, gcb);
this->verbose = verbose;
@@ -222,14 +224,25 @@ bool Input::discoverGameController()
if (verbose)
{
cout << "\nChecking for game controllers...\n";
cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
if (nJoysticks > 0)
{
string stNumJoysticks = nJoysticks == 1 ? "joystick" : "joysticks";
string stNumGamePads = numGamepads == 1 ? "is a gamepad" : "are gamepads";
cout << "\n** Checking game controllers" << endl;
cout << nJoysticks << " " << stNumJoysticks << " found (" << numGamepads << " " << stNumGamePads << ")\n";
}
else
{
cout << "\n>> No game controllers found\n";
}
}
if (numGamepads > 0)
{
found = true;
cout << "\n>> GAMEPAD LIST:" << endl;
for (int i = 0; i < numGamepads; i++)
{
// Abre el mando y lo añade a la lista
@@ -243,7 +256,8 @@ bool Input::discoverGameController()
// name = name + separator + to_string(i);
if (verbose)
{
cout << " -" << name << endl;
// cout << " - " << name << endl;
cout << "#" << i + 1 << ": " << name << endl;
}
controllerNames.push_back(name);
}
@@ -256,6 +270,8 @@ bool Input::discoverGameController()
}
}
cout << endl;
SDL_GameControllerEventState(SDL_ENABLE);
}
@@ -322,14 +338,21 @@ void Input::setDefaultBindings()
bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
bindKey(INPUT_EXIT, SDL_SCANCODE_ESCAPE);
bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Z);
bindKey(INPUT_BUTTON_2, SDL_SCANCODE_X);
bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
bindKey(INPUT_PAUSE, SDL_SCANCODE_H);
bindKey(INPUT_EXIT, SDL_SCANCODE_ESCAPE);
// Mando
bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_A);
bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_B);
bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_X);
@@ -338,4 +361,26 @@ void Input::setDefaultBindings()
bindGameControllerButton(INPUT_BUTTON_6, SDL_CONTROLLER_BUTTON_START);
bindGameControllerButton(INPUT_BUTTON_7, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
bindGameControllerButton(INPUT_BUTTON_8, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
bindGameControllerButton(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_A);
bindGameControllerButton(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_B);
bindGameControllerButton(INPUT_PAUSE, SDL_CONTROLLER_BUTTON_START);
bindGameControllerButton(INPUT_EXIT, SDL_CONTROLLER_BUTTON_BACK);
}
// Elimina todas las asociaciones de teclado y mando al objeto
void Input::clearBindings()
{
// Inicializa las variables
keyBindings_t kb;
kb.scancode = 0;
kb.active = false;
keyBindings.clear();
keyBindings.resize(INPUT_TOTAL, kb);
GameControllerBindings_t gcb;
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
gcb.active = false;
gameControllerBindings.clear();
gameControllerBindings.resize(INPUT_TOTAL, gcb);
}

View File

@@ -129,6 +129,9 @@ public:
// Establece unas teclas y botones del mando por defectp
void setDefaultBindings();
// Elimina todas las asociaciones de teclado y mando al objeto
void clearBindings();
};
#endif