Ya se pueden definir los botones para cada jugador. Falta guardarlos en el fichero de configuración
This commit is contained in:
@@ -40,10 +40,15 @@ DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, p
|
||||
button.button = SDL_CONTROLLER_BUTTON_START;
|
||||
buttons.push_back(button);
|
||||
|
||||
button.label = "QUIT";
|
||||
button.label = "SALIR DEL JUEGO";
|
||||
button.input = input_exit;
|
||||
button.button = SDL_CONTROLLER_BUTTON_BACK;
|
||||
buttons.push_back(button);
|
||||
|
||||
for (int i = 0; i < input->getNumControllers(); ++i)
|
||||
{
|
||||
controllerNames.push_back(input->getControllerName(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -64,16 +69,21 @@ void DefineButtons::render()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
text->writeCentered(x, y - 10, "PLAYER " + std::to_string(indexController + 1));
|
||||
text->writeCentered(x, y - 20, "PLAYER " + std::to_string(indexController + 1));
|
||||
text->writeCentered(x, y - 10, controllerNames[indexController]);
|
||||
text->writeCentered(x, y, buttons[indexButton].label);
|
||||
}
|
||||
}
|
||||
|
||||
int getJoyIndex(int id);
|
||||
|
||||
void DefineButtons::doJoystickButtonDown(SDL_JoyButtonEvent *event)
|
||||
{
|
||||
//int i = getJoyIndex(event->which);
|
||||
int i = input->getJoyIndex(event->which);
|
||||
|
||||
// Solo pillamos botones del mando que toca
|
||||
if (i != indexController)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buttons[indexButton].button = (SDL_GameControllerButton)event->button;
|
||||
incIndexButton();
|
||||
@@ -91,57 +101,6 @@ void DefineButtons::checkInput()
|
||||
{
|
||||
if (event.type == SDL_JOYBUTTONDOWN)
|
||||
doJoystickButtonDown(&event.jbutton);
|
||||
|
||||
/*if (eventHandler->type == SDL_JOYBUTTONDOWN)
|
||||
{
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_A)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_A;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_B)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_B;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_X)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_X;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_Y)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_Y;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_BACK)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_BACK;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_START)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_START;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
|
||||
incIndexButton();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user