Variables renombrades en input.cpp
This commit is contained in:
@@ -24,27 +24,27 @@ DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
DefineButtonsButton button;
|
||||
|
||||
button.label = lang::getText(95);
|
||||
button.input = input_fire_left;
|
||||
button.input = InputType::FIRE_LEFT;
|
||||
button.button = SDL_CONTROLLER_BUTTON_X;
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(96);
|
||||
button.input = input_fire_center;
|
||||
button.input = InputType::FIRE_CENTER;
|
||||
button.button = SDL_CONTROLLER_BUTTON_Y;
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(97);
|
||||
button.input = input_fire_right;
|
||||
button.input = InputType::FIRE_RIGHT;
|
||||
button.button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(98);
|
||||
button.input = input_start;
|
||||
button.input = InputType::START;
|
||||
button.button = SDL_CONTROLLER_BUTTON_START;
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(99);
|
||||
button.input = input_exit;
|
||||
button.input = InputType::EXIT;
|
||||
button.button = SDL_CONTROLLER_BUTTON_BACK;
|
||||
buttons_.push_back(button);
|
||||
|
||||
@@ -155,7 +155,7 @@ void DefineButtons::incIndexButton()
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
input_->allActive(index_controller_);
|
||||
//input_->allActive(index_controller_);
|
||||
|
||||
// Reinicia variables
|
||||
index_button_ = 0;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
struct DefineButtonsButton
|
||||
{
|
||||
std::string label; // Texto en pantalla para el botón
|
||||
inputs_e input; // Input asociado
|
||||
InputType input; // Input asociado
|
||||
SDL_GameControllerButton button; // Botón del mando correspondiente
|
||||
};
|
||||
|
||||
|
||||
@@ -132,65 +132,59 @@ Director::~Director()
|
||||
/// Inicializa el objeto input
|
||||
void Director::initInput()
|
||||
{
|
||||
// Establece si ha de mostrar mensajes
|
||||
#ifdef VERBOSE
|
||||
Input::get()->setVerbose(true);
|
||||
#else
|
||||
Input::get()->setVerbose(false);
|
||||
#endif
|
||||
// Busca si hay mandos conectados
|
||||
Input::get()->discoverGameControllers();
|
||||
|
||||
// Teclado - Movimiento del jugador
|
||||
Input::get()->bindKey(input_up, SDL_SCANCODE_UP);
|
||||
Input::get()->bindKey(input_down, SDL_SCANCODE_DOWN);
|
||||
Input::get()->bindKey(input_left, SDL_SCANCODE_LEFT);
|
||||
Input::get()->bindKey(input_right, SDL_SCANCODE_RIGHT);
|
||||
Input::get()->bindKey(InputType::UP, SDL_SCANCODE_UP);
|
||||
Input::get()->bindKey(InputType::DOWN, SDL_SCANCODE_DOWN);
|
||||
Input::get()->bindKey(InputType::LEFT, SDL_SCANCODE_LEFT);
|
||||
Input::get()->bindKey(InputType::RIGHT, SDL_SCANCODE_RIGHT);
|
||||
|
||||
Input::get()->bindKey(input_fire_left, SDL_SCANCODE_Q);
|
||||
Input::get()->bindKey(input_fire_center, SDL_SCANCODE_W);
|
||||
Input::get()->bindKey(input_fire_right, SDL_SCANCODE_E);
|
||||
Input::get()->bindKey(InputType::FIRE_LEFT, SDL_SCANCODE_Q);
|
||||
Input::get()->bindKey(InputType::FIRE_CENTER, SDL_SCANCODE_W);
|
||||
Input::get()->bindKey(InputType::FIRE_RIGHT, SDL_SCANCODE_E);
|
||||
|
||||
Input::get()->bindKey(input_start, SDL_SCANCODE_RETURN);
|
||||
Input::get()->bindKey(InputType::START, SDL_SCANCODE_RETURN);
|
||||
|
||||
// Teclado - Control del programa
|
||||
Input::get()->bindKey(input_service, SDL_SCANCODE_0);
|
||||
Input::get()->bindKey(input_exit, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(input_pause, SDL_SCANCODE_P);
|
||||
Input::get()->bindKey(input_window_dec_size, SDL_SCANCODE_F1);
|
||||
Input::get()->bindKey(input_window_inc_size, SDL_SCANCODE_F2);
|
||||
Input::get()->bindKey(input_window_fullscreen, SDL_SCANCODE_F3);
|
||||
Input::get()->bindKey(input_video_shaders, SDL_SCANCODE_F4);
|
||||
Input::get()->bindKey(input_mute, SDL_SCANCODE_F5);
|
||||
Input::get()->bindKey(input_showinfo, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(input_reset, SDL_SCANCODE_F10);
|
||||
Input::get()->bindKey(InputType::SERVICE, SDL_SCANCODE_0);
|
||||
Input::get()->bindKey(InputType::EXIT, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(InputType::PAUSE, SDL_SCANCODE_P);
|
||||
Input::get()->bindKey(InputType::WINDOW_DEC_SIZE, SDL_SCANCODE_F1);
|
||||
Input::get()->bindKey(InputType::WINDOW_INC_SIZE, SDL_SCANCODE_F2);
|
||||
Input::get()->bindKey(InputType::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
|
||||
Input::get()->bindKey(InputType::VIDEO_SHADERS, SDL_SCANCODE_F4);
|
||||
Input::get()->bindKey(InputType::MUTE, SDL_SCANCODE_F5);
|
||||
Input::get()->bindKey(InputType::SHOWINFO, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(InputType::RESET, SDL_SCANCODE_F10);
|
||||
|
||||
// Asigna botones a inputs
|
||||
const int numGamePads = Input::get()->getNumControllers();
|
||||
for (int i = 0; i < numGamePads; ++i)
|
||||
{
|
||||
// Mando - Movimiento del jugador
|
||||
Input::get()->bindGameControllerButton(i, input_up, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||
Input::get()->bindGameControllerButton(i, input_down, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||
Input::get()->bindGameControllerButton(i, input_left, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||||
Input::get()->bindGameControllerButton(i, input_right, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||
Input::get()->bindGameControllerButton(i, InputType::DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||
Input::get()->bindGameControllerButton(i, InputType::LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||
|
||||
Input::get()->bindGameControllerButton(i, input_fire_left, SDL_CONTROLLER_BUTTON_X);
|
||||
Input::get()->bindGameControllerButton(i, input_fire_center, SDL_CONTROLLER_BUTTON_Y);
|
||||
Input::get()->bindGameControllerButton(i, input_fire_right, SDL_CONTROLLER_BUTTON_B);
|
||||
Input::get()->bindGameControllerButton(i, InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_X);
|
||||
Input::get()->bindGameControllerButton(i, InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_Y);
|
||||
Input::get()->bindGameControllerButton(i, InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_B);
|
||||
|
||||
Input::get()->bindGameControllerButton(i, input_start, SDL_CONTROLLER_BUTTON_START);
|
||||
Input::get()->bindGameControllerButton(i, InputType::START, SDL_CONTROLLER_BUTTON_START);
|
||||
|
||||
// Mando - Control del programa
|
||||
Input::get()->bindGameControllerButton(i, input_service, SDL_CONTROLLER_BUTTON_BACK);
|
||||
Input::get()->bindGameControllerButton(i, input_exit, input_start);
|
||||
Input::get()->bindGameControllerButton(i, input_pause, input_fire_right);
|
||||
Input::get()->bindGameControllerButton(i, input_video_shaders, input_fire_left);
|
||||
Input::get()->bindGameControllerButton(i, input_mute, input_left);
|
||||
Input::get()->bindGameControllerButton(i, input_showinfo, input_right);
|
||||
Input::get()->bindGameControllerButton(i, input_reset, input_fire_center);
|
||||
Input::get()->bindGameControllerButton(i, input_config, input_down);
|
||||
Input::get()->bindGameControllerButton(i, input_swap_controllers, input_up);
|
||||
Input::get()->bindGameControllerButton(i, InputType::SERVICE, SDL_CONTROLLER_BUTTON_BACK);
|
||||
Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START);
|
||||
Input::get()->bindGameControllerButton(i, InputType::PAUSE, InputType::FIRE_RIGHT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::VIDEO_SHADERS, InputType::FIRE_LEFT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::MUTE, InputType::LEFT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::SHOWINFO, InputType::RIGHT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER);
|
||||
Input::get()->bindGameControllerButton(i, InputType::CONFIG, InputType::DOWN);
|
||||
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
||||
}
|
||||
|
||||
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
||||
@@ -208,14 +202,14 @@ void Director::initInput()
|
||||
// Asigna botones a inputs desde otros inputs
|
||||
for (int i = 0; i < numGamePads; ++i)
|
||||
{
|
||||
Input::get()->bindGameControllerButton(i, input_exit, input_start);
|
||||
Input::get()->bindGameControllerButton(i, input_reset, input_fire_center);
|
||||
Input::get()->bindGameControllerButton(i, input_pause, input_fire_right);
|
||||
Input::get()->bindGameControllerButton(i, input_video_shaders, input_fire_left);
|
||||
Input::get()->bindGameControllerButton(i, input_mute, input_left);
|
||||
Input::get()->bindGameControllerButton(i, input_showinfo, input_right);
|
||||
Input::get()->bindGameControllerButton(i, input_config, input_down);
|
||||
Input::get()->bindGameControllerButton(i, input_swap_controllers, input_up);
|
||||
Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START);
|
||||
Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER);
|
||||
Input::get()->bindGameControllerButton(i, InputType::PAUSE, InputType::FIRE_RIGHT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::VIDEO_SHADERS, InputType::FIRE_LEFT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::MUTE, InputType::LEFT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::SHOWINFO, InputType::RIGHT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::CONFIG, InputType::DOWN);
|
||||
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
||||
}
|
||||
|
||||
// Guarda las asignaciones de botones en las opciones
|
||||
|
||||
@@ -1972,7 +1972,7 @@ void Game::checkInput()
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
// Comprueba si se va a pausar el juego
|
||||
if (input_->checkModInput(input_service, input_pause, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (input_->checkModInput(InputType::SERVICE, InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
pause(!paused_);
|
||||
return;
|
||||
@@ -1990,17 +1990,17 @@ void Game::checkInput()
|
||||
// Comprueba direcciones
|
||||
if (demo_.data_file[i][demo_.counter].left == 1)
|
||||
{
|
||||
player->setInput(input_left);
|
||||
player->setInput(InputType::LEFT);
|
||||
}
|
||||
|
||||
else if (demo_.data_file[i][demo_.counter].right == 1)
|
||||
{
|
||||
player->setInput(input_right);
|
||||
player->setInput(InputType::RIGHT);
|
||||
}
|
||||
|
||||
else if (demo_.data_file[i][demo_.counter].no_input == 1)
|
||||
{
|
||||
player->setInput(input_null);
|
||||
player->setInput(InputType::NONE);
|
||||
}
|
||||
|
||||
// Comprueba botones
|
||||
@@ -2008,7 +2008,7 @@ void Game::checkInput()
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
player->setInput(input_fire_center);
|
||||
player->setInput(InputType::FIRE_CENTER);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BulletType::UP, player->isPowerUp(), player->getId());
|
||||
player->setFireCooldown(10);
|
||||
}
|
||||
@@ -2018,7 +2018,7 @@ void Game::checkInput()
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
player->setInput(input_fire_left);
|
||||
player->setInput(InputType::FIRE_LEFT);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BulletType::LEFT, player->isPowerUp(), player->getId());
|
||||
player->setFireCooldown(10);
|
||||
}
|
||||
@@ -2028,7 +2028,7 @@ void Game::checkInput()
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
player->setInput(input_fire_right);
|
||||
player->setInput(InputType::FIRE_RIGHT);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BulletType::RIGHT, player->isPowerUp(), player->getId());
|
||||
player->setFireCooldown(10);
|
||||
}
|
||||
@@ -2064,9 +2064,9 @@ void Game::checkInput()
|
||||
if (player->isPlaying())
|
||||
{
|
||||
// Input a la izquierda
|
||||
if (input_->checkInput(input_left, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::LEFT, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_left);
|
||||
player->setInput(InputType::LEFT);
|
||||
#ifdef RECORDING
|
||||
demo.keys.left = 1;
|
||||
#endif
|
||||
@@ -2074,9 +2074,9 @@ void Game::checkInput()
|
||||
else
|
||||
{
|
||||
// Input a la derecha
|
||||
if (input_->checkInput(input_right, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::RIGHT, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_right);
|
||||
player->setInput(InputType::RIGHT);
|
||||
#ifdef RECORDING
|
||||
demo.keys.right = 1;
|
||||
#endif
|
||||
@@ -2084,18 +2084,18 @@ void Game::checkInput()
|
||||
else
|
||||
{
|
||||
// Ninguno de los dos inputs anteriores
|
||||
player->setInput(input_null);
|
||||
player->setInput(InputType::NONE);
|
||||
#ifdef RECORDING
|
||||
demo.keys.no_input = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// Comprueba el input de disparar al centro
|
||||
if (input_->checkInput(input_fire_center, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::FIRE_CENTER, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
player->setInput(input_fire_center);
|
||||
player->setInput(InputType::FIRE_CENTER);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BulletType::UP, player->isPowerUp(), player->getId());
|
||||
player->setFireCooldown(10);
|
||||
|
||||
@@ -2108,11 +2108,11 @@ void Game::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el input de disparar a la izquierda
|
||||
else if (input_->checkInput(input_fire_left, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
player->setInput(input_fire_left);
|
||||
player->setInput(InputType::FIRE_LEFT);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BulletType::LEFT, player->isPowerUp(), player->getId());
|
||||
player->setFireCooldown(10);
|
||||
|
||||
@@ -2125,11 +2125,11 @@ void Game::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el input de disparar a la derecha
|
||||
else if (input_->checkInput(input_fire_right, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
player->setInput(input_fire_right);
|
||||
player->setInput(InputType::FIRE_RIGHT);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BulletType::RIGHT, player->isPowerUp(), player->getId());
|
||||
player->setFireCooldown(10);
|
||||
|
||||
@@ -2153,15 +2153,15 @@ void Game::checkInput()
|
||||
else if (player->isContinue() || player->isWaiting())
|
||||
{
|
||||
// Si no está jugando, el botón de start le permite continuar jugando
|
||||
if (input_->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setStatusPlaying(PlayerStatus::PLAYING);
|
||||
}
|
||||
|
||||
// Si está continuando, los botones de fuego hacen decrementar el contador
|
||||
const auto fire1 = input_->checkInput(input_fire_left, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire2 = input_->checkInput(input_fire_center, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire3 = input_->checkInput(input_fire_right, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire1 = input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire2 = input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire3 = input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
if (fire1 || fire2 || fire3)
|
||||
{
|
||||
player->decContinueCounter();
|
||||
@@ -2169,41 +2169,41 @@ void Game::checkInput()
|
||||
}
|
||||
else if (player->isEnteringName())
|
||||
{
|
||||
const auto fire1 = input_->checkInput(input_fire_left, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire2 = input_->checkInput(input_fire_center, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire3 = input_->checkInput(input_fire_right, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire1 = input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire2 = input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
const auto fire3 = input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index);
|
||||
if (fire1 || fire2 || fire3)
|
||||
{
|
||||
if (player->getRecordNamePos() == 7)
|
||||
{
|
||||
player->setInput(input_start);
|
||||
player->setInput(InputType::START);
|
||||
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
||||
player->setStatusPlaying(PlayerStatus::CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
player->setInput(input_right);
|
||||
player->setInput(InputType::RIGHT);
|
||||
}
|
||||
}
|
||||
else if (input_->checkInput(input_up, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_up);
|
||||
player->setInput(InputType::UP);
|
||||
}
|
||||
else if (input_->checkInput(input_down, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_down);
|
||||
player->setInput(InputType::DOWN);
|
||||
}
|
||||
else if (input_->checkInput(input_left, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_left);
|
||||
player->setInput(InputType::LEFT);
|
||||
}
|
||||
else if (input_->checkInput(input_right, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_right);
|
||||
player->setInput(InputType::RIGHT);
|
||||
}
|
||||
else if (input_->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
else if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_start);
|
||||
player->setInput(InputType::START);
|
||||
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
||||
player->setStatusPlaying(PlayerStatus::CONTINUE);
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
namespace globalInputs
|
||||
{
|
||||
// Variables
|
||||
std::vector<int> servicePressedCounter;
|
||||
std::vector<int> service_pressed_counter;
|
||||
|
||||
// Inicializa variables
|
||||
void init()
|
||||
{
|
||||
const auto numInputs = Input::get()->getNumControllers() + 1;
|
||||
servicePressedCounter.reserve(numInputs);
|
||||
for (int i = 0; i < numInputs; ++i)
|
||||
const auto num_inputs = Input::get()->getNumControllers() + 1;
|
||||
service_pressed_counter.reserve(num_inputs);
|
||||
for (int i = 0; i < num_inputs; ++i)
|
||||
{
|
||||
servicePressedCounter.push_back(0);
|
||||
service_pressed_counter.push_back(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,78 +59,78 @@ namespace globalInputs
|
||||
void check()
|
||||
{
|
||||
// Comprueba si se sale con el teclado
|
||||
if (Input::get()->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
quit(section::Options::QUIT_NORMAL);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si se va a resetear el juego
|
||||
else if (Input::get()->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
else if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
else if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchAudio();
|
||||
return;
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
else if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
servicePressedCounter[0]++;
|
||||
service_pressed_counter[0]++;
|
||||
|
||||
if (servicePressedCounter[0] >= 3000)
|
||||
if (service_pressed_counter[0] >= 3000)
|
||||
{
|
||||
OnScreenHelp::get()->toggleState();
|
||||
servicePressedCounter[0] = 0;
|
||||
service_pressed_counter[0] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
servicePressedCounter[0] = 0;
|
||||
service_pressed_counter[0] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||
{
|
||||
// Comprueba si se sale con el mando
|
||||
if (Input::get()->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
quit(section::Options::QUIT_SHUTDOWN);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si se va a resetear el juego
|
||||
else if (Input::get()->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
else if (Input::get()->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
switchAudio();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input::get()->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
servicePressedCounter[i + 1]++;
|
||||
service_pressed_counter[i + 1]++;
|
||||
|
||||
if (servicePressedCounter[i + 1] >= 3000)
|
||||
if (service_pressed_counter[i + 1] >= 3000)
|
||||
{
|
||||
OnScreenHelp::get()->toggleState();
|
||||
servicePressedCounter[i + 1] = 0;
|
||||
service_pressed_counter[i + 1] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
servicePressedCounter[i + 1] = 0;
|
||||
service_pressed_counter[i + 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <vector>
|
||||
namespace globalInputs
|
||||
{
|
||||
extern std::vector<int> servicePressedCounter;
|
||||
extern std::vector<int> service_pressed_counter;
|
||||
|
||||
// Inicializa variables
|
||||
void init();
|
||||
|
||||
@@ -19,40 +19,39 @@
|
||||
|
||||
// Constructor
|
||||
HiScoreTable::HiScoreTable(JA_Music_t *music)
|
||||
: music(music)
|
||||
: music_(music)
|
||||
{
|
||||
// Copia punteros
|
||||
renderer = Screen::get()->getRenderer();
|
||||
renderer_ = Screen::get()->getRenderer();
|
||||
|
||||
// Objetos
|
||||
eventHandler = std::make_unique<SDL_Event>();
|
||||
fade = std::make_unique<Fade>(renderer);
|
||||
background = std::make_unique<Background>(renderer);
|
||||
text = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer);
|
||||
fade_ = std::make_unique<Fade>(renderer_);
|
||||
background_ = std::make_unique<Background>(renderer_);
|
||||
text_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer_);
|
||||
|
||||
// Crea un backbuffer para el renderizador
|
||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND);
|
||||
backbuffer_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
counter = 0;
|
||||
counterEnd = 800;
|
||||
viewArea = {0, 0, param.game.width, param.game.height};
|
||||
fadeMode = FadeMode::IN;
|
||||
ticks_ = 0;
|
||||
ticks_speed_ = 15;
|
||||
counter_ = 0;
|
||||
counter_end_ = 800;
|
||||
view_area_ = {0, 0, param.game.width, param.game.height};
|
||||
fade_mode_ = FadeMode::IN;
|
||||
|
||||
// Inicializa objetos
|
||||
background->setPos(param.game.game_area.rect);
|
||||
background->setCloudsSpeed(-0.1f);
|
||||
background->setGradientNumber(1);
|
||||
background->setTransition(0.8f);
|
||||
fade->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade->setType(FadeType::RANDOM_SQUARE);
|
||||
fade->setPost(param.fade.post_duration);
|
||||
fade->setMode(fadeMode);
|
||||
fade->activate();
|
||||
background_->setPos(param.game.game_area.rect);
|
||||
background_->setCloudsSpeed(-0.1f);
|
||||
background_->setGradientNumber(1);
|
||||
background_->setTransition(0.8f);
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->setPost(param.fade.post_duration);
|
||||
fade_->setMode(fade_mode_);
|
||||
fade_->activate();
|
||||
|
||||
// Crea el contenido de la textura con la lista de puntuaciones
|
||||
fillTexture();
|
||||
@@ -61,45 +60,45 @@ HiScoreTable::HiScoreTable(JA_Music_t *music)
|
||||
// Destructor
|
||||
HiScoreTable::~HiScoreTable()
|
||||
{
|
||||
SDL_DestroyTexture(backbuffer);
|
||||
SDL_DestroyTexture(backbuffer_);
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void HiScoreTable::update()
|
||||
{
|
||||
// Actualiza las variables
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Mantiene la música sonando
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
JA_PlayMusic(music);
|
||||
JA_PlayMusic(music_);
|
||||
}
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza el fondo
|
||||
background->update();
|
||||
background_->update();
|
||||
|
||||
// Gestiona el fade
|
||||
updateFade();
|
||||
|
||||
// Gestiona el contador y sus eventos
|
||||
counter++;
|
||||
counter_++;
|
||||
|
||||
if (counter == 150)
|
||||
if (counter_ == 150)
|
||||
{
|
||||
background->setColor({0, 0, 0});
|
||||
background->setAlpha(96);
|
||||
background_->setColor({0, 0, 0});
|
||||
background_->setAlpha(96);
|
||||
}
|
||||
|
||||
if (counter == counterEnd)
|
||||
if (counter_ == counter_end_)
|
||||
{
|
||||
fade->activate();
|
||||
fade_->activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,40 +106,40 @@ void HiScoreTable::update()
|
||||
// Crea el contenido de la textura con la lista de puntuaciones
|
||||
void HiScoreTable::fillTexture()
|
||||
{
|
||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
|
||||
constexpr auto maxNames = 10;
|
||||
constexpr auto spaceBetweenHeader = 32;
|
||||
const auto spaceBetweenLines = text->getCharacterSize() * 2.0f;
|
||||
const auto size = spaceBetweenHeader + spaceBetweenLines * (maxNames - 1) + text->getCharacterSize();
|
||||
const auto firstLine = (param.game.height - size) / 2;
|
||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
|
||||
constexpr auto max_names = 10;
|
||||
constexpr auto space_between_header = 32;
|
||||
const auto space_between_lines = text_->getCharacterSize() * 2.0f;
|
||||
const auto size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize();
|
||||
const auto first_line = (param.game.height - size) / 2;
|
||||
|
||||
// Pinta en el backbuffer el texto y los sprites
|
||||
auto temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
// Escribe el texto: Mejores puntuaciones
|
||||
text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, firstLine, lang::getText(42), 1, orange_color, 1, shdw_txt_color);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, first_line, lang::getText(42), 1, orange_color, 1, shdw_txt_color);
|
||||
|
||||
// Escribe los nombres de la tabla de puntuaciones
|
||||
for (int i = 0; i < maxNames; ++i)
|
||||
for (int i = 0; i < max_names; ++i)
|
||||
{
|
||||
const auto nameLenght = options.game.hi_score_table[i].name.length();
|
||||
const auto name_lenght = options.game.hi_score_table[i].name.length();
|
||||
const auto score = format(options.game.hi_score_table[i].score);
|
||||
const auto scoreLenght = score.size();
|
||||
const auto numDots = 25 - nameLenght - scoreLenght;
|
||||
const auto score_lenght = score.size();
|
||||
const auto num_dots = 25 - name_lenght - score_lenght;
|
||||
std::string dots = "";
|
||||
for (int j = 0; j < (int)numDots; ++j)
|
||||
for (int j = 0; j < (int)num_dots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const auto line = options.game.hi_score_table[i].name + dots + score;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orange_color, 1, shdw_txt_color);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, (i * space_between_lines) + first_line + space_between_header, line, 1, orange_color, 1, shdw_txt_color);
|
||||
}
|
||||
|
||||
// Cambia el destino de renderizado
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Pinta en pantalla
|
||||
@@ -153,16 +152,16 @@ void HiScoreTable::render()
|
||||
Screen::get()->clean(bg_color);
|
||||
|
||||
// Pinta el fondo
|
||||
background->render();
|
||||
background_->render();
|
||||
|
||||
// Establece la ventana del backbuffer
|
||||
viewArea.y = std::max(0, param.game.height - counter + 100);
|
||||
view_area_.y = std::max(0, param.game.height - counter_ + 100);
|
||||
|
||||
// Copia el backbuffer al renderizador
|
||||
SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea);
|
||||
SDL_RenderCopy(renderer_, backbuffer_, nullptr, &view_area_);
|
||||
|
||||
// Renderiza el fade
|
||||
fade->render();
|
||||
fade_->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
Screen::get()->blit();
|
||||
@@ -171,7 +170,7 @@ void HiScoreTable::render()
|
||||
// Recarga todas las texturas
|
||||
void HiScoreTable::reloadTextures()
|
||||
{
|
||||
text->reLoadTexture();
|
||||
text_->reLoadTexture();
|
||||
fillTexture();
|
||||
}
|
||||
|
||||
@@ -179,19 +178,20 @@ void HiScoreTable::reloadTextures()
|
||||
void HiScoreTable::checkEvents()
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler.get()) != 0)
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba si se ha cambiado el tamaño de la ventana
|
||||
else if (eventHandler->type == SDL_WINDOWEVENT)
|
||||
else if (event.type == SDL_WINDOWEVENT)
|
||||
{
|
||||
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
{
|
||||
reloadTextures();
|
||||
}
|
||||
@@ -233,16 +233,16 @@ void HiScoreTable::run()
|
||||
// Gestiona el fade
|
||||
void HiScoreTable::updateFade()
|
||||
{
|
||||
fade->update();
|
||||
fade_->update();
|
||||
|
||||
if (fade->hasEnded() && fadeMode == FadeMode::IN)
|
||||
if (fade_->hasEnded() && fade_mode_ == FadeMode::IN)
|
||||
{
|
||||
fade->reset();
|
||||
fadeMode = FadeMode::OUT;
|
||||
fade->setMode(fadeMode);
|
||||
fade_->reset();
|
||||
fade_mode_ = FadeMode::OUT;
|
||||
fade_->setMode(fade_mode_);
|
||||
}
|
||||
|
||||
if (fade->hasEnded() && fadeMode == FadeMode::OUT)
|
||||
if (fade_->hasEnded() && fade_mode_ == FadeMode::OUT)
|
||||
{
|
||||
section::name = section::Name::INSTRUCTIONS;
|
||||
}
|
||||
|
||||
@@ -28,22 +28,21 @@ class HiScoreTable
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||
JA_Music_t *music; // Musica de fondo
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
||||
JA_Music_t *music_; // Musica de fondo
|
||||
|
||||
std::unique_ptr<Fade> fade; // Objeto para renderizar fades
|
||||
std::unique_ptr<Background> background; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
|
||||
std::unique_ptr<Text> text; // Objeto para escribir texto
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||
|
||||
// Variables
|
||||
Uint16 counter; // Contador
|
||||
Uint16 counterEnd; // Valor final para el contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
SDL_Rect viewArea; // Parte de la textura que se muestra en pantalla
|
||||
FadeMode fadeMode; // Modo de fade a utilizar
|
||||
Uint16 counter_; // Contador
|
||||
Uint16 counter_end_; // Valor final para el contador
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||
SDL_Rect view_area_; // Parte de la textura que se muestra en pantalla
|
||||
FadeMode fade_mode_; // Modo de fade a utilizar
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
384
source/input.cpp
384
source/input.cpp
@@ -6,122 +6,108 @@
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, basi...
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Input *Input::input = nullptr;
|
||||
Input *Input::input_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto input con esta función estática
|
||||
void Input::init(std::string dbPath)
|
||||
void Input::init(std::string game_controller_db_path)
|
||||
{
|
||||
Input::input = new Input(dbPath);
|
||||
Input::input_ = new Input(game_controller_db_path);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto input con esta función estática
|
||||
void Input::destroy()
|
||||
{
|
||||
delete Input::input;
|
||||
delete Input::input_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto input y podemos trabajar con él
|
||||
Input *Input::get()
|
||||
{
|
||||
return Input::input;
|
||||
return Input::input_;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Input::Input(std::string dbPath)
|
||||
: dbPath(dbPath)
|
||||
Input::Input(std::string game_controller_db_path)
|
||||
: game_controller_db_path_(game_controller_db_path)
|
||||
{
|
||||
// Inicializa variables
|
||||
verbose = false;
|
||||
enabled = true;
|
||||
enabled_ = true;
|
||||
|
||||
// Busca si hay mandos conectados
|
||||
discoverGameControllers();
|
||||
|
||||
// Inicializa las vectores
|
||||
keyBindings_t kb;
|
||||
KeyBindings kb;
|
||||
kb.scancode = 0;
|
||||
kb.active = false;
|
||||
keyBindings.resize(input_number_of_inputs, kb);
|
||||
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), kb);
|
||||
|
||||
GameControllerBindings_t gcb;
|
||||
ControllerBindings gcb;
|
||||
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
gcb.active = false;
|
||||
gameControllerBindings.resize(numGamepads);
|
||||
for (int i = 0; i < numGamepads; ++i)
|
||||
controller_bindings_.resize(num_gamepads_);
|
||||
for (int i = 0; i < num_gamepads_; ++i)
|
||||
{
|
||||
gameControllerBindings[i].resize(input_number_of_inputs, gcb);
|
||||
controller_bindings_[i].resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), gcb);
|
||||
}
|
||||
|
||||
// Listado de los inputs usados para jugar, excluyendo botones para la interfaz
|
||||
gameInputs.clear();
|
||||
gameInputs.push_back(input_fire_left);
|
||||
gameInputs.push_back(input_fire_center);
|
||||
gameInputs.push_back(input_fire_right);
|
||||
gameInputs.push_back(input_up);
|
||||
gameInputs.push_back(input_down);
|
||||
gameInputs.push_back(input_left);
|
||||
gameInputs.push_back(input_right);
|
||||
game_inputs_.clear();
|
||||
game_inputs_.push_back(InputType::FIRE_LEFT);
|
||||
game_inputs_.push_back(InputType::FIRE_CENTER);
|
||||
game_inputs_.push_back(InputType::FIRE_RIGHT);
|
||||
game_inputs_.push_back(InputType::UP);
|
||||
game_inputs_.push_back(InputType::DOWN);
|
||||
game_inputs_.push_back(InputType::LEFT);
|
||||
game_inputs_.push_back(InputType::RIGHT);
|
||||
|
||||
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
||||
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);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Input::~Input()
|
||||
{
|
||||
}
|
||||
|
||||
// Actualiza el estado del objeto
|
||||
void Input::update()
|
||||
{
|
||||
if (disabledUntil == d_keyPressed && !checkAnyInput())
|
||||
{
|
||||
enable();
|
||||
}
|
||||
button_inputs_.clear();
|
||||
button_inputs_.push_back(InputType::FIRE_LEFT);
|
||||
button_inputs_.push_back(InputType::FIRE_CENTER);
|
||||
button_inputs_.push_back(InputType::FIRE_RIGHT);
|
||||
button_inputs_.push_back(InputType::START);
|
||||
}
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void Input::bindKey(inputs_e input, SDL_Scancode code)
|
||||
void Input::bindKey(InputType input, SDL_Scancode code)
|
||||
{
|
||||
keyBindings[input].scancode = code;
|
||||
key_bindings_[static_cast<int>(input)].scancode = code;
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(int index, inputs_e input, SDL_GameControllerButton button)
|
||||
void Input::bindGameControllerButton(int controller_index, InputType input, SDL_GameControllerButton button)
|
||||
{
|
||||
if (index < numGamepads)
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
gameControllerBindings[index][input].button = button;
|
||||
controller_bindings_[controller_index][static_cast<int>(input)].button = button;
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(int index, inputs_e inputTarget, inputs_e inputSource)
|
||||
void Input::bindGameControllerButton(int controller_index, InputType input_target, InputType input_source)
|
||||
{
|
||||
if (index < numGamepads)
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
gameControllerBindings[index][inputTarget].button = gameControllerBindings[index][inputSource].button;
|
||||
controller_bindings_[controller_index][static_cast<int>(input_target)].button = controller_bindings_[controller_index][static_cast<int>(input_source)].button;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(inputs_e input, bool repeat, int device, int index)
|
||||
bool Input::checkInput(InputType input, bool repeat, int device, int controller_index)
|
||||
{
|
||||
if (!enabled)
|
||||
if (!enabled_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool successKeyboard = false;
|
||||
bool successGameController = false;
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
const int input_index = static_cast<int>(input);
|
||||
|
||||
if (device == INPUT_USE_ANY)
|
||||
{
|
||||
index = 0;
|
||||
controller_index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
@@ -130,108 +116,109 @@ bool Input::checkInput(inputs_e input, bool repeat, int device, int index)
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
if (keyStates[keyBindings[input].scancode] != 0)
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
||||
{
|
||||
successKeyboard = true;
|
||||
success_keyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successKeyboard = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!keyBindings[input].active)
|
||||
if (!key_bindings_[input_index].active)
|
||||
{
|
||||
if (keyStates[keyBindings[input].scancode] != 0)
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
||||
{
|
||||
keyBindings[input].active = true;
|
||||
successKeyboard = true;
|
||||
key_bindings_[input_index].active = true;
|
||||
success_keyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successKeyboard = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (keyStates[keyBindings[input].scancode] == 0)
|
||||
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
||||
{
|
||||
keyBindings[input].active = false;
|
||||
successKeyboard = false;
|
||||
key_bindings_[input_index].active = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
successKeyboard = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameControllerFound() && index < numGamepads)
|
||||
if (gameControllerFound() && controller_index < num_gamepads_)
|
||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||
{
|
||||
successGameController = checkAxisInput(input, index);
|
||||
if (!successGameController)
|
||||
success_controller = checkAxisInput(input, controller_index);
|
||||
if (!success_controller)
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
||||
{
|
||||
successGameController = true;
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successGameController = false;
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!gameControllerBindings[index][input].active)
|
||||
if (!controller_bindings_[controller_index][input_index].active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
||||
{
|
||||
gameControllerBindings[index][input].active = true;
|
||||
successGameController = true;
|
||||
controller_bindings_[controller_index][input_index].active = true;
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successGameController = false;
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) == 0)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) == 0)
|
||||
{
|
||||
gameControllerBindings[index][input].active = false;
|
||||
successGameController = false;
|
||||
controller_bindings_[controller_index][input_index].active = false;
|
||||
success_controller = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
successGameController = false;
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (successKeyboard || successGameController);
|
||||
return (success_keyboard || success_controller);
|
||||
}
|
||||
|
||||
// Comprueba si un input con modificador esta activo
|
||||
bool Input::checkModInput(inputs_e inputMod, inputs_e input, bool repeat, int device, int index)
|
||||
bool Input::checkModInput(InputType input_mod, InputType input, bool repeat, int device, int controller_index)
|
||||
{
|
||||
if (!enabled || index >= numGamepads || !checkInput(inputMod, INPUT_ALLOW_REPEAT, device, index))
|
||||
if (!enabled_ || controller_index >= num_gamepads_ || !checkInput(input_mod, INPUT_ALLOW_REPEAT, device, controller_index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool successKeyboard = false;
|
||||
bool successGameController = false;
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
const int input_index = static_cast<int>(input);
|
||||
|
||||
if (device == INPUT_USE_ANY)
|
||||
{
|
||||
index = 0;
|
||||
controller_index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
@@ -240,111 +227,111 @@ bool Input::checkModInput(inputs_e inputMod, inputs_e input, bool repeat, int de
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
if (keyStates[keyBindings[input].scancode] != 0)
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
||||
{
|
||||
successKeyboard = true;
|
||||
success_keyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successKeyboard = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!keyBindings[input].active)
|
||||
if (!key_bindings_[input_index].active)
|
||||
{
|
||||
if (keyStates[keyBindings[input].scancode] != 0)
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
||||
{
|
||||
keyBindings[input].active = true;
|
||||
successKeyboard = true;
|
||||
key_bindings_[input_index].active = true;
|
||||
success_keyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successKeyboard = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (keyStates[keyBindings[input].scancode] == 0)
|
||||
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
||||
{
|
||||
keyBindings[input].active = false;
|
||||
successKeyboard = false;
|
||||
key_bindings_[input_index].active = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
successKeyboard = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameControllerFound() && index < numGamepads)
|
||||
if (gameControllerFound() && controller_index < num_gamepads_)
|
||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||
{
|
||||
successGameController = checkAxisInput(input, index);
|
||||
if (!successGameController)
|
||||
success_controller = checkAxisInput(input, controller_index);
|
||||
if (!success_controller)
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
||||
{
|
||||
successGameController = true;
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successGameController = false;
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!gameControllerBindings[index][input].active)
|
||||
if (!controller_bindings_[controller_index][input_index].active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
||||
{
|
||||
gameControllerBindings[index][input].active = true;
|
||||
successGameController = true;
|
||||
controller_bindings_[controller_index][input_index].active = true;
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successGameController = false;
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) == 0)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) == 0)
|
||||
{
|
||||
gameControllerBindings[index][input].active = false;
|
||||
successGameController = false;
|
||||
controller_bindings_[controller_index][input_index].active = false;
|
||||
success_controller = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
successGameController = false;
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (successKeyboard || successGameController);
|
||||
return (success_keyboard || success_controller);
|
||||
}
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
bool Input::checkAnyInput(int device, int index)
|
||||
bool Input::checkAnyInput(int device, int controller_index)
|
||||
{
|
||||
if (device == INPUT_USE_ANY)
|
||||
{
|
||||
index = 0;
|
||||
controller_index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
for (int i = 0; i < (int)keyBindings.size(); ++i)
|
||||
for (int i = 0; i < (int)key_bindings_.size(); ++i)
|
||||
{
|
||||
if (mKeystates[keyBindings[i].scancode] != 0 && !keyBindings[i].active)
|
||||
if (mKeystates[key_bindings_[i].scancode] != 0 && !key_bindings_[i].active)
|
||||
{
|
||||
keyBindings[i].active = true;
|
||||
key_bindings_[i].active = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -354,11 +341,11 @@ bool Input::checkAnyInput(int device, int index)
|
||||
{
|
||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
||||
{
|
||||
for (int i = 0; i < (int)gameControllerBindings.size(); ++i)
|
||||
for (int i = 0; i < (int)controller_bindings_.size(); ++i)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][i].button) != 0 && !gameControllerBindings[index][i].active)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][i].button) != 0 && !controller_bindings_[controller_index][i].active)
|
||||
{
|
||||
gameControllerBindings[index][i].active = true;
|
||||
controller_bindings_[controller_index][i].active = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -372,13 +359,13 @@ bool Input::checkAnyInput(int device, int index)
|
||||
int Input::checkAnyButtonPressed(bool repeat)
|
||||
{
|
||||
// Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado
|
||||
if (checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_ANY))
|
||||
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_ANY))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Solo comprueba los botones definidos previamente
|
||||
for (auto bi : buttonInputs)
|
||||
for (auto bi : button_inputs_)
|
||||
{
|
||||
// Comprueba el teclado
|
||||
if (checkInput(bi, repeat, INPUT_USE_KEYBOARD))
|
||||
@@ -387,7 +374,7 @@ int Input::checkAnyButtonPressed(bool repeat)
|
||||
}
|
||||
|
||||
// Comprueba los mandos
|
||||
for (int i = 0; i < numGamepads; ++i)
|
||||
for (int i = 0; i < num_gamepads_; ++i)
|
||||
{
|
||||
if (checkInput(bi, repeat, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
@@ -409,60 +396,64 @@ bool Input::discoverGameControllers()
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
|
||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
||||
{
|
||||
if (verbose)
|
||||
#ifdef VERBOSE
|
||||
{
|
||||
std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
numJoysticks = SDL_NumJoysticks();
|
||||
numGamepads = 0;
|
||||
num_joysticks_ = SDL_NumJoysticks();
|
||||
num_gamepads_ = 0;
|
||||
|
||||
// Cuenta el número de mandos
|
||||
joysticks.clear();
|
||||
for (int i = 0; i < numJoysticks; ++i)
|
||||
joysticks_.clear();
|
||||
for (int i = 0; i < num_joysticks_; ++i)
|
||||
{
|
||||
SDL_Joystick *joy = SDL_JoystickOpen(i);
|
||||
joysticks.push_back(joy);
|
||||
joysticks_.push_back(joy);
|
||||
if (SDL_IsGameController(i))
|
||||
{
|
||||
numGamepads++;
|
||||
num_gamepads_++;
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
#ifdef VERBOSE
|
||||
{
|
||||
std::cout << "\nChecking for game controllers...\n";
|
||||
std::cout << numJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
||||
std::cout << num_joysticks_ << " joysticks found, " << num_gamepads_ << " are gamepads\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (numGamepads > 0)
|
||||
if (num_gamepads_ > 0)
|
||||
{
|
||||
found = true;
|
||||
|
||||
for (int i = 0; i < numGamepads; i++)
|
||||
for (int i = 0; i < num_gamepads_; i++)
|
||||
{
|
||||
// Abre el mando y lo añade a la lista
|
||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
{
|
||||
connectedControllers.push_back(pad);
|
||||
connected_controllers_.push_back(pad);
|
||||
const std::string separator(" #");
|
||||
std::string name = SDL_GameControllerNameForIndex(i);
|
||||
if (verbose)
|
||||
#ifdef VERBOSE
|
||||
{
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
controllerNames.push_back(name);
|
||||
#endif
|
||||
controller_names_.push_back(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose)
|
||||
#ifdef VERBOSE
|
||||
{
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,47 +466,27 @@ bool Input::discoverGameControllers()
|
||||
// Comprueba si hay algun mando conectado
|
||||
bool Input::gameControllerFound()
|
||||
{
|
||||
return numGamepads > 0 ? true : false;
|
||||
return num_gamepads_ > 0 ? true : false;
|
||||
}
|
||||
|
||||
// Obten el nombre de un mando de juego
|
||||
std::string Input::getControllerName(int index) const
|
||||
std::string Input::getControllerName(int controller_index) const
|
||||
{
|
||||
return numGamepads > 0 ? controllerNames[index] : "";
|
||||
return num_gamepads_ > 0 ? controller_names_[controller_index] : "";
|
||||
}
|
||||
|
||||
// Obten el número de mandos conectados
|
||||
int Input::getNumControllers() const
|
||||
{
|
||||
return numGamepads;
|
||||
}
|
||||
|
||||
// Establece si ha de mostrar mensajes
|
||||
void Input::setVerbose(bool value)
|
||||
{
|
||||
verbose = value;
|
||||
}
|
||||
|
||||
// Deshabilita las entradas durante un periodo de tiempo
|
||||
void Input::disableUntil(i_disable_e value)
|
||||
{
|
||||
disabledUntil = value;
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
// Hablita las entradas
|
||||
void Input::enable()
|
||||
{
|
||||
enabled = true;
|
||||
disabledUntil = d_notDisabled;
|
||||
return num_gamepads_;
|
||||
}
|
||||
|
||||
// Obtiene el indice del controlador a partir de un event.id
|
||||
int Input::getJoyIndex(int id) const
|
||||
{
|
||||
for (int i = 0; i < numJoysticks; ++i)
|
||||
for (int i = 0; i < num_joysticks_; ++i)
|
||||
{
|
||||
if (SDL_JoystickInstanceID(joysticks[i]) == id)
|
||||
if (SDL_JoystickInstanceID(joysticks_[i]) == id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -524,7 +495,7 @@ int Input::getJoyIndex(int id) const
|
||||
}
|
||||
|
||||
// Muestra por consola los controles asignados
|
||||
void Input::printBindings(int device, int index) const
|
||||
void Input::printBindings(int device, int controller_index) const
|
||||
{
|
||||
if (device == INPUT_USE_ANY || device == INPUT_USE_KEYBOARD)
|
||||
{
|
||||
@@ -533,35 +504,35 @@ void Input::printBindings(int device, int index) const
|
||||
|
||||
if (device == INPUT_USE_GAMECONTROLLER)
|
||||
{
|
||||
if (index >= numGamepads)
|
||||
if (controller_index >= num_gamepads_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Muestra el nombre del mando
|
||||
std::cout << "\n"
|
||||
<< controllerNames[index] << std::endl;
|
||||
<< controller_names_[controller_index] << std::endl;
|
||||
|
||||
// Muestra los botones asignados
|
||||
for (auto bi : buttonInputs)
|
||||
for (auto bi : button_inputs_)
|
||||
{
|
||||
std::cout << to_string(bi) << " : " << gameControllerBindings[index][bi].button << std::endl;
|
||||
std::cout << to_string(bi) << " : " << controller_bindings_[controller_index][static_cast<int>(bi)].button << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton Input::getControllerBinding(int index, inputs_e input) const
|
||||
SDL_GameControllerButton Input::getControllerBinding(int controller_index, InputType input) const
|
||||
{
|
||||
return gameControllerBindings[index][input].button;
|
||||
return controller_bindings_[controller_index][static_cast<int>(input)].button;
|
||||
}
|
||||
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int Input::getIndexByName(std::string name) const
|
||||
{
|
||||
for (int i = 0; i < numGamepads; ++i)
|
||||
for (int i = 0; i < num_gamepads_; ++i)
|
||||
{
|
||||
if (controllerNames[i] == name)
|
||||
if (controller_names_[i] == name)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -569,30 +540,30 @@ int Input::getIndexByName(std::string name) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Convierte un inputs_e a std::string
|
||||
std::string Input::to_string(inputs_e input) const
|
||||
// Convierte un InputType a std::string
|
||||
std::string Input::to_string(InputType input) const
|
||||
{
|
||||
if (input == input_fire_left)
|
||||
if (input == InputType::FIRE_LEFT)
|
||||
{
|
||||
return "input_fire_left";
|
||||
}
|
||||
|
||||
if (input == input_fire_center)
|
||||
if (input == InputType::FIRE_CENTER)
|
||||
{
|
||||
return "input_fire_center";
|
||||
}
|
||||
|
||||
if (input == input_fire_right)
|
||||
if (input == InputType::FIRE_RIGHT)
|
||||
{
|
||||
return "input_fire_right";
|
||||
}
|
||||
|
||||
if (input == input_start)
|
||||
if (input == InputType::START)
|
||||
{
|
||||
return "input_start";
|
||||
}
|
||||
|
||||
if (input == input_service)
|
||||
if (input == InputType::SERVICE)
|
||||
{
|
||||
return "input_service";
|
||||
}
|
||||
@@ -600,76 +571,77 @@ std::string Input::to_string(inputs_e input) const
|
||||
return "";
|
||||
}
|
||||
|
||||
// Convierte un std::string a inputs_e
|
||||
inputs_e Input::to_inputs_e(std::string name) const
|
||||
// Convierte un std::string a InputType
|
||||
InputType Input::to_inputs_e(std::string name) const
|
||||
{
|
||||
if (name == "input_fire_left")
|
||||
{
|
||||
return input_fire_left;
|
||||
return InputType::FIRE_LEFT;
|
||||
}
|
||||
|
||||
if (name == "input_fire_center")
|
||||
{
|
||||
return input_fire_center;
|
||||
return InputType::FIRE_CENTER;
|
||||
}
|
||||
|
||||
if (name == "input_fire_right")
|
||||
{
|
||||
return input_fire_right;
|
||||
return InputType::FIRE_RIGHT;
|
||||
}
|
||||
|
||||
if (name == "input_start")
|
||||
{
|
||||
return input_start;
|
||||
return InputType::START;
|
||||
}
|
||||
|
||||
if (name == "input_service")
|
||||
{
|
||||
return input_service;
|
||||
return InputType::SERVICE;
|
||||
}
|
||||
|
||||
return input_null;
|
||||
return InputType::NONE;
|
||||
}
|
||||
|
||||
// Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando
|
||||
void Input::allActive(int index)
|
||||
/*void Input::allActive(int controller_index)
|
||||
{
|
||||
for (int i = 0; i < (int)buttonInputs.size(); ++i)
|
||||
for (int i = 0; i < (int)button_inputs_.size(); ++i)
|
||||
{
|
||||
gameControllerBindings[index][i].active = true;
|
||||
controller_bindings_[controller_index][i].active = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool Input::checkAxisInput(inputs_e input, int index) const
|
||||
bool Input::checkAxisInput(InputType input, int controller_index) const
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case input_left:
|
||||
if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTX) < -30000)
|
||||
case InputType::LEFT:
|
||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -30000)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case input_right:
|
||||
if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTX) > 30000)
|
||||
case InputType::RIGHT:
|
||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > 30000)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case input_up:
|
||||
if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTY) < -30000)
|
||||
case InputType::UP:
|
||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -30000)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case input_down:
|
||||
if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTY) > 30000)
|
||||
case InputType::DOWN:
|
||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > 30000)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
|
||||
153
source/input.h
153
source/input.h
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton, SDL_G...
|
||||
#include <SDL2/SDL_joystick.h> // for SDL_Joystick
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_Scancode
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton, SDL_G...
|
||||
#include <SDL2/SDL_joystick.h> // for SDL_Joystick
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_Scancode
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
/*
|
||||
connectedControllers es un vector donde estan todos los mandos encontrados [0 .. n]
|
||||
@@ -16,98 +16,89 @@ device contiene el tipo de dispositivo a comprobar:
|
||||
INPUT_USE_ANY mirará tanto el teclado como el PRIMER controlador
|
||||
*/
|
||||
|
||||
enum inputs_e
|
||||
enum class InputType : int
|
||||
{
|
||||
// Inputs de movimiento
|
||||
input_up,
|
||||
input_down,
|
||||
input_left,
|
||||
input_right,
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
|
||||
// Inputs personalizados
|
||||
input_fire_left,
|
||||
input_fire_center,
|
||||
input_fire_right,
|
||||
input_start,
|
||||
FIRE_LEFT,
|
||||
FIRE_CENTER,
|
||||
FIRE_RIGHT,
|
||||
START,
|
||||
|
||||
// Inputs de control
|
||||
input_exit,
|
||||
input_pause,
|
||||
input_service,
|
||||
input_window_fullscreen,
|
||||
input_window_inc_size,
|
||||
input_window_dec_size,
|
||||
input_video_shaders,
|
||||
input_reset,
|
||||
input_mute,
|
||||
input_showinfo,
|
||||
input_config,
|
||||
input_swap_controllers,
|
||||
EXIT,
|
||||
PAUSE,
|
||||
SERVICE,
|
||||
WINDOW_FULLSCREEN,
|
||||
WINDOW_INC_SIZE,
|
||||
WINDOW_DEC_SIZE,
|
||||
VIDEO_SHADERS,
|
||||
RESET,
|
||||
MUTE,
|
||||
SHOWINFO,
|
||||
CONFIG,
|
||||
SWAP_CONTROLLERS,
|
||||
|
||||
// Input obligatorio
|
||||
input_null,
|
||||
input_number_of_inputs,
|
||||
NONE,
|
||||
NUMBER_OF_INPUTS,
|
||||
};
|
||||
|
||||
#define INPUT_ALLOW_REPEAT true
|
||||
#define INPUT_DO_NOT_ALLOW_REPEAT false
|
||||
constexpr bool INPUT_ALLOW_REPEAT = true;
|
||||
constexpr bool INPUT_DO_NOT_ALLOW_REPEAT = false;
|
||||
|
||||
#define INPUT_USE_KEYBOARD 0
|
||||
#define INPUT_USE_GAMECONTROLLER 1
|
||||
#define INPUT_USE_ANY 2
|
||||
|
||||
enum i_disable_e
|
||||
{
|
||||
d_notDisabled,
|
||||
d_forever,
|
||||
d_keyPressed
|
||||
};
|
||||
constexpr int INPUT_USE_KEYBOARD = 0;
|
||||
constexpr int INPUT_USE_GAMECONTROLLER = 1;
|
||||
constexpr int INPUT_USE_ANY = 2;
|
||||
|
||||
class Input
|
||||
{
|
||||
private:
|
||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
||||
static Input *input;
|
||||
static Input *input_;
|
||||
|
||||
struct keyBindings_t
|
||||
struct KeyBindings
|
||||
{
|
||||
Uint8 scancode; // Scancode asociado
|
||||
bool active; // Indica si está activo
|
||||
};
|
||||
|
||||
struct GameControllerBindings_t
|
||||
struct ControllerBindings
|
||||
{
|
||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||
bool active; // Indica si está activo
|
||||
};
|
||||
|
||||
// Variables
|
||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||
std::vector<SDL_Joystick *> joysticks; // Vector con todos los joysticks conectados
|
||||
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
std::vector<std::vector<GameControllerBindings_t>> gameControllerBindings; // Vector con los botones asociadas a los inputs predefinidos para cada mando
|
||||
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 numJoysticks; // Número de joysticks conectados
|
||||
int numGamepads; // Número de mandos conectados
|
||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
||||
bool verbose; // Indica si ha de mostrar mensajes
|
||||
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
||||
bool enabled; // Indica si está habilitado
|
||||
std::vector<SDL_GameController *> connected_controllers_; // Vector con todos los mandos conectados
|
||||
std::vector<SDL_Joystick *> joysticks_; // Vector con todos los joysticks conectados
|
||||
std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
std::vector<std::vector<ControllerBindings>> controller_bindings_; // Vector con los botones asociadas a los inputs predefinidos para cada mando
|
||||
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
||||
std::vector<InputType> game_inputs_; // Inputs usados para jugar, normalmente direcciones y botones
|
||||
std::vector<InputType> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
||||
int num_joysticks_; // Número de joysticks conectados
|
||||
int num_gamepads_; // Número de mandos conectados
|
||||
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||
bool enabled_; // Indica si está habilitado
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool checkAxisInput(inputs_e input, int index = 0) const;
|
||||
bool checkAxisInput(InputType input, int controller_index = 0) const;
|
||||
|
||||
// Constructor
|
||||
Input(std::string dbPath);
|
||||
Input(std::string game_controller_db_path);
|
||||
|
||||
// Destructor
|
||||
~Input();
|
||||
~Input() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
static void init(std::string dbPath);
|
||||
static void init(std::string game_controller_db_path);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
static void destroy();
|
||||
@@ -115,24 +106,21 @@ public:
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
static Input *get();
|
||||
|
||||
// Actualiza el estado del objeto
|
||||
void update();
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void bindKey(inputs_e input, SDL_Scancode code);
|
||||
void bindKey(InputType input, SDL_Scancode code);
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void bindGameControllerButton(int index, inputs_e input, SDL_GameControllerButton button);
|
||||
void bindGameControllerButton(int index, inputs_e inputTarget, inputs_e inputSource);
|
||||
void bindGameControllerButton(int controller_index, InputType input, SDL_GameControllerButton button);
|
||||
void bindGameControllerButton(int controller_index, InputType inputTarget, InputType inputSource);
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool checkInput(inputs_e input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0);
|
||||
bool checkInput(InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si un input con modificador esta activo
|
||||
bool checkModInput(inputs_e inputMod, inputs_e input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0);
|
||||
bool checkModInput(InputType input_mod, InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);
|
||||
bool checkAnyInput(int device = INPUT_USE_ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si hay algún botón pulsado
|
||||
int checkAnyButtonPressed(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT);
|
||||
@@ -147,35 +135,26 @@ public:
|
||||
int getNumControllers() const;
|
||||
|
||||
// Obten el nombre de un mando de juego
|
||||
std::string getControllerName(int index) const;
|
||||
|
||||
// Establece si ha de mostrar mensajes
|
||||
void setVerbose(bool value);
|
||||
|
||||
// Deshabilita las entradas durante un periodo de tiempo
|
||||
void disableUntil(i_disable_e value);
|
||||
|
||||
// Hablita las entradas
|
||||
void enable();
|
||||
std::string getControllerName(int controller_index) const;
|
||||
|
||||
// Obtiene el indice del controlador a partir de un event.id
|
||||
int getJoyIndex(int id) const;
|
||||
|
||||
// Muestra por consola los controles asignados
|
||||
void printBindings(int device = INPUT_USE_KEYBOARD, int index = 0) const;
|
||||
void printBindings(int device = INPUT_USE_KEYBOARD, int controller_index = 0) const;
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton getControllerBinding(int index, inputs_e input) const;
|
||||
SDL_GameControllerButton getControllerBinding(int controller_index, InputType input) const;
|
||||
|
||||
// Convierte un inputs_e a std::string
|
||||
std::string to_string(inputs_e input) const;
|
||||
// Convierte un InputType a std::string
|
||||
std::string to_string(InputType input) const;
|
||||
|
||||
// Convierte un std::string a inputs_e
|
||||
inputs_e to_inputs_e(std::string name) const;
|
||||
// Convierte un std::string a InputType
|
||||
InputType to_inputs_e(std::string name) const;
|
||||
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int getIndexByName(std::string name) const;
|
||||
|
||||
// Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando
|
||||
void allActive(int index);
|
||||
//void allActive(int index);
|
||||
};
|
||||
@@ -57,11 +57,11 @@ void initOptions()
|
||||
|
||||
// Inputs que se guardan en las opciones y, por tanto, a disco
|
||||
c.inputs.clear();
|
||||
c.inputs.push_back(input_fire_left);
|
||||
c.inputs.push_back(input_fire_center);
|
||||
c.inputs.push_back(input_fire_right);
|
||||
c.inputs.push_back(input_start);
|
||||
c.inputs.push_back(input_service);
|
||||
c.inputs.push_back(InputType::FIRE_LEFT);
|
||||
c.inputs.push_back(InputType::FIRE_CENTER);
|
||||
c.inputs.push_back(InputType::FIRE_RIGHT);
|
||||
c.inputs.push_back(InputType::START);
|
||||
c.inputs.push_back(InputType::SERVICE);
|
||||
|
||||
// Botones asociados a los inputs anteriores
|
||||
c.buttons.clear();
|
||||
|
||||
@@ -77,7 +77,7 @@ void Player::init()
|
||||
}
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void Player::setInput(int input)
|
||||
void Player::setInput(InputType input)
|
||||
{
|
||||
switch (status_playing_)
|
||||
{
|
||||
@@ -99,37 +99,37 @@ void Player::setInput(int input)
|
||||
}
|
||||
|
||||
// Procesa inputs para cuando está jugando
|
||||
void Player::setInputPlaying(int input)
|
||||
void Player::setInputPlaying(InputType input)
|
||||
{
|
||||
switch (input)
|
||||
{
|
||||
case input_left:
|
||||
case InputType::LEFT:
|
||||
{
|
||||
vel_x_ = -base_speed_;
|
||||
setWalkingStatus(PlayerStatus::WALKING_LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
case input_right:
|
||||
case InputType::RIGHT:
|
||||
{
|
||||
vel_x_ = base_speed_;
|
||||
setWalkingStatus(PlayerStatus::WALKING_RIGHT);
|
||||
break;
|
||||
}
|
||||
|
||||
case input_fire_center:
|
||||
case InputType::FIRE_CENTER:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_UP);
|
||||
break;
|
||||
}
|
||||
|
||||
case input_fire_left:
|
||||
case InputType::FIRE_LEFT:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
case input_fire_right:
|
||||
case InputType::FIRE_RIGHT:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_RIGHT);
|
||||
break;
|
||||
@@ -145,27 +145,27 @@ void Player::setInputPlaying(int input)
|
||||
}
|
||||
|
||||
// Procesa inputs para cuando está introduciendo el nombre
|
||||
void Player::setInputEnteringName(int input)
|
||||
void Player::setInputEnteringName(InputType input)
|
||||
{
|
||||
switch (input)
|
||||
{
|
||||
case input_left:
|
||||
case InputType::LEFT:
|
||||
enter_name_->decPos();
|
||||
break;
|
||||
|
||||
case input_right:
|
||||
case InputType::RIGHT:
|
||||
enter_name_->incPos();
|
||||
break;
|
||||
|
||||
case input_up:
|
||||
case InputType::UP:
|
||||
enter_name_->incIndex();
|
||||
break;
|
||||
|
||||
case input_down:
|
||||
case InputType::DOWN:
|
||||
enter_name_->decIndex();
|
||||
break;
|
||||
|
||||
case input_start:
|
||||
case InputType::START:
|
||||
setRecordName(enter_name_->getName());
|
||||
break;
|
||||
|
||||
|
||||
@@ -121,13 +121,13 @@ public:
|
||||
void setPlayerTextures(std::vector<std::shared_ptr<Texture>> texture);
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void setInput(int input);
|
||||
void setInput(InputType input);
|
||||
|
||||
// Procesa inputs para cuando está jugando
|
||||
void setInputPlaying(int input);
|
||||
void setInputPlaying(InputType input);
|
||||
|
||||
// Procesa inputs para cuando está introduciendo el nombre
|
||||
void setInputEnteringName(int input);
|
||||
void setInputEnteringName(InputType input);
|
||||
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
void move();
|
||||
|
||||
@@ -293,7 +293,7 @@ void Screen::checkInput()
|
||||
{
|
||||
#ifndef ARCADE
|
||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||
if (Input::get()->checkInput(input_window_fullscreen, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchVideoMode();
|
||||
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||
@@ -302,7 +302,7 @@ void Screen::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(input_window_dec_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
decWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
@@ -311,7 +311,7 @@ void Screen::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(input_window_inc_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
incWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
@@ -321,7 +321,7 @@ void Screen::checkInput()
|
||||
#endif
|
||||
|
||||
// Comprueba el teclado para activar o desactivar los shaders
|
||||
if (Input::get()->checkInput(input_video_shaders, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchShaders();
|
||||
return;
|
||||
@@ -329,7 +329,7 @@ void Screen::checkInput()
|
||||
|
||||
#ifdef DEBUG
|
||||
// Comprueba el teclado para mostrar la información de debug
|
||||
if (Input::get()->checkInput(input_showinfo, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
show_info_ = !show_info_;
|
||||
return;
|
||||
@@ -339,14 +339,14 @@ void Screen::checkInput()
|
||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||
{
|
||||
// Comprueba los mandos para activar o desactivar los shaders
|
||||
if (Input::get()->checkModInput(input_service, input_video_shaders, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
switchShaders();
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba los mandos para mostrar la información de debug
|
||||
if (Input::get()->checkModInput(input_service, input_showinfo, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
show_info_ = !show_info_;
|
||||
return;
|
||||
@@ -489,7 +489,7 @@ void Screen::displayInfo()
|
||||
// Resolution
|
||||
dbg_print(0, 0, info_resolution_.c_str(), 255, 255, 0);
|
||||
|
||||
dbg_print(0, 8, std::to_string(globalInputs::servicePressedCounter[0]).c_str(), 255, 255, 0);
|
||||
dbg_print(0, 8, std::to_string(globalInputs::service_pressed_counter[0]).c_str(), 255, 255, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ void Title::checkInput()
|
||||
if (!define_buttons_->isEnabled())
|
||||
{
|
||||
// Comprueba el teclado para empezar a jugar
|
||||
if (input_->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
{
|
||||
@@ -249,24 +249,24 @@ void Title::checkInput()
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
||||
if (input_->checkModInput(input_service, input_swap_controllers, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (input_->checkModInput(InputType::SERVICE, InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
swapControllers();
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si algun mando quiere ser configurado
|
||||
if (input_->checkModInput(input_service, input_config, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (input_->checkModInput(InputType::SERVICE, InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
define_buttons_->enable(i);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el botón de START de los mandos
|
||||
if (input_->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
// Si no está el botón de servicio activo
|
||||
if (!input_->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (!input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
{
|
||||
|
||||
@@ -126,7 +126,7 @@ struct OptionsController
|
||||
Uint8 device_type; // Indica si se utilizará teclado o mando o ambos
|
||||
std::string name; // Nombre del dispositivo
|
||||
bool plugged; // Indica si el mando se encuentra conectado
|
||||
std::vector<inputs_e> inputs; // Listado de inputs
|
||||
std::vector<InputType> inputs; // Listado de inputs
|
||||
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user