Compare commits

...

2 Commits

3 changed files with 44 additions and 8 deletions

View File

@@ -93,10 +93,14 @@ int main(int argc, char *argv[])
Input *input = new Input(asset->get("gamecontrollerdb.txt")); Input *input = new Input(asset->get("gamecontrollerdb.txt"));
input->setVerbose(options->console); input->setVerbose(options->console);
input->discoverGameController(); input->discoverGameController();
input->bindKey(INPUT_UP, SDL_SCANCODE_UP); //input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN); //input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT); //input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); //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 = ""; string controllerName = "";
int numControllers = input->getNumControllers(); int numControllers = input->getNumControllers();
if (numControllers > 0) if (numControllers > 0)
@@ -278,7 +282,7 @@ int main(int argc, char *argv[])
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 7, "Pulsa 'N' para mostrar", 1, {240, 240, 240}, 1, {0, 0, 192}); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 7, "Pulsa 'N' para mostrar", 1, {240, 240, 240}, 1, {0, 0, 192});
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 8, "una notificacion", 1, {240, 240, 240}, 1, {0, 0, 192}); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 8, "una notificacion", 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeCentered(options->screen.nativeWidth / 2, options->screen.nativeHeight / 2, controllerName); debugText->writeCentered(options->screen.nativeWidth / 2, options->screen.nativeHeight / 2, controllerName);
debugText->writeCentered(options->screen.nativeWidth / 2, (options->screen.nativeHeight / 2) + debugText->getCharacterSize(), inputPressed); debugText->writeCentered(options->screen.nativeWidth / 2, (options->screen.nativeHeight / 2) + (debugText->getCharacterSize()*2), inputPressed);
// Vuelca el buffer en pantalla // Vuelca el buffer en pantalla
screen->blit(); screen->blit();

View File

@@ -20,6 +20,8 @@ Input::Input(string file)
verbose = true; verbose = true;
enabled = true; enabled = true;
setDefaultBindings();
} }
// Actualiza el estado del objeto // Actualiza el estado del objeto
@@ -236,11 +238,11 @@ bool Input::discoverGameController()
connectedControllers.push_back(pad); connectedControllers.push_back(pad);
const string separator(" #"); const string separator(" #");
string name = SDL_GameControllerNameForIndex(i); string name = SDL_GameControllerNameForIndex(i);
name.resize(25); // name.resize(25);
name = name + separator + to_string(i); // name = name + separator + to_string(i);
if (verbose) if (verbose)
{ {
cout << name << endl; cout << " -" << name << endl;
} }
controllerNames.push_back(name); controllerNames.push_back(name);
} }
@@ -309,4 +311,30 @@ void Input::enable()
{ {
enabled = true; enabled = true;
disabledUntil = d_notDisabled; 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);
} }

View File

@@ -35,6 +35,7 @@ using namespace std;
#define INPUT_BUTTON_18 22 #define INPUT_BUTTON_18 22
#define INPUT_BUTTON_19 23 #define INPUT_BUTTON_19 23
#define INPUT_BUTTON_20 24 #define INPUT_BUTTON_20 24
#define INPUT_PAUSE 25 #define INPUT_PAUSE 25
#define INPUT_EXIT 26 #define INPUT_EXIT 26
#define INPUT_ACCEPT 27 #define INPUT_ACCEPT 27
@@ -125,6 +126,9 @@ public:
// Hablita las entradas // Hablita las entradas
void enable(); void enable();
// Establece unas teclas y botones del mando por defectp
void setDefaultBindings();
}; };
#endif #endif