From 51518f3bd855a107531fbbd779280a2d6fc485f7 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 23 May 2023 18:24:17 +0200 Subject: [PATCH] =?UTF-8?q?input:=20a=C3=B1adidas=20asignaciones=20por=20d?= =?UTF-8?q?efecto=20para=20teclado=20y=20mando?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 14 +++++++++----- units/input.cpp | 32 ++++++++++++++++++++++++++++++-- units/input.h | 4 ++++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 0c3ff70..4756b13 100644 --- a/main.cpp +++ b/main.cpp @@ -93,11 +93,15 @@ int main(int argc, char *argv[]) Input *input = new Input(asset->get("gamecontrollerdb.txt")); input->setVerbose(options->console); input->discoverGameController(); - input->bindKey(INPUT_UP, SDL_SCANCODE_UP); - input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN); - input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT); - input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); - string controllerName = "htfvhfhk"; + //input->bindKey(INPUT_UP, SDL_SCANCODE_UP); + //input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN); + //input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT); + //input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); + //input->bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP); + //input->bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN); + //input->bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT); + //input->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); + string controllerName = ""; int numControllers = input->getNumControllers(); if (numControllers > 0) { diff --git a/units/input.cpp b/units/input.cpp index d3fd456..22410ba 100644 --- a/units/input.cpp +++ b/units/input.cpp @@ -20,6 +20,8 @@ Input::Input(string file) verbose = true; enabled = true; + + setDefaultBindings(); } // Actualiza el estado del objeto @@ -236,8 +238,8 @@ bool Input::discoverGameController() connectedControllers.push_back(pad); const string separator(" #"); string name = SDL_GameControllerNameForIndex(i); - //name.resize(25); - //name = name + separator + to_string(i); + // name.resize(25); + // name = name + separator + to_string(i); if (verbose) { cout << " -" << name << endl; @@ -309,4 +311,30 @@ void Input::enable() { enabled = true; disabledUntil = d_notDisabled; +} + +// Establece unas teclas y botones del mando por defectp +void Input::setDefaultBindings() +{ + // Teclado + bindKey(INPUT_UP, SDL_SCANCODE_UP); + 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_ACCEPT, SDL_SCANCODE_RETURN); + + // 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); + bindGameControllerButton(INPUT_BUTTON_4, SDL_CONTROLLER_BUTTON_Y); + bindGameControllerButton(INPUT_BUTTON_5, SDL_CONTROLLER_BUTTON_BACK); + bindGameControllerButton(INPUT_BUTTON_6, SDL_CONTROLLER_BUTTON_START); + bindGameControllerButton(INPUT_BUTTON_7, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); + bindGameControllerButton(INPUT_BUTTON_8, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); } \ No newline at end of file diff --git a/units/input.h b/units/input.h index ad8491f..7473b18 100644 --- a/units/input.h +++ b/units/input.h @@ -35,6 +35,7 @@ using namespace std; #define INPUT_BUTTON_18 22 #define INPUT_BUTTON_19 23 #define INPUT_BUTTON_20 24 + #define INPUT_PAUSE 25 #define INPUT_EXIT 26 #define INPUT_ACCEPT 27 @@ -125,6 +126,9 @@ public: // Hablita las entradas void enable(); + + // Establece unas teclas y botones del mando por defectp + void setDefaultBindings(); }; #endif