style: renomenat InputType a InputActions

This commit is contained in:
2025-03-16 18:57:08 +01:00
parent 1b38a5a581
commit 43a1f1a8f6
13 changed files with 199 additions and 199 deletions

View File

@@ -1,5 +1,5 @@
#include "define_buttons.h" #include "define_buttons.h"
#include "input.h" // Para Input, InputType #include "input.h" // Para Input, InputAction
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "options.h" // Para OptionsController, Options, options #include "options.h" // Para OptionsController, Options, options
#include "param.h" // Para Param, param, ParamGame, ParamTitle #include "param.h" // Para Param, param, ParamGame, ParamTitle
@@ -135,9 +135,9 @@ bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button)
void DefineButtons::clearButtons() void DefineButtons::clearButtons()
{ {
buttons_.clear(); buttons_.clear();
buttons_.emplace_back(lang::getText(95), InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_INVALID); buttons_.emplace_back(lang::getText(95), InputAction::FIRE_LEFT, SDL_CONTROLLER_BUTTON_INVALID);
buttons_.emplace_back(lang::getText(96), InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_INVALID); buttons_.emplace_back(lang::getText(96), InputAction::FIRE_CENTER, SDL_CONTROLLER_BUTTON_INVALID);
buttons_.emplace_back(lang::getText(97), InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_INVALID); buttons_.emplace_back(lang::getText(97), InputAction::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_INVALID);
buttons_.emplace_back(lang::getText(98), InputType::START, SDL_CONTROLLER_BUTTON_INVALID); buttons_.emplace_back(lang::getText(98), InputAction::START, SDL_CONTROLLER_BUTTON_INVALID);
buttons_.emplace_back(lang::getText(99), InputType::SERVICE, SDL_CONTROLLER_BUTTON_INVALID); buttons_.emplace_back(lang::getText(99), InputAction::SERVICE, SDL_CONTROLLER_BUTTON_INVALID);
} }

View File

@@ -8,16 +8,16 @@
#include <vector> // Para vector #include <vector> // Para vector
class Input; // lines 8-8 class Input; // lines 8-8
class Text; // lines 9-9 class Text; // lines 9-9
enum class InputType : int; // lines 10-10 enum class InputAction : int; // lines 10-10
struct DefineButtonsButton struct DefineButtonsButton
{ {
std::string label; // Texto en pantalla para el botón std::string label; // Texto en pantalla para el botón
InputType input; // Input asociado InputAction input; // Input asociado
SDL_GameControllerButton button; // Botón del mando correspondiente SDL_GameControllerButton button; // Botón del mando correspondiente
// Constructor // Constructor
DefineButtonsButton(const std::string &lbl, InputType inp, SDL_GameControllerButton btn) DefineButtonsButton(const std::string &lbl, InputAction inp, SDL_GameControllerButton btn)
: label(lbl), input(inp), button(btn) {} : label(lbl), input(inp), button(btn) {}
}; };

View File

@@ -27,7 +27,7 @@
#include "dbgtxt.h" // Para dbg_init #include "dbgtxt.h" // Para dbg_init
#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_... #include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_...
#include "hiscore_table.h" // Para HiScoreTable #include "hiscore_table.h" // Para HiScoreTable
#include "input.h" // Para Input, InputType #include "input.h" // Para Input, InputAction
#include "instructions.h" // Para Instructions #include "instructions.h" // Para Instructions
#include "intro.h" // Para Intro #include "intro.h" // Para Intro
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV... #include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
@@ -167,58 +167,58 @@ void Director::loadScoreFile()
void Director::bindInputs() void Director::bindInputs()
{ {
// Teclado - Movimiento del jugador // Teclado - Movimiento del jugador
Input::get()->bindKey(InputType::UP, SDL_SCANCODE_UP); Input::get()->bindKey(InputAction::UP, SDL_SCANCODE_UP);
Input::get()->bindKey(InputType::DOWN, SDL_SCANCODE_DOWN); Input::get()->bindKey(InputAction::DOWN, SDL_SCANCODE_DOWN);
Input::get()->bindKey(InputType::LEFT, SDL_SCANCODE_LEFT); Input::get()->bindKey(InputAction::LEFT, SDL_SCANCODE_LEFT);
Input::get()->bindKey(InputType::RIGHT, SDL_SCANCODE_RIGHT); Input::get()->bindKey(InputAction::RIGHT, SDL_SCANCODE_RIGHT);
Input::get()->bindKey(InputType::FIRE_LEFT, SDL_SCANCODE_Q); Input::get()->bindKey(InputAction::FIRE_LEFT, SDL_SCANCODE_Q);
Input::get()->bindKey(InputType::FIRE_CENTER, SDL_SCANCODE_W); Input::get()->bindKey(InputAction::FIRE_CENTER, SDL_SCANCODE_W);
Input::get()->bindKey(InputType::FIRE_RIGHT, SDL_SCANCODE_E); Input::get()->bindKey(InputAction::FIRE_RIGHT, SDL_SCANCODE_E);
Input::get()->bindKey(InputType::START, SDL_SCANCODE_RETURN); Input::get()->bindKey(InputAction::START, SDL_SCANCODE_RETURN);
// Teclado - Control del programa // Teclado - Control del programa
Input::get()->bindKey(InputType::SERVICE, SDL_SCANCODE_0); Input::get()->bindKey(InputAction::SERVICE, SDL_SCANCODE_0);
Input::get()->bindKey(InputType::EXIT, SDL_SCANCODE_ESCAPE); Input::get()->bindKey(InputAction::EXIT, SDL_SCANCODE_ESCAPE);
Input::get()->bindKey(InputType::PAUSE, SDL_SCANCODE_P); Input::get()->bindKey(InputAction::PAUSE, SDL_SCANCODE_P);
Input::get()->bindKey(InputType::WINDOW_DEC_SIZE, SDL_SCANCODE_F1); Input::get()->bindKey(InputAction::WINDOW_DEC_SIZE, SDL_SCANCODE_F1);
Input::get()->bindKey(InputType::WINDOW_INC_SIZE, SDL_SCANCODE_F2); Input::get()->bindKey(InputAction::WINDOW_INC_SIZE, SDL_SCANCODE_F2);
Input::get()->bindKey(InputType::WINDOW_FULLSCREEN, SDL_SCANCODE_F3); Input::get()->bindKey(InputAction::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
Input::get()->bindKey(InputType::VIDEO_SHADERS, SDL_SCANCODE_F4); Input::get()->bindKey(InputAction::VIDEO_SHADERS, SDL_SCANCODE_F4);
Input::get()->bindKey(InputType::VIDEO_INTEGER_SCALE, SDL_SCANCODE_F5); Input::get()->bindKey(InputAction::VIDEO_INTEGER_SCALE, SDL_SCANCODE_F5);
Input::get()->bindKey(InputType::MUTE, SDL_SCANCODE_F6); Input::get()->bindKey(InputAction::MUTE, SDL_SCANCODE_F6);
Input::get()->bindKey(InputType::AUTO_FIRE, SDL_SCANCODE_F7); Input::get()->bindKey(InputAction::AUTO_FIRE, SDL_SCANCODE_F7);
Input::get()->bindKey(InputType::CHANGE_LANG, SDL_SCANCODE_F8); Input::get()->bindKey(InputAction::CHANGE_LANG, SDL_SCANCODE_F8);
Input::get()->bindKey(InputType::RESET, SDL_SCANCODE_F10); Input::get()->bindKey(InputAction::RESET, SDL_SCANCODE_F10);
Input::get()->bindKey(InputType::SHOWINFO, SDL_SCANCODE_F12); Input::get()->bindKey(InputAction::SHOW_INFO, SDL_SCANCODE_F12);
// Asigna botones a inputs // Asigna botones a inputs
const int num_gamepads = Input::get()->getNumControllers(); const int NUM_GAMEPADS = Input::get()->getNumControllers();
for (int i = 0; i < num_gamepads; ++i) for (int i = 0; i < NUM_GAMEPADS; ++i)
{ {
// Mando - Movimiento del jugador // Mando - Movimiento del jugador
Input::get()->bindGameControllerButton(i, InputType::UP, SDL_CONTROLLER_BUTTON_DPAD_UP); Input::get()->bindGameControllerButton(i, InputAction::UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
Input::get()->bindGameControllerButton(i, InputType::DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN); Input::get()->bindGameControllerButton(i, InputAction::DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
Input::get()->bindGameControllerButton(i, InputType::LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT); Input::get()->bindGameControllerButton(i, InputAction::LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
Input::get()->bindGameControllerButton(i, InputType::RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); Input::get()->bindGameControllerButton(i, InputAction::RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
Input::get()->bindGameControllerButton(i, InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_X); Input::get()->bindGameControllerButton(i, InputAction::FIRE_LEFT, SDL_CONTROLLER_BUTTON_X);
Input::get()->bindGameControllerButton(i, InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_Y); Input::get()->bindGameControllerButton(i, InputAction::FIRE_CENTER, SDL_CONTROLLER_BUTTON_Y);
Input::get()->bindGameControllerButton(i, InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_B); Input::get()->bindGameControllerButton(i, InputAction::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_B);
Input::get()->bindGameControllerButton(i, InputType::START, SDL_CONTROLLER_BUTTON_START); Input::get()->bindGameControllerButton(i, InputAction::START, SDL_CONTROLLER_BUTTON_START);
// Mando - Control del programa // Mando - Control del programa
Input::get()->bindGameControllerButton(i, InputType::SERVICE, SDL_CONTROLLER_BUTTON_BACK); Input::get()->bindGameControllerButton(i, InputAction::SERVICE, SDL_CONTROLLER_BUTTON_BACK);
} }
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso // Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
const size_t max_controllers = std::min(2, num_gamepads); const size_t max_controllers = std::min(2, NUM_GAMEPADS);
for (size_t i = 0; i < max_controllers; ++i) for (size_t i = 0; i < max_controllers; ++i)
{ {
for (auto &controller : options.controllers) for (auto &controller : options.controllers)
@@ -234,16 +234,16 @@ void Director::bindInputs()
} }
// Asigna botones a inputs desde otros inputs // Asigna botones a inputs desde otros inputs
for (int i = 0; i < num_gamepads; ++i) for (int i = 0; i < NUM_GAMEPADS; ++i)
{ {
Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START); Input::get()->bindGameControllerButton(i, InputAction::EXIT, InputAction::START);
Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER); Input::get()->bindGameControllerButton(i, InputAction::RESET, InputAction::FIRE_CENTER);
Input::get()->bindGameControllerButton(i, InputType::PAUSE, InputType::FIRE_RIGHT); Input::get()->bindGameControllerButton(i, InputAction::PAUSE, InputAction::FIRE_RIGHT);
Input::get()->bindGameControllerButton(i, InputType::VIDEO_SHADERS, InputType::FIRE_LEFT); Input::get()->bindGameControllerButton(i, InputAction::VIDEO_SHADERS, InputAction::FIRE_LEFT);
Input::get()->bindGameControllerButton(i, InputType::MUTE, InputType::LEFT); Input::get()->bindGameControllerButton(i, InputAction::MUTE, InputAction::LEFT);
Input::get()->bindGameControllerButton(i, InputType::SHOWINFO, InputType::RIGHT); Input::get()->bindGameControllerButton(i, InputAction::SHOW_INFO, InputAction::RIGHT);
Input::get()->bindGameControllerButton(i, InputType::CONFIG, InputType::DOWN); Input::get()->bindGameControllerButton(i, InputAction::CONFIG, InputAction::DOWN);
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP); Input::get()->bindGameControllerButton(i, InputAction::SWAP_CONTROLLERS, InputAction::UP);
} }
// Guarda las asignaciones de botones en las opciones de los dos primeros mandos // Guarda las asignaciones de botones en las opciones de los dos primeros mandos

View File

@@ -17,7 +17,7 @@
#include "fade.h" // Para Fade, FadeType, FadeMode #include "fade.h" // Para Fade, FadeType, FadeMode
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check, update #include "global_inputs.h" // Para check, update
#include "input.h" // Para InputType, Input, INPUT_DO_NOT_ALL... #include "input.h" // Para InputAction, Input, INPUT_DO_NOT_ALL...
#include "item.h" // Para Item, ItemType #include "item.h" // Para Item, ItemType
#include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState #include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState
#include "lang.h" // Para getText #include "lang.h" // Para getText
@@ -1365,8 +1365,8 @@ void Game::checkPauseInput()
// Comprueba los mandos // Comprueba los mandos
for (int i = 0; i < input_->getNumControllers(); ++i) for (int i = 0; i < input_->getNumControllers(); ++i)
{ {
if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && if (input_->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{ {
pause(!paused_); pause(!paused_);
return; return;
@@ -1374,7 +1374,7 @@ void Game::checkPauseInput()
} }
// Comprueba el teclado // Comprueba el teclado
if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
pause(!paused_); pause(!paused_);
return; return;
@@ -1410,15 +1410,15 @@ void Game::handleDemoPlayerInput(const std::shared_ptr<Player> &player, int inde
if (demoData.left == 1) if (demoData.left == 1)
{ {
player->setInput(InputType::LEFT); player->setInput(InputAction::LEFT);
} }
else if (demoData.right == 1) else if (demoData.right == 1)
{ {
player->setInput(InputType::RIGHT); player->setInput(InputAction::RIGHT);
} }
else if (demoData.no_input == 1) else if (demoData.no_input == 1)
{ {
player->setInput(InputType::NONE); player->setInput(InputAction::NONE);
} }
if (demoData.fire == 1) if (demoData.fire == 1)
@@ -1440,8 +1440,8 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
{ {
if (player->canFire()) if (player->canFire())
{ {
player->setInput(bulletType == BulletType::UP ? InputType::FIRE_CENTER : bulletType == BulletType::LEFT ? InputType::FIRE_LEFT player->setInput(bulletType == BulletType::UP ? InputAction::FIRE_CENTER : bulletType == BulletType::LEFT ? InputAction::FIRE_LEFT
: InputType::FIRE_RIGHT); : InputAction::FIRE_RIGHT);
createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId()); createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
JA_PlaySound(Resource::get()->getSound("bullet.wav")); JA_PlaySound(Resource::get()->getSound("bullet.wav"));
@@ -1481,23 +1481,23 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
const auto &controller = options.controllers.at(player->getController()); const auto &controller = options.controllers.at(player->getController());
const bool autofire = player->isPowerUp() || options.game.autofire; const bool autofire = player->isPowerUp() || options.game.autofire;
if (input_->checkInput(InputType::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) if (input_->checkInput(InputAction::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index))
{ {
player->setInput(InputType::LEFT); player->setInput(InputAction::LEFT);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.left = 1; demo_.keys.left = 1;
#endif #endif
} }
else if (input_->checkInput(InputType::RIGHT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) else if (input_->checkInput(InputAction::RIGHT, INPUT_ALLOW_REPEAT, controller.type, controller.index))
{ {
player->setInput(InputType::RIGHT); player->setInput(InputAction::RIGHT);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.right = 1; demo_.keys.right = 1;
#endif #endif
} }
else else
{ {
player->setInput(InputType::NONE); player->setInput(InputAction::NONE);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.no_input = 1; demo_.keys.no_input = 1;
#endif #endif
@@ -1509,21 +1509,21 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado. // Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex) void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex)
{ {
if (input_->checkInput(InputType::FIRE_CENTER, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) if (input_->checkInput(InputAction::FIRE_CENTER, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
handleFireInput(player, BulletType::UP); handleFireInput(player, BulletType::UP);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.fire = 1; demo_.keys.fire = 1;
#endif #endif
} }
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) else if (input_->checkInput(InputAction::FIRE_LEFT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
handleFireInput(player, BulletType::LEFT); handleFireInput(player, BulletType::LEFT);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.fire_left = 1; demo_.keys.fire_left = 1;
#endif #endif
} }
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) else if (input_->checkInput(InputAction::FIRE_RIGHT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
handleFireInput(player, BulletType::RIGHT); handleFireInput(player, BulletType::RIGHT);
#ifdef RECORDING #ifdef RECORDING
@@ -1536,16 +1536,16 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
void Game::handlePlayerContinue(const std::shared_ptr<Player> &player) void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
{ {
const auto controllerIndex = player->getController(); const auto controllerIndex = player->getController();
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
player->setPlayingState(PlayerState::PLAYING); player->setPlayingState(PlayerState::PLAYING);
player->addCredit(); player->addCredit();
} }
// Disminuye el contador de continuación si se presiona cualquier botón de disparo. // Disminuye el contador de continuación si se presiona cualquier botón de disparo.
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) || if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) || input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
if (player->getContinueCounter() < 7) if (player->getContinueCounter() < 7)
{ {
@@ -1558,9 +1558,9 @@ void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
void Game::handleNameInput(const std::shared_ptr<Player> &player) void Game::handleNameInput(const std::shared_ptr<Player> &player)
{ {
const auto controllerIndex = player->getController(); const auto controllerIndex = player->getController();
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) || if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) || input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
if (player->isShowingName()) if (player->isShowingName())
{ {
@@ -1568,30 +1568,30 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
} }
else if (player->getEnterNamePositionOverflow()) else if (player->getEnterNamePositionOverflow())
{ {
player->setInput(InputType::START); player->setInput(InputAction::START);
addScoreToScoreBoard(player); addScoreToScoreBoard(player);
player->setPlayingState(PlayerState::SHOWING_NAME); player->setPlayingState(PlayerState::SHOWING_NAME);
} }
else else
{ {
player->setInput(InputType::RIGHT); player->setInput(InputAction::RIGHT);
} }
} }
else if (input_->checkInput(InputType::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) else if (input_->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
player->setInput(InputType::UP); player->setInput(InputAction::UP);
} }
else if (input_->checkInput(InputType::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) else if (input_->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
player->setInput(InputType::DOWN); player->setInput(InputAction::DOWN);
} }
else if (input_->checkInput(InputType::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) else if (input_->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
player->setInput(InputType::LEFT); player->setInput(InputAction::LEFT);
} }
else if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) else if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{ {
player->setInput(InputType::START); player->setInput(InputAction::START);
addScoreToScoreBoard(player); addScoreToScoreBoard(player);
player->setPlayingState(PlayerState::SHOWING_NAME); player->setPlayingState(PlayerState::SHOWING_NAME);
} }

View File

@@ -4,7 +4,7 @@
#include <string> // Para operator+, string, to_string, basic_string #include <string> // Para operator+, string, to_string, basic_string
#include <vector> // Para vector #include <vector> // Para vector
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "input.h" // Para Input, InputDeviceToUse, InputType, INP... #include "input.h" // Para Input, InputDeviceToUse, InputAction, INP...
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundVolume #include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundVolume
#include "lang.h" // Para getText, Code, getNextLangCode, loadFro... #include "lang.h" // Para getText, Code, getNextLangCode, loadFro...
#include "notifier.h" // Para Notifier #include "notifier.h" // Para Notifier
@@ -178,7 +178,7 @@ namespace globalInputs
// Teclado // Teclado
{ {
// Comprueba el teclado para cambiar entre pantalla completa y ventana // Comprueba el teclado para cambiar entre pantalla completa y ventana
if (Input::get()->checkInput(InputType::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
Screen::get()->toggleVideoMode(); Screen::get()->toggleVideoMode();
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? lang::getText(132) : lang::getText(133); const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? lang::getText(132) : lang::getText(133);
@@ -187,7 +187,7 @@ namespace globalInputs
} }
// Comprueba el teclado para decrementar el tamaño de la ventana // Comprueba el teclado para decrementar el tamaño de la ventana
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
if (Screen::get()->decWindowZoom()) if (Screen::get()->decWindowZoom())
{ {
@@ -197,7 +197,7 @@ namespace globalInputs
} }
// Comprueba el teclado para incrementar el tamaño de la ventana // Comprueba el teclado para incrementar el tamaño de la ventana
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
if (Screen::get()->incWindowZoom()) if (Screen::get()->incWindowZoom())
{ {
@@ -207,7 +207,7 @@ namespace globalInputs
} }
// Salir // Salir
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
quit(section::Options::QUIT_WITH_KEYBOARD); quit(section::Options::QUIT_WITH_KEYBOARD);
return; return;
@@ -221,41 +221,41 @@ namespace globalInputs
} }
// Reset // Reset
if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
reset(); reset();
return; return;
} }
// Audio // Audio
if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
toggleAudio(); toggleAudio();
return; return;
} }
// Autofire // Autofire
if (Input::get()->checkInput(InputType::AUTO_FIRE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::AUTO_FIRE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
toggleFireMode(); toggleFireMode();
return; return;
} }
// Idioma // Idioma
if (Input::get()->checkInput(InputType::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
changeLang(); changeLang();
return; return;
} }
// Shaders // Shaders
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
toggleShaders(); toggleShaders();
return; return;
} }
if (Input::get()->checkInput(InputType::VIDEO_INTEGER_SCALE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::VIDEO_INTEGER_SCALE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
toggleintegerScale(); toggleintegerScale();
return; return;
@@ -263,14 +263,14 @@ namespace globalInputs
#ifdef DEBUG #ifdef DEBUG
// Comprueba el teclado para mostrar la información de debug // Comprueba el teclado para mostrar la información de debug
if (Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
Screen::get()->toggleDebugInfo(); Screen::get()->toggleDebugInfo();
return; return;
} }
#endif #endif
// OnScreenHelp // OnScreenHelp
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {
service_pressed = true; service_pressed = true;
return; return;
@@ -282,47 +282,47 @@ namespace globalInputs
for (int i = 0; i < Input::get()->getNumControllers(); ++i) for (int i = 0; i < Input::get()->getNumControllers(); ++i)
{ {
// Salir // Salir
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) Input::get()->checkInput(InputAction::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{ {
quit(section::Options::QUIT_WITH_CONTROLLER); quit(section::Options::QUIT_WITH_CONTROLLER);
return; return;
} }
// Reset // Reset
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) Input::get()->checkInput(InputAction::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{ {
reset(); reset();
return; return;
} }
// Audio // Audio
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) Input::get()->checkInput(InputAction::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{ {
toggleAudio(); toggleAudio();
return; return;
} }
// Shaders // Shaders
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) Input::get()->checkInput(InputAction::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{ {
toggleShaders(); toggleShaders();
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
// Debug Info // Debug Info
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{ {
Screen::get()->toggleDebugInfo(); Screen::get()->toggleDebugInfo();
return; return;
} }
#endif #endif
// OnScreenHelp // OnScreenHelp
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{ {
service_pressed = true; service_pressed = true;
return; return;

View File

@@ -38,21 +38,21 @@ Input::Input(const std::string &game_controller_db_path)
discoverGameControllers(); discoverGameControllers();
// Inicializa los vectores // Inicializa los vectores
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), KeyBindings()); key_bindings_.resize(static_cast<int>(InputAction::SIZE), KeyBindings());
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputType::NUMBER_OF_INPUTS), ControllerBindings())); controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputAction::SIZE), ControllerBindings()));
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas // Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
button_inputs_ = {InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START}; button_inputs_ = {InputAction::FIRE_LEFT, InputAction::FIRE_CENTER, InputAction::FIRE_RIGHT, InputAction::START};
} }
// Asigna inputs a teclas // Asigna inputs a teclas
void Input::bindKey(InputType input, SDL_Scancode code) void Input::bindKey(InputAction input, SDL_Scancode code)
{ {
key_bindings_.at(static_cast<int>(input)).scancode = code; key_bindings_.at(static_cast<int>(input)).scancode = code;
} }
// Asigna inputs a botones del mando // Asigna inputs a botones del mando
void Input::bindGameControllerButton(int controller_index, InputType input, SDL_GameControllerButton button) void Input::bindGameControllerButton(int controller_index, InputAction input, SDL_GameControllerButton button)
{ {
if (controller_index < num_gamepads_) if (controller_index < num_gamepads_)
{ {
@@ -61,7 +61,7 @@ void Input::bindGameControllerButton(int controller_index, InputType input, SDL_
} }
// Asigna inputs a botones del mando // Asigna inputs a botones del mando
void Input::bindGameControllerButton(int controller_index, InputType input_target, InputType input_source) void Input::bindGameControllerButton(int controller_index, InputAction input_target, InputAction input_source)
{ {
if (controller_index < num_gamepads_) if (controller_index < num_gamepads_)
{ {
@@ -70,7 +70,7 @@ void Input::bindGameControllerButton(int controller_index, InputType input_targe
} }
// Comprueba si un input esta activo // Comprueba si un input esta activo
bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, int controller_index) bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device, int controller_index)
{ {
bool success_keyboard = false; bool success_keyboard = false;
bool success_controller = false; bool success_controller = false;
@@ -190,7 +190,7 @@ bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
int Input::checkAnyButtonPressed(bool repeat) int Input::checkAnyButtonPressed(bool repeat)
{ {
// Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado // Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::ANY)) if (checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::ANY))
{ {
return 0; return 0;
} }
@@ -335,7 +335,7 @@ void Input::printBindings(InputDeviceToUse device, int controller_index) const
} }
// Obtiene el SDL_GameControllerButton asignado a un input // Obtiene el SDL_GameControllerButton asignado a un input
SDL_GameControllerButton Input::getControllerBinding(int controller_index, InputType input) const SDL_GameControllerButton Input::getControllerBinding(int controller_index, InputAction input) const
{ {
return controller_bindings_[controller_index][static_cast<int>(input)].button; return controller_bindings_[controller_index][static_cast<int>(input)].button;
} }
@@ -347,42 +347,42 @@ int Input::getIndexByName(const std::string &name) const
return it != controller_names_.end() ? std::distance(controller_names_.begin(), it) : -1; return it != controller_names_.end() ? std::distance(controller_names_.begin(), it) : -1;
} }
// Convierte un InputType a std::string // Convierte un InputAction a std::string
std::string Input::to_string(InputType input) const std::string Input::to_string(InputAction input) const
{ {
switch (input) switch (input)
{ {
case InputType::FIRE_LEFT: case InputAction::FIRE_LEFT:
return "input_fire_left"; return "input_fire_left";
case InputType::FIRE_CENTER: case InputAction::FIRE_CENTER:
return "input_fire_center"; return "input_fire_center";
case InputType::FIRE_RIGHT: case InputAction::FIRE_RIGHT:
return "input_fire_right"; return "input_fire_right";
case InputType::START: case InputAction::START:
return "input_start"; return "input_start";
case InputType::SERVICE: case InputAction::SERVICE:
return "input_service"; return "input_service";
default: default:
return ""; return "";
} }
} }
// Convierte un std::string a InputType // Convierte un std::string a InputAction
InputType Input::to_inputs_e(const std::string &name) const InputAction Input::to_inputs_e(const std::string &name) const
{ {
static const std::unordered_map<std::string, InputType> inputMap = { static const std::unordered_map<std::string, InputAction> inputMap = {
{"input_fire_left", InputType::FIRE_LEFT}, {"input_fire_left", InputAction::FIRE_LEFT},
{"input_fire_center", InputType::FIRE_CENTER}, {"input_fire_center", InputAction::FIRE_CENTER},
{"input_fire_right", InputType::FIRE_RIGHT}, {"input_fire_right", InputAction::FIRE_RIGHT},
{"input_start", InputType::START}, {"input_start", InputAction::START},
{"input_service", InputType::SERVICE}}; {"input_service", InputAction::SERVICE}};
auto it = inputMap.find(name); auto it = inputMap.find(name);
return it != inputMap.end() ? it->second : InputType::NONE; return it != inputMap.end() ? it->second : InputAction::NONE;
} }
// Comprueba el eje del mando // Comprueba el eje del mando
bool Input::checkAxisInput(InputType input, int controller_index, bool repeat) bool Input::checkAxisInput(InputAction input, int controller_index, bool repeat)
{ {
// Umbral para considerar el eje como activo // Umbral para considerar el eje como activo
const Sint16 threshold = 30000; const Sint16 threshold = 30000;
@@ -390,16 +390,16 @@ bool Input::checkAxisInput(InputType input, int controller_index, bool repeat)
switch (input) switch (input)
{ {
case InputType::LEFT: case InputAction::LEFT:
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -threshold; axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -threshold;
break; break;
case InputType::RIGHT: case InputAction::RIGHT:
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > threshold; axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > threshold;
break; break;
case InputType::UP: case InputAction::UP:
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -threshold; axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -threshold;
break; break;
case InputType::DOWN: case InputAction::DOWN:
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > threshold; axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > threshold;
break; break;
default: default:

View File

@@ -16,7 +16,7 @@ device contiene el tipo de dispositivo a comprobar:
InputDeviceToUse::ANY mirará tanto el teclado como el PRIMER controlador InputDeviceToUse::ANY mirará tanto el teclado como el PRIMER controlador
*/ */
enum class InputType : int enum class InputAction : int
{ {
// Inputs de movimiento // Inputs de movimiento
UP, UP,
@@ -42,14 +42,14 @@ enum class InputType : int
RESET, RESET,
MUTE, MUTE,
CHANGE_LANG, CHANGE_LANG,
SHOWINFO, SHOW_INFO,
CONFIG, CONFIG,
SWAP_CONTROLLERS, SWAP_CONTROLLERS,
AUTO_FIRE, AUTO_FIRE,
// Input obligatorio // Input obligatorio
NONE, NONE,
NUMBER_OF_INPUTS, SIZE,
}; };
constexpr bool INPUT_ALLOW_REPEAT = true; constexpr bool INPUT_ALLOW_REPEAT = true;
@@ -95,13 +95,13 @@ private:
std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos 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::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<std::string> controller_names_; // Vector con los nombres de los mandos
std::vector<InputType> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones std::vector<InputAction> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones
int num_joysticks_ = 0; // Número de joysticks conectados int num_joysticks_ = 0; // Número de joysticks conectados
int num_gamepads_ = 0; // Número de mandos conectados int num_gamepads_ = 0; // Número de mandos conectados
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
// Comprueba el eje del mando // Comprueba el eje del mando
bool checkAxisInput(InputType input, int controller_index, bool repeat); bool checkAxisInput(InputAction input, int controller_index, bool repeat);
// Constructor // Constructor
explicit Input(const std::string &game_controller_db_path); explicit Input(const std::string &game_controller_db_path);
@@ -120,14 +120,14 @@ public:
static Input *get(); static Input *get();
// Asigna inputs a teclas // Asigna inputs a teclas
void bindKey(InputType input, SDL_Scancode code); void bindKey(InputAction input, SDL_Scancode code);
// Asigna inputs a botones del mando // Asigna inputs a botones del mando
void bindGameControllerButton(int controller_index, InputType input, SDL_GameControllerButton button); void bindGameControllerButton(int controller_index, InputAction input, SDL_GameControllerButton button);
void bindGameControllerButton(int controller_index, InputType inputTarget, InputType inputSource); void bindGameControllerButton(int controller_index, InputAction inputTarget, InputAction inputSource);
// Comprueba si un input esta activo // Comprueba si un input esta activo
bool checkInput(InputType input, bool repeat = true, InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0); bool checkInput(InputAction input, bool repeat = true, InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
// Comprueba si hay almenos un input activo // Comprueba si hay almenos un input activo
bool checkAnyInput(InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0); bool checkAnyInput(InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
@@ -154,13 +154,13 @@ public:
void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const; void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const;
// Obtiene el SDL_GameControllerButton asignado a un input // Obtiene el SDL_GameControllerButton asignado a un input
SDL_GameControllerButton getControllerBinding(int controller_index, InputType input) const; SDL_GameControllerButton getControllerBinding(int controller_index, InputAction input) const;
// Convierte un InputType a std::string // Convierte un InputAction a std::string
std::string to_string(InputType input) const; std::string to_string(InputAction input) const;
// Convierte un std::string a InputType // Convierte un std::string a InputAction
InputType to_inputs_e(const std::string &name) const; InputAction to_inputs_e(const std::string &name) const;
// Obtiene el indice a partir del nombre del mando // Obtiene el indice a partir del nombre del mando
int getIndexByName(const std::string &name) const; int getIndexByName(const std::string &name) const;

View File

@@ -4,7 +4,7 @@
#include <SDL2/SDL_stdinc.h> // Para Uint32 #include <SDL2/SDL_stdinc.h> // Para Uint32
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector
#include "input.h" // Para InputType, InputDeviceToUse #include "input.h" // Para InputAction, InputDeviceToUse
#include "manage_hiscore_table.h" // Para HiScoreEntry #include "manage_hiscore_table.h" // Para HiScoreEntry
enum class ScreenFilter : int; // lines 8-8 enum class ScreenFilter : int; // lines 8-8
enum class ScreenVideoMode : Uint32; // lines 9-9 enum class ScreenVideoMode : Uint32; // lines 9-9
@@ -87,13 +87,13 @@ struct OptionsController
InputDeviceToUse type; // Indica si se utilizará teclado o mando o ambos InputDeviceToUse type; // Indica si se utilizará teclado o mando o ambos
std::string name; // Nombre del dispositivo std::string name; // Nombre del dispositivo
bool plugged; // Indica si el mando se encuentra conectado bool plugged; // Indica si el mando se encuentra conectado
std::vector<InputType> inputs; // Listado de inputs std::vector<InputAction> inputs; // Listado de inputs
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
// Constructor por defecto // Constructor por defecto
OptionsController() OptionsController()
: index(-1), player_id(-1), type(InputDeviceToUse::CONTROLLER), name(""), plugged(false), : index(-1), player_id(-1), type(InputDeviceToUse::CONTROLLER), name(""), plugged(false),
inputs{InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START, InputType::SERVICE}, inputs{InputAction::FIRE_LEFT, InputAction::FIRE_CENTER, InputAction::FIRE_RIGHT, InputAction::START, InputAction::SERVICE},
buttons{SDL_CONTROLLER_BUTTON_X, SDL_CONTROLLER_BUTTON_Y, SDL_CONTROLLER_BUTTON_B, SDL_CONTROLLER_BUTTON_START, SDL_CONTROLLER_BUTTON_BACK} {} buttons{SDL_CONTROLLER_BUTTON_X, SDL_CONTROLLER_BUTTON_Y, SDL_CONTROLLER_BUTTON_B, SDL_CONTROLLER_BUTTON_START, SDL_CONTROLLER_BUTTON_BACK} {}
}; };

View File

@@ -4,7 +4,7 @@
#include <stdlib.h> // Para rand #include <stdlib.h> // Para rand
#include <algorithm> // Para clamp, max, min #include <algorithm> // Para clamp, max, min
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // Para AnimatedSprite
#include "input.h" // Para InputType #include "input.h" // Para InputAction
#include "param.h" // Para Param, ParamGame, param #include "param.h" // Para Param, ParamGame, param
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode #include "scoreboard.h" // Para Scoreboard, ScoreboardMode
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
@@ -70,7 +70,7 @@ void Player::init()
} }
// Actua en consecuencia de la entrada recibida // Actua en consecuencia de la entrada recibida
void Player::setInput(InputType input) void Player::setInput(InputAction input)
{ {
switch (playing_state_) switch (playing_state_)
{ {
@@ -91,33 +91,33 @@ void Player::setInput(InputType input)
} }
// Procesa inputs para cuando está jugando // Procesa inputs para cuando está jugando
void Player::setInputPlaying(InputType input) void Player::setInputPlaying(InputAction input)
{ {
switch (input) switch (input)
{ {
case InputType::LEFT: case InputAction::LEFT:
{ {
vel_x_ = -BASE_SPEED_; vel_x_ = -BASE_SPEED_;
setWalkingState(PlayerState::WALKING_LEFT); setWalkingState(PlayerState::WALKING_LEFT);
break; break;
} }
case InputType::RIGHT: case InputAction::RIGHT:
{ {
vel_x_ = BASE_SPEED_; vel_x_ = BASE_SPEED_;
setWalkingState(PlayerState::WALKING_RIGHT); setWalkingState(PlayerState::WALKING_RIGHT);
break; break;
} }
case InputType::FIRE_CENTER: case InputAction::FIRE_CENTER:
{ {
setFiringState(PlayerState::FIRING_UP); setFiringState(PlayerState::FIRING_UP);
break; break;
} }
case InputType::FIRE_LEFT: case InputAction::FIRE_LEFT:
{ {
setFiringState(PlayerState::FIRING_LEFT); setFiringState(PlayerState::FIRING_LEFT);
break; break;
} }
case InputType::FIRE_RIGHT: case InputAction::FIRE_RIGHT:
{ {
setFiringState(PlayerState::FIRING_RIGHT); setFiringState(PlayerState::FIRING_RIGHT);
break; break;
@@ -132,23 +132,23 @@ void Player::setInputPlaying(InputType input)
} }
// Procesa inputs para cuando está introduciendo el nombre // Procesa inputs para cuando está introduciendo el nombre
void Player::setInputEnteringName(InputType input) void Player::setInputEnteringName(InputAction input)
{ {
switch (input) switch (input)
{ {
case InputType::LEFT: case InputAction::LEFT:
enter_name_->decPosition(); enter_name_->decPosition();
break; break;
case InputType::RIGHT: case InputAction::RIGHT:
enter_name_->incPosition(); enter_name_->incPosition();
break; break;
case InputType::UP: case InputAction::UP:
enter_name_->incIndex(); enter_name_->incIndex();
break; break;
case InputType::DOWN: case InputAction::DOWN:
enter_name_->decIndex(); enter_name_->decIndex();
break; break;
case InputType::START: case InputAction::START:
last_enter_name_ = getRecordName(); last_enter_name_ = getRecordName();
if (last_enter_name_.empty()) if (last_enter_name_.empty())
{ {
@@ -227,10 +227,10 @@ void Player::move()
switch (id_) switch (id_)
{ {
case 1: case 1:
setInputPlaying(InputType::LEFT); setInputPlaying(InputAction::LEFT);
break; break;
case 2: case 2:
setInputPlaying(InputType::RIGHT); setInputPlaying(InputAction::RIGHT);
break; break;
default: default:
break; break;
@@ -258,7 +258,7 @@ void Player::move()
switch (id_) switch (id_)
{ {
case 1: case 1:
setInputPlaying(InputType::RIGHT); setInputPlaying(InputAction::RIGHT);
pos_x_ += vel_x_; pos_x_ += vel_x_;
if (pos_x_ > default_pos_x_) if (pos_x_ > default_pos_x_)
{ {
@@ -268,7 +268,7 @@ void Player::move()
} }
break; break;
case 2: case 2:
setInputPlaying(InputType::LEFT); setInputPlaying(InputAction::LEFT);
pos_x_ += vel_x_; pos_x_ += vel_x_;
if (pos_x_ < default_pos_x_) if (pos_x_ < default_pos_x_)
{ {
@@ -288,7 +288,7 @@ void Player::move()
pos_x_ += vel_x_ / 2.0f; pos_x_ += vel_x_ / 2.0f;
if (vel_x_ > 0) if (vel_x_ > 0)
{ {
// setInputPlaying(InputType::RIGHT); // setInputPlaying(InputAction::RIGHT);
if (pos_x_ > param.game.game_area.rect.w - WIDTH_) if (pos_x_ > param.game.game_area.rect.w - WIDTH_)
{ {
pos_x_ = param.game.game_area.rect.w - WIDTH_; pos_x_ = param.game.game_area.rect.w - WIDTH_;
@@ -297,7 +297,7 @@ void Player::move()
} }
else else
{ {
// setInputPlaying(InputType::LEFT); // setInputPlaying(InputAction::LEFT);
if (pos_x_ < param.game.game_area.rect.x) if (pos_x_ < param.game.game_area.rect.x)
{ {
pos_x_ = param.game.game_area.rect.x; pos_x_ = param.game.game_area.rect.x;

View File

@@ -11,7 +11,7 @@
#include "options.h" // Para Options, OptionsGame, options #include "options.h" // Para Options, OptionsGame, options
#include "utils.h" // Para Circle #include "utils.h" // Para Circle
class Texture; // lines 13-13 class Texture; // lines 13-13
enum class InputType : int; // lines 14-14 enum class InputAction : int; // lines 14-14
enum class ScoreboardMode; // lines 15-15 enum class ScoreboardMode; // lines 15-15
// Estados del jugador // Estados del jugador
@@ -152,13 +152,13 @@ public:
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture); void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture);
// Actua en consecuencia de la entrada recibida // Actua en consecuencia de la entrada recibida
void setInput(InputType input); void setInput(InputAction input);
// Procesa inputs para cuando está jugando // Procesa inputs para cuando está jugando
void setInputPlaying(InputType input); void setInputPlaying(InputAction input);
// Procesa inputs para cuando está introduciendo el nombre // Procesa inputs para cuando está introduciendo el nombre
void setInputEnteringName(InputType input); void setInputEnteringName(InputAction input);
// Mueve el jugador a la posición y animación que le corresponde // Mueve el jugador a la posición y animación que le corresponde
void move(); void move();
@@ -238,7 +238,7 @@ public:
int getScoreBoardPanel() const { return scoreboard_panel_; } int getScoreBoardPanel() const { return scoreboard_panel_; }
int getWidth() const { return WIDTH_; } int getWidth() const { return WIDTH_; }
PlayerState getPlayingState() const { return playing_state_; } PlayerState getPlayingState() const { return playing_state_; }
const std::string& getName() const { return name_; } const std::string &getName() const { return name_; }
bool get1CC() const { return game_completed_ && credits_used_ == 1; } bool get1CC() const { return game_completed_ && credits_used_ == 1; }
bool getEnterNamePositionOverflow() const { return enter_name_->getPositionOverflow(); } bool getEnterNamePositionOverflow() const { return enter_name_->getPositionOverflow(); }

View File

@@ -88,10 +88,10 @@ void Screen::renderScreen()
} }
// Establece el modo de video // Establece el modo de video
void Screen::setVideoMode(ScreenVideoMode video_mode) void Screen::setVideoMode(ScreenVideoMode mode)
{ {
// Actualiza las opciones // Actualiza las opciones
options.video.mode = video_mode; options.video.mode = mode;
// Configura el modo de pantalla // Configura el modo de pantalla
Uint32 flags = SDL_GetWindowFlags(window_); Uint32 flags = SDL_GetWindowFlags(window_);
@@ -316,17 +316,17 @@ void Screen::loadShaders()
{ {
const std::string GLSL_FILE = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl"; const std::string GLSL_FILE = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
std::ifstream f(Asset::get()->get(GLSL_FILE).c_str()); std::ifstream f(Asset::get()->get(GLSL_FILE).c_str());
shaderSource = std::string((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()); shader_source_ = std::string((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
} }
// Inicializa los shaders // Inicializa los shaders
void Screen::initShaders() void Screen::initShaders()
{ {
if (shaderSource.empty()) if (shader_source_.empty())
{ {
loadShaders(); loadShaders();
} }
shader::init(window_, game_canvas_, shaderSource); shader::init(window_, game_canvas_, shader_source_);
} }
// Calcula el tamaño de la ventana // Calcula el tamaño de la ventana

View File

@@ -44,7 +44,7 @@ private:
int fps_counter_ = 0; // Contador de frames por segundo int fps_counter_ = 0; // Contador de frames por segundo
int fps_ = 0; // Frames calculados en el último segundo int fps_ = 0; // Frames calculados en el último segundo
std::string info_resolution_; // Texto con la informacion de la pantalla std::string info_resolution_; // Texto con la informacion de la pantalla
std::string shaderSource; // Almacenar el contenido del archivo GLSL std::string shader_source_; // Almacena el contenido del archivo GLSL
#ifdef DEBUG #ifdef DEBUG
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
@@ -162,7 +162,7 @@ public:
void render(); void render();
// Establece el modo de video // Establece el modo de video
void setVideoMode(ScreenVideoMode video_mode = options.video.mode); void setVideoMode(ScreenVideoMode mode = options.video.mode);
// Cambia entre pantalla completa y ventana // Cambia entre pantalla completa y ventana
void toggleVideoMode(); void toggleVideoMode();

View File

@@ -9,7 +9,7 @@
#include "fade.h" // Para Fade, FadeType #include "fade.h" // Para Fade, FadeType
#include "game_logo.h" // Para GameLogo #include "game_logo.h" // Para GameLogo
#include "global_inputs.h" // Para check, update #include "global_inputs.h" // Para check, update
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_R... #include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_R...
#include "jail_audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_... #include "jail_audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_...
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "global_events.h" // Para handleEvent #include "global_events.h" // Para handleEvent
@@ -198,8 +198,8 @@ void Title::checkInput()
for (const auto &controller : options.controllers) for (const auto &controller : options.controllers)
{ {
// START // START
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index) && if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index) &&
!Input::get()->checkInput(InputType::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index)) !Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
{ {
if ((state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) && !fade_->isEnabled()) if ((state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) && !fade_->isEnabled())
{ {
@@ -224,16 +224,16 @@ void Title::checkInput()
} }
// SWAP_CONTROLLERS // SWAP_CONTROLLERS
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) && if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
Input::get()->checkInput(InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index)) Input::get()->checkInput(InputAction::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
{ {
swapControllers(); swapControllers();
return; return;
} }
// CONFIG // CONFIG
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) && if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
Input::get()->checkInput(InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index)) Input::get()->checkInput(InputAction::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
{ {
define_buttons_->enable(controller.index); define_buttons_->enable(controller.index);
return; return;