Input: mogudes structs, enums i consts a la part publica

This commit is contained in:
2025-07-30 08:53:57 +02:00
parent 677feb3afe
commit 989f081a25
14 changed files with 302 additions and 275 deletions

View File

@@ -51,12 +51,12 @@ void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event)
// Asigna los botones definidos al input_ // Asigna los botones definidos al input_
void DefineButtons::bindButtons() { void DefineButtons::bindButtons() {
for (const auto &button : buttons_) { for (const auto &button : buttons_) {
input_->bindGameControllerButton(index_controller_, button.input, button.button); input_->bindGameControllerButton(index_controller_, button.action, button.button);
} }
// Remapea los inputs a inputs // Remapea los inputs a inputs
input_->bindGameControllerButton(index_controller_, InputAction::SM_SELECT, InputAction::FIRE_LEFT); input_->bindGameControllerButton(index_controller_, Input::Action::SM_SELECT, Input::Action::FIRE_LEFT);
input_->bindGameControllerButton(index_controller_, InputAction::SM_BACK, InputAction::FIRE_CENTER); input_->bindGameControllerButton(index_controller_, Input::Action::SM_BACK, Input::Action::FIRE_CENTER);
} }
// Comprueba los eventos // Comprueba los eventos
@@ -117,11 +117,11 @@ auto DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) -> bool {
// Limpia la asignación de botones // Limpia la asignación de botones
void DefineButtons::clearButtons() { void DefineButtons::clearButtons() {
buttons_.clear(); buttons_.clear();
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_LEFT"), InputAction::FIRE_LEFT, SDL_GAMEPAD_BUTTON_INVALID); buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_LEFT"), Input::Action::FIRE_LEFT, SDL_GAMEPAD_BUTTON_INVALID);
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_UP"), InputAction::FIRE_CENTER, SDL_GAMEPAD_BUTTON_INVALID); buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_UP"), Input::Action::FIRE_CENTER, SDL_GAMEPAD_BUTTON_INVALID);
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_RIGHT"), InputAction::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_INVALID); buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_RIGHT"), Input::Action::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_INVALID);
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] START"), InputAction::START, SDL_GAMEPAD_BUTTON_INVALID); buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] START"), Input::Action::START, SDL_GAMEPAD_BUTTON_INVALID);
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] SERVICE_MENU"), InputAction::SERVICE, SDL_GAMEPAD_BUTTON_INVALID); buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] SERVICE_MENU"), Input::Action::SERVICE, SDL_GAMEPAD_BUTTON_INVALID);
} }
// Comprueba si ha finalizado // Comprueba si ha finalizado

View File

@@ -8,24 +8,22 @@
#include <utility> #include <utility>
#include <vector> // Para vector #include <vector> // Para vector
// Declaraciones adelantadas #include "input.h"
class Input; #include "text.h"
class Text;
enum class InputAction : int;
// Estructura para definir botones
struct DefineButtonsButton {
std::string label; // Texto en pantalla
InputAction input; // Acción asociada
SDL_GamepadButton button; // Botón del mando
DefineButtonsButton(std::string lbl, InputAction inp, SDL_GamepadButton btn)
: label(std::move(lbl)), input(inp), button(btn) {}
};
// Clase DefineButtons // Clase DefineButtons
class DefineButtons { class DefineButtons {
public: public:
// Estructura para definir botones
struct Button {
std::string label; // Texto en pantalla
Input::Action action; // Acción asociada
SDL_GamepadButton button; // Botón del mando
Button(std::string label, Input::Action action, SDL_GamepadButton button)
: label(std::move(label)), action(action), button(button) {}
};
DefineButtons(); DefineButtons();
~DefineButtons() = default; ~DefineButtons() = default;
@@ -42,7 +40,7 @@ class DefineButtons {
// Variables // Variables
bool enabled_ = false; // Indica si está activo bool enabled_ = false; // Indica si está activo
int x_ = 0, y_ = 0; // Coordenadas de texto int x_ = 0, y_ = 0; // Coordenadas de texto
std::vector<DefineButtonsButton> buttons_; // Definiciones de botones std::vector<Button> buttons_; // Definiciones de botones
size_t index_controller_ = 0; // Índice del controlador asignado size_t index_controller_ = 0; // Índice del controlador asignado
size_t index_button_ = 0; // Índice del botón en proceso size_t index_button_ = 0; // Índice del botón en proceso
std::vector<std::string> controller_names_; // Nombres de los mandos std::vector<std::string> controller_names_; // Nombres de los mandos

View File

@@ -150,60 +150,60 @@ void Director::loadScoreFile() {
// Asigna los botones y teclas al objeto Input // Asigna los botones y teclas al objeto Input
void Director::bindInputs() { void Director::bindInputs() {
// Teclado - Movimiento del jugador // Teclado - Movimiento del jugador
Input::get()->bindKey(InputAction::UP, SDL_SCANCODE_UP); Input::get()->bindKey(Input::Action::UP, SDL_SCANCODE_UP);
Input::get()->bindKey(InputAction::DOWN, SDL_SCANCODE_DOWN); Input::get()->bindKey(Input::Action::DOWN, SDL_SCANCODE_DOWN);
Input::get()->bindKey(InputAction::LEFT, SDL_SCANCODE_LEFT); Input::get()->bindKey(Input::Action::LEFT, SDL_SCANCODE_LEFT);
Input::get()->bindKey(InputAction::RIGHT, SDL_SCANCODE_RIGHT); Input::get()->bindKey(Input::Action::RIGHT, SDL_SCANCODE_RIGHT);
// Teclado - Disparo del jugador // Teclado - Disparo del jugador
Input::get()->bindKey(InputAction::FIRE_LEFT, SDL_SCANCODE_Q); Input::get()->bindKey(Input::Action::FIRE_LEFT, SDL_SCANCODE_Q);
Input::get()->bindKey(InputAction::FIRE_CENTER, SDL_SCANCODE_W); Input::get()->bindKey(Input::Action::FIRE_CENTER, SDL_SCANCODE_W);
Input::get()->bindKey(InputAction::FIRE_RIGHT, SDL_SCANCODE_E); Input::get()->bindKey(Input::Action::FIRE_RIGHT, SDL_SCANCODE_E);
// Teclado - Interfaz // Teclado - Interfaz
Input::get()->bindKey(InputAction::START, SDL_SCANCODE_RETURN); Input::get()->bindKey(Input::Action::START, SDL_SCANCODE_RETURN);
// Teclado - Menu de servicio // Teclado - Menu de servicio
Input::get()->bindKey(InputAction::SERVICE, SDL_SCANCODE_0); Input::get()->bindKey(Input::Action::SERVICE, SDL_SCANCODE_0);
Input::get()->bindKey(InputAction::SM_SELECT, SDL_SCANCODE_RETURN); Input::get()->bindKey(Input::Action::SM_SELECT, SDL_SCANCODE_RETURN);
Input::get()->bindKey(InputAction::SM_BACK, SDL_SCANCODE_BACKSPACE); Input::get()->bindKey(Input::Action::SM_BACK, SDL_SCANCODE_BACKSPACE);
// Teclado - Control del programa // Teclado - Control del programa
Input::get()->bindKey(InputAction::EXIT, SDL_SCANCODE_ESCAPE); Input::get()->bindKey(Input::Action::EXIT, SDL_SCANCODE_ESCAPE);
Input::get()->bindKey(InputAction::PAUSE, SDL_SCANCODE_P); Input::get()->bindKey(Input::Action::PAUSE, SDL_SCANCODE_P);
Input::get()->bindKey(InputAction::BACK, SDL_SCANCODE_BACKSPACE); Input::get()->bindKey(Input::Action::BACK, SDL_SCANCODE_BACKSPACE);
Input::get()->bindKey(InputAction::WINDOW_DEC_SIZE, SDL_SCANCODE_F1); Input::get()->bindKey(Input::Action::WINDOW_DEC_SIZE, SDL_SCANCODE_F1);
Input::get()->bindKey(InputAction::WINDOW_INC_SIZE, SDL_SCANCODE_F2); Input::get()->bindKey(Input::Action::WINDOW_INC_SIZE, SDL_SCANCODE_F2);
Input::get()->bindKey(InputAction::WINDOW_FULLSCREEN, SDL_SCANCODE_F3); Input::get()->bindKey(Input::Action::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
Input::get()->bindKey(InputAction::TOGGLE_VIDEO_SHADERS, SDL_SCANCODE_F4); Input::get()->bindKey(Input::Action::TOGGLE_VIDEO_SHADERS, SDL_SCANCODE_F4);
Input::get()->bindKey(InputAction::TOGGLE_VIDEO_INTEGER_SCALE, SDL_SCANCODE_F5); Input::get()->bindKey(Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, SDL_SCANCODE_F5);
Input::get()->bindKey(InputAction::TOGGLE_VIDEO_VSYNC, SDL_SCANCODE_F6); Input::get()->bindKey(Input::Action::TOGGLE_VIDEO_VSYNC, SDL_SCANCODE_F6);
Input::get()->bindKey(InputAction::TOGGLE_AUDIO, SDL_SCANCODE_F7); Input::get()->bindKey(Input::Action::TOGGLE_AUDIO, SDL_SCANCODE_F7);
Input::get()->bindKey(InputAction::TOGGLE_AUTO_FIRE, SDL_SCANCODE_F8); Input::get()->bindKey(Input::Action::TOGGLE_AUTO_FIRE, SDL_SCANCODE_F8);
Input::get()->bindKey(InputAction::CHANGE_LANG, SDL_SCANCODE_F9); Input::get()->bindKey(Input::Action::CHANGE_LANG, SDL_SCANCODE_F9);
Input::get()->bindKey(InputAction::RESET, SDL_SCANCODE_F10); Input::get()->bindKey(Input::Action::RESET, SDL_SCANCODE_F10);
Input::get()->bindKey(InputAction::SHOW_INFO, SDL_SCANCODE_F12); Input::get()->bindKey(Input::Action::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, InputAction::UP, SDL_GAMEPAD_BUTTON_DPAD_UP); Input::get()->bindGameControllerButton(i, Input::Action::UP, SDL_GAMEPAD_BUTTON_DPAD_UP);
Input::get()->bindGameControllerButton(i, InputAction::DOWN, SDL_GAMEPAD_BUTTON_DPAD_DOWN); Input::get()->bindGameControllerButton(i, Input::Action::DOWN, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
Input::get()->bindGameControllerButton(i, InputAction::LEFT, SDL_GAMEPAD_BUTTON_DPAD_LEFT); Input::get()->bindGameControllerButton(i, Input::Action::LEFT, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
Input::get()->bindGameControllerButton(i, InputAction::RIGHT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT); Input::get()->bindGameControllerButton(i, Input::Action::RIGHT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
// Mando - Disparo del jugador // Mando - Disparo del jugador
Input::get()->bindGameControllerButton(i, InputAction::FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST); Input::get()->bindGameControllerButton(i, Input::Action::FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST);
Input::get()->bindGameControllerButton(i, InputAction::FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH); Input::get()->bindGameControllerButton(i, Input::Action::FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH);
Input::get()->bindGameControllerButton(i, InputAction::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST); Input::get()->bindGameControllerButton(i, Input::Action::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST);
// Mando - Interfaz // Mando - Interfaz
Input::get()->bindGameControllerButton(i, InputAction::START, SDL_GAMEPAD_BUTTON_START); Input::get()->bindGameControllerButton(i, Input::Action::START, SDL_GAMEPAD_BUTTON_START);
Input::get()->bindGameControllerButton(i, InputAction::SERVICE, SDL_GAMEPAD_BUTTON_BACK); Input::get()->bindGameControllerButton(i, Input::Action::SERVICE, SDL_GAMEPAD_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
@@ -221,8 +221,8 @@ 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) {
// Mando - Menu de servicio // Mando - Menu de servicio
Input::get()->bindGameControllerButton(i, InputAction::SM_SELECT, InputAction::FIRE_LEFT); Input::get()->bindGameControllerButton(i, Input::Action::SM_SELECT, Input::Action::FIRE_LEFT);
Input::get()->bindGameControllerButton(i, InputAction::SM_BACK, InputAction::FIRE_CENTER); Input::get()->bindGameControllerButton(i, Input::Action::SM_BACK, Input::Action::FIRE_CENTER);
} }
// 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

@@ -5,6 +5,7 @@
#include "mouse.h" // Para handleEvent #include "mouse.h" // Para handleEvent
#include "screen.h" #include "screen.h"
#include "section.hpp" // Para Name, Options, name, options #include "section.hpp" // Para Name, Options, name, options
#include "input.h"
namespace GlobalEvents { namespace GlobalEvents {
// Comprueba los eventos que se pueden producir en cualquier sección del juego // Comprueba los eventos que se pueden producir en cualquier sección del juego
@@ -29,5 +30,8 @@ void check(const SDL_Event &event) {
} }
Mouse::handleEvent(event); Mouse::handleEvent(event);
static auto input = Input::get();
input->handleEvent(event);
} }
} // namespace GlobalEvents } // namespace GlobalEvents

View File

@@ -5,7 +5,7 @@
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "audio.h" // Para Audio #include "audio.h" // Para Audio
#include "input.h" // Para Input, INPUT_DO_NOT_ALLOW_REPEAT, InputAction, InputDevice #include "input.h" // Para Input, Input::DO_NOT_ALLOW_REPEAT, InputAction, InputDevice
#include "lang.h" // Para getText, Code, getNextLangCode, loadFromFile #include "lang.h" // Para getText, Code, getNextLangCode, loadFromFile
#include "options.h" // Para SettingsOptions, settings, VideoOptions, WindowOptions, video, window, AudioOptions, audio #include "options.h" // Para SettingsOptions, settings, VideoOptions, WindowOptions, video, window, AudioOptions, audio
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
@@ -163,7 +163,7 @@ void incWindowSize() {
// Comprueba el boton de servicio // Comprueba el boton de servicio
auto checkServiceButton() -> bool { auto checkServiceButton() -> bool {
// Teclado // Teclado
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
toggleServiceMenu(); toggleServiceMenu();
return true; return true;
} }
@@ -171,7 +171,7 @@ auto checkServiceButton() -> bool {
// Mandos // Mandos
{ {
for (int i = 0; i < Input::get()->getNumControllers(); ++i) { for (int i = 0; i < Input::get()->getNumControllers(); ++i) {
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { if (Input::get()->checkInput(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
toggleServiceMenu(); toggleServiceMenu();
return true; return true;
} }
@@ -189,37 +189,37 @@ auto checkServiceInputs() -> bool {
// Teclado // Teclado
{ {
// Arriba // Arriba
if (Input::get()->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
ServiceMenu::get()->setSelectorUp(); ServiceMenu::get()->setSelectorUp();
return true; return true;
} }
// Abajo // Abajo
if (Input::get()->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
ServiceMenu::get()->setSelectorDown(); ServiceMenu::get()->setSelectorDown();
return true; return true;
} }
// Derecha // Derecha
if (Input::get()->checkInput(InputAction::RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
ServiceMenu::get()->adjustOption(true); ServiceMenu::get()->adjustOption(true);
return true; return true;
} }
// Izquierda // Izquierda
if (Input::get()->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
ServiceMenu::get()->adjustOption(false); ServiceMenu::get()->adjustOption(false);
return true; return true;
} }
// Aceptar // Aceptar
if (Input::get()->checkInput(InputAction::SM_SELECT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
ServiceMenu::get()->selectOption(); ServiceMenu::get()->selectOption();
return true; return true;
} }
// Atras // Atras
if (Input::get()->checkInput(InputAction::SM_BACK, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
ServiceMenu::get()->moveBack(); ServiceMenu::get()->moveBack();
return true; return true;
} }
@@ -229,37 +229,37 @@ auto checkServiceInputs() -> bool {
{ {
for (int i = 0; i < Input::get()->getNumControllers(); ++i) { for (int i = 0; i < Input::get()->getNumControllers(); ++i) {
// Arriba // Arriba
if (Input::get()->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { if (Input::get()->checkInput(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
ServiceMenu::get()->setSelectorUp(); ServiceMenu::get()->setSelectorUp();
return true; return true;
} }
// Abajo // Abajo
if (Input::get()->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { if (Input::get()->checkInput(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
ServiceMenu::get()->setSelectorDown(); ServiceMenu::get()->setSelectorDown();
return true; return true;
} }
// Derecha // Derecha
if (Input::get()->checkInput(InputAction::RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { if (Input::get()->checkInput(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
ServiceMenu::get()->adjustOption(true); ServiceMenu::get()->adjustOption(true);
return true; return true;
} }
// Izquierda // Izquierda
if (Input::get()->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { if (Input::get()->checkInput(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
ServiceMenu::get()->adjustOption(false); ServiceMenu::get()->adjustOption(false);
return true; return true;
} }
// Aceptar // Aceptar
if (Input::get()->checkInput(InputAction::SM_SELECT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { if (Input::get()->checkInput(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
ServiceMenu::get()->selectOption(); ServiceMenu::get()->selectOption();
return true; return true;
} }
// Atras // Atras
if (Input::get()->checkInput(InputAction::SM_BACK, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { if (Input::get()->checkInput(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
ServiceMenu::get()->moveBack(); ServiceMenu::get()->moveBack();
return true; return true;
} }
@@ -273,7 +273,7 @@ auto checkInputs() -> bool {
// 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(InputAction::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::WINDOW_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
Screen::get()->toggleFullscreen(); Screen::get()->toggleFullscreen();
const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10"); const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10");
Notifier::get()->show({MODE}); Notifier::get()->show({MODE});
@@ -281,7 +281,7 @@ auto checkInputs() -> bool {
} }
// 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(InputAction::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::WINDOW_DEC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
if (Screen::get()->decWindowSize()) { if (Screen::get()->decWindowSize()) {
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)}); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
} }
@@ -289,7 +289,7 @@ auto checkInputs() -> bool {
} }
// 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(InputAction::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::WINDOW_INC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
if (Screen::get()->incWindowSize()) { if (Screen::get()->incWindowSize()) {
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)}); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
} }
@@ -297,7 +297,7 @@ auto checkInputs() -> bool {
} }
// Salir // Salir
if (Input::get()->checkInput(InputAction::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::EXIT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
quit(); quit();
return true; return true;
} }
@@ -309,50 +309,50 @@ auto checkInputs() -> bool {
} }
// Reset // Reset
if (Input::get()->checkInput(InputAction::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::RESET, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
reset(); reset();
return true; return true;
} }
// Audio // Audio
if (Input::get()->checkInput(InputAction::TOGGLE_AUDIO, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::TOGGLE_AUDIO, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
toggleAudio(); toggleAudio();
return true; return true;
} }
// Autofire // Autofire
if (Input::get()->checkInput(InputAction::TOGGLE_AUTO_FIRE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::TOGGLE_AUTO_FIRE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
toggleFireMode(); toggleFireMode();
return true; return true;
} }
// Idioma // Idioma
if (Input::get()->checkInput(InputAction::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::CHANGE_LANG, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
changeLang(); changeLang();
return true; return true;
} }
// Shaders // Shaders
if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::TOGGLE_VIDEO_SHADERS, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
toggleShaders(); toggleShaders();
return true; return true;
} }
// Integer Scale // Integer Scale
if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_INTEGER_SCALE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
toggleIntegerScale(); toggleIntegerScale();
return true; return true;
} }
// VSync // VSync
if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_VSYNC, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::TOGGLE_VIDEO_VSYNC, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
toggleVSync(); toggleVSync();
return true; return true;
} }
#ifdef _DEBUG #ifdef _DEBUG
// Debug info // Debug info
if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(Input::Action::SHOW_INFO, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
Screen::get()->toggleDebugInfo(); Screen::get()->toggleDebugInfo();
return true; return true;
} }

View File

@@ -27,39 +27,39 @@ Input::Input(std::string game_controller_db_path)
initSDLGamePad(); initSDLGamePad();
// Inicializa los vectores // Inicializa los vectores
key_bindings_.resize(static_cast<int>(InputAction::SIZE), KeyBindings()); key_bindings_.resize(static_cast<int>(Action::SIZE), KeyBindings());
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputAction::SIZE), ControllerBindings())); controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(Action::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_ = {InputAction::FIRE_LEFT, InputAction::FIRE_CENTER, InputAction::FIRE_RIGHT, InputAction::START}; button_inputs_ = {Action::FIRE_LEFT, Action::FIRE_CENTER, Action::FIRE_RIGHT, Action::START};
} }
// Asigna inputs a teclas // Asigna inputs a teclas
void Input::bindKey(InputAction input, SDL_Scancode code) { void Input::bindKey(Action 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, InputAction input, SDL_GamepadButton button) { void Input::bindGameControllerButton(int controller_index, Action input, SDL_GamepadButton button) {
if (controller_index < num_gamepads_) { if (controller_index < num_gamepads_) {
controller_bindings_.at(controller_index).at(static_cast<int>(input)).button = button; controller_bindings_.at(controller_index).at(static_cast<int>(input)).button = button;
} }
} }
// Asigna inputs a botones del mando // Asigna inputs a botones del mando
void Input::bindGameControllerButton(int controller_index, InputAction input_target, InputAction input_source) { void Input::bindGameControllerButton(int controller_index, Action input_target, Action input_source) {
if (controller_index < num_gamepads_) { if (controller_index < num_gamepads_) {
controller_bindings_.at(controller_index).at(static_cast<int>(input_target)).button = controller_bindings_.at(controller_index).at(static_cast<int>(input_source)).button; controller_bindings_.at(controller_index).at(static_cast<int>(input_target)).button = controller_bindings_.at(controller_index).at(static_cast<int>(input_source)).button;
} }
} }
// Comprueba si un input esta activo // Comprueba si un input esta activo
auto Input::checkInput(InputAction input, bool repeat, InputDevice device, int controller_index) -> bool { auto Input::checkInput(Action input, bool repeat, Device device, int controller_index) -> bool {
bool success_keyboard = false; bool success_keyboard = false;
bool success_controller = false; bool success_controller = false;
const int INPUT_INDEX = static_cast<int>(input); const int INPUT_INDEX = static_cast<int>(input);
if (device == InputDevice::KEYBOARD || device == InputDevice::ANY) { if (device == Device::KEYBOARD || device == Device::ANY) {
if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido) if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido)
success_keyboard = key_bindings_[INPUT_INDEX].is_held; success_keyboard = key_bindings_[INPUT_INDEX].is_held;
} else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma) } else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma)
@@ -68,7 +68,7 @@ auto Input::checkInput(InputAction input, bool repeat, InputDevice device, int c
} }
if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_) { if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_) {
if ((device == InputDevice::CONTROLLER) || (device == InputDevice::ANY)) { if ((device == Device::CONTROLLER) || (device == Device::ANY)) {
success_controller = checkAxisInput(input, controller_index, repeat); success_controller = checkAxisInput(input, controller_index, repeat);
if (!success_controller) { if (!success_controller) {
@@ -85,12 +85,12 @@ auto Input::checkInput(InputAction input, bool repeat, InputDevice device, int c
} }
// Comprueba si hay almenos un input activo // Comprueba si hay almenos un input activo
auto Input::checkAnyInput(InputDevice device, int controller_index) -> bool { auto Input::checkAnyInput(Device device, int controller_index) -> bool {
// Obtenemos el número total de acciones posibles para iterar sobre ellas. // Obtenemos el número total de acciones posibles para iterar sobre ellas.
const int NUM_ACTIONS = static_cast<int>(InputAction::SIZE); const int NUM_ACTIONS = static_cast<int>(Action::SIZE);
// --- Comprobación del Teclado --- // --- Comprobación del Teclado ---
if (device == InputDevice::KEYBOARD || device == InputDevice::ANY) { if (device == Device::KEYBOARD || device == Device::ANY) {
for (int i = 0; i < NUM_ACTIONS; ++i) { for (int i = 0; i < NUM_ACTIONS; ++i) {
// Simplemente leemos el estado pre-calculado por Input::update(). // Simplemente leemos el estado pre-calculado por Input::update().
// Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'. // Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'.
@@ -103,7 +103,7 @@ auto Input::checkAnyInput(InputDevice device, int controller_index) -> bool {
// --- Comprobación del Mando --- // --- Comprobación del Mando ---
// Comprobamos si hay mandos y si el índice solicitado es válido. // Comprobamos si hay mandos y si el índice solicitado es válido.
if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_) { if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_) {
if (device == InputDevice::CONTROLLER || device == InputDevice::ANY) { if (device == Device::CONTROLLER || device == Device::ANY) {
// Bucle CORREGIDO: Iteramos sobre todas las acciones, no sobre el número de mandos. // Bucle CORREGIDO: Iteramos sobre todas las acciones, no sobre el número de mandos.
for (int i = 0; i < NUM_ACTIONS; ++i) { for (int i = 0; i < NUM_ACTIONS; ++i) {
// Leemos el estado pre-calculado para el mando y la acción específicos. // Leemos el estado pre-calculado para el mando y la acción específicos.
@@ -123,13 +123,13 @@ auto Input::checkAnyButton(bool repeat) -> int {
// Solo comprueba los botones definidos previamente // Solo comprueba los botones definidos previamente
for (auto bi : button_inputs_) { for (auto bi : button_inputs_) {
// Comprueba el teclado // Comprueba el teclado
if (checkInput(bi, repeat, InputDevice::KEYBOARD)) { if (checkInput(bi, repeat, Device::KEYBOARD)) {
return 1; return 1;
} }
// Comprueba los mandos // Comprueba los mandos
for (int i = 0; i < num_gamepads_; ++i) { for (int i = 0; i < num_gamepads_; ++i) {
if (checkInput(bi, repeat, InputDevice::CONTROLLER, i)) { if (checkInput(bi, repeat, Device::CONTROLLER, i)) {
return i + 1; return i + 1;
} }
} }
@@ -226,12 +226,12 @@ auto Input::getJoyIndex(SDL_JoystickID id) const -> int {
} }
// Muestra por consola los controles asignados // Muestra por consola los controles asignados
void Input::printBindings(InputDevice device, int controller_index) const { void Input::printBindings(Device device, int controller_index) const {
if (device == InputDevice::ANY || device == InputDevice::KEYBOARD) { if (device == Device::ANY || device == Device::KEYBOARD) {
return; return;
} }
if (device == InputDevice::CONTROLLER) { if (device == Device::CONTROLLER) {
if (controller_index >= num_gamepads_) { if (controller_index >= num_gamepads_) {
return; return;
} }
@@ -247,7 +247,7 @@ void Input::printBindings(InputDevice device, int controller_index) const {
} }
// Obtiene el SDL_GamepadButton asignado a un input // Obtiene el SDL_GamepadButton asignado a un input
auto Input::getControllerBinding(int controller_index, InputAction input) const -> SDL_GamepadButton { auto Input::getControllerBinding(int controller_index, Action input) const -> SDL_GamepadButton {
return controller_bindings_[controller_index][static_cast<int>(input)].button; return controller_bindings_[controller_index][static_cast<int>(input)].button;
} }
@@ -258,17 +258,17 @@ auto Input::getIndexByName(const std::string &name) const -> int {
} }
// Convierte un InputAction a std::string // Convierte un InputAction a std::string
auto Input::inputToString(InputAction input) -> std::string { auto Input::inputToString(Action input) -> std::string {
switch (input) { switch (input) {
case InputAction::FIRE_LEFT: case Action::FIRE_LEFT:
return "input_fire_left"; return "input_fire_left";
case InputAction::FIRE_CENTER: case Action::FIRE_CENTER:
return "input_fire_center"; return "input_fire_center";
case InputAction::FIRE_RIGHT: case Action::FIRE_RIGHT:
return "input_fire_right"; return "input_fire_right";
case InputAction::START: case Action::START:
return "input_start"; return "input_start";
case InputAction::SERVICE: case Action::SERVICE:
return "input_service"; return "input_service";
default: default:
return ""; return "";
@@ -276,34 +276,34 @@ auto Input::inputToString(InputAction input) -> std::string {
} }
// Convierte un std::string a InputAction // Convierte un std::string a InputAction
auto Input::stringToInput(const std::string &name) -> InputAction { auto Input::stringToInput(const std::string &name) -> Action {
static const std::unordered_map<std::string, InputAction> INPUT_MAP = { static const std::unordered_map<std::string, Action> INPUT_MAP = {
{"input_fire_left", InputAction::FIRE_LEFT}, {"input_fire_left", Action::FIRE_LEFT},
{"input_fire_center", InputAction::FIRE_CENTER}, {"input_fire_center", Action::FIRE_CENTER},
{"input_fire_right", InputAction::FIRE_RIGHT}, {"input_fire_right", Action::FIRE_RIGHT},
{"input_start", InputAction::START}, {"input_start", Action::START},
{"input_service", InputAction::SERVICE}}; {"input_service", Action::SERVICE}};
auto it = INPUT_MAP.find(name); auto it = INPUT_MAP.find(name);
return it != INPUT_MAP.end() ? it->second : InputAction::NONE; return it != INPUT_MAP.end() ? it->second : Action::NONE;
} }
// Comprueba el eje del mando // Comprueba el eje del mando
auto Input::checkAxisInput(InputAction input, int controller_index, bool repeat) -> bool { auto Input::checkAxisInput(Action input, int controller_index, bool repeat) -> bool {
// Umbral para considerar el eje como activo // Umbral para considerar el eje como activo
bool axis_active_now = false; bool axis_active_now = false;
switch (input) { switch (input) {
case InputAction::LEFT: case Action::LEFT:
axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) < -AXIS_THRESHOLD; axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) < -AXIS_THRESHOLD;
break; break;
case InputAction::RIGHT: case Action::RIGHT:
axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) > AXIS_THRESHOLD; axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) > AXIS_THRESHOLD;
break; break;
case InputAction::UP: case Action::UP:
axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) < -AXIS_THRESHOLD; axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) < -AXIS_THRESHOLD;
break; break;
case InputAction::DOWN: case Action::DOWN:
axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) > AXIS_THRESHOLD; axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) > AXIS_THRESHOLD;
break; break;
default: default:
@@ -380,3 +380,24 @@ void Input::update() {
} }
} }
} }
void Input::handleEvent(const SDL_Event &event) {
switch (event.type) {
case SDL_EVENT_GAMEPAD_ADDED: {
printf("¡Mando conectado! ID: %d\n", event.gdevice.which);
SDL_Gamepad *gamepad = SDL_OpenGamepad(event.gdevice.which);
if (gamepad) {
printf("Gamepad abierto correctamente.\n");
} else {
printf("Error al abrir el gamepad: %s\n", SDL_GetError());
}
break;
}
case SDL_EVENT_GAMEPAD_REMOVED: {
printf("¡Mando desconectado! Instance ID: %d\n", event.gdevice.which);
// Aquí puedes cerrar el gamepad si lo tenías abierto
// SDL_CloseGamepad(gamepad); ← si tienes el puntero guardado
break;
}
}
}

View File

@@ -14,8 +14,15 @@ 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
*/ */
// Acciones de entrada posibles en el juego // Clase Input: gestiona la entrada de teclado y mandos (singleton)
enum class InputAction : int { class Input {
public:
// --- Constantes ---
static constexpr bool ALLOW_REPEAT = true;
static constexpr bool DO_NOT_ALLOW_REPEAT = false;
// Acciones de entrada posibles en el juego
enum class Action : int {
// Inputs de movimiento // Inputs de movimiento
UP, UP,
DOWN, DOWN,
@@ -54,36 +61,30 @@ enum class InputAction : int {
// Input obligatorio // Input obligatorio
NONE, NONE,
SIZE, SIZE,
}; };
constexpr bool INPUT_ALLOW_REPEAT = true; // Tipos de dispositivos de entrada
constexpr bool INPUT_DO_NOT_ALLOW_REPEAT = false; enum class Device : int {
// Tipos de dispositivos de entrada
enum class InputDevice : int {
KEYBOARD = 0, KEYBOARD = 0,
CONTROLLER = 1, CONTROLLER = 1,
ANY = 2, ANY = 2,
}; };
// Clase Input: gestiona la entrada de teclado y mandos (singleton)
class Input {
public:
// --- Métodos de singleton --- // --- Métodos de singleton ---
static void init(const std::string &game_controller_db_path); // Inicializa el singleton static void init(const std::string &game_controller_db_path); // Inicializa el singleton
static void destroy(); // Libera el singleton static void destroy(); // Libera el singleton
static auto get() -> Input *; // Obtiene la instancia static auto get() -> Input *; // Obtiene la instancia
// --- Métodos de configuración de controles --- // --- Métodos de configuración de controles ---
void bindKey(InputAction input, SDL_Scancode code); // Asigna inputs a teclas void bindKey(Action input, SDL_Scancode code); // Asigna inputs a teclas
void bindGameControllerButton(int controller_index, InputAction input, SDL_GamepadButton button); // Asigna inputs a botones del mando void bindGameControllerButton(int controller_index, Action input, SDL_GamepadButton button); // Asigna inputs a botones del mando
void bindGameControllerButton(int controller_index, InputAction input_target, InputAction input_source); // Asigna inputs a otros inputs del mando void bindGameControllerButton(int controller_index, Action input_target, Action input_source); // Asigna inputs a otros inputs del mando
// --- Métodos de consulta de entrada --- // --- Métodos de consulta de entrada ---
void update(); // Comprueba fisicamente los botones y teclas que se han pulsado void update(); // Comprueba fisicamente los botones y teclas que se han pulsado
auto checkInput(InputAction input, bool repeat = true, InputDevice device = InputDevice::ANY, int controller_index = 0) -> bool; // Comprueba si un input está activo auto checkInput(Action input, bool repeat = true, Device device = Device::ANY, int controller_index = 0) -> bool; // Comprueba si un input está activo
auto checkAnyInput(InputDevice device = InputDevice::ANY, int controller_index = 0) -> bool; // Comprueba si hay al menos un input activo auto checkAnyInput(Device device = Device::ANY, int controller_index = 0) -> bool; // Comprueba si hay al menos un input activo
auto checkAnyButton(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT) -> int; // Comprueba si hay algún botón pulsado auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> int; // Comprueba si hay algún botón pulsado
// --- Métodos de gestión de mandos --- // --- Métodos de gestión de mandos ---
auto discoverGameControllers() -> bool; // Busca si hay mandos conectados auto discoverGameControllers() -> bool; // Busca si hay mandos conectados
@@ -93,15 +94,18 @@ class Input {
[[nodiscard]] auto getJoyIndex(SDL_JoystickID id) const -> int; // Obtiene el índice del controlador a partir de un event.id [[nodiscard]] auto getJoyIndex(SDL_JoystickID id) const -> int; // Obtiene el índice del controlador a partir de un event.id
// --- Métodos de consulta y utilidades --- // --- Métodos de consulta y utilidades ---
void printBindings(InputDevice device = InputDevice::KEYBOARD, int controller_index = 0) const; // Muestra por consola los controles asignados void printBindings(Device device = Device::KEYBOARD, int controller_index = 0) const; // Muestra por consola los controles asignados
[[nodiscard]] auto getControllerBinding(int controller_index, InputAction input) const -> SDL_GamepadButton; // Obtiene el SDL_GamepadButton asignado a un input [[nodiscard]] auto getControllerBinding(int controller_index, Action input) const -> SDL_GamepadButton; // Obtiene el SDL_GamepadButton asignado a un input
[[nodiscard]] static auto inputToString(InputAction input) -> std::string; // Convierte un InputAction a std::string [[nodiscard]] static auto inputToString(Action input) -> std::string; // Convierte un InputAction a std::string
[[nodiscard]] static auto stringToInput(const std::string &name) -> InputAction; // Convierte un std::string a InputAction [[nodiscard]] static auto stringToInput(const std::string &name) -> Action; // Convierte un std::string a InputAction
[[nodiscard]] auto getIndexByName(const std::string &name) const -> int; // Obtiene el índice a partir del nombre del mando [[nodiscard]] auto getIndexByName(const std::string &name) const -> int; // Obtiene el índice a partir del nombre del mando
// --- Métodos de reseteo de estado de entrada --- // --- Métodos de reseteo de estado de entrada ---
void resetInputStates(); // Pone todos los KeyBindings.active y ControllerBindings.active a false void resetInputStates(); // Pone todos los KeyBindings.active y ControllerBindings.active a false
// --- Eventos ---
void handleEvent(const SDL_Event &event); // Comprueba si se conecta algun mando
private: private:
// --- Estructuras internas --- // --- Estructuras internas ---
struct KeyBindings { struct KeyBindings {
@@ -132,14 +136,14 @@ class Input {
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 asociados a los inputs predefinidos para cada mando std::vector<std::vector<ControllerBindings>> controller_bindings_; // Vector con los botones asociados 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<InputAction> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones std::vector<Action> 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
// --- Métodos internos --- // --- Métodos internos ---
void initSDLGamePad(); // Inicializa SDL para la gestión de mandos void initSDLGamePad(); // Inicializa SDL para la gestión de mandos
auto checkAxisInput(InputAction input, int controller_index, bool repeat) -> bool; // Comprueba el eje del mando auto checkAxisInput(Action input, int controller_index, bool repeat) -> bool; // Comprueba el eje del mando
// --- Constructor y destructor --- // --- Constructor y destructor ---
explicit Input(std::string game_controller_db_path); // Constructor privado explicit Input(std::string game_controller_db_path); // Constructor privado

View File

@@ -189,7 +189,7 @@ void parseAndSetController(const std::string& var, const std::string& value) {
} else if (setting_key == "player") { } else if (setting_key == "player") {
controller.player_id = std::clamp(std::stoi(value), 1, 2); controller.player_id = std::clamp(std::stoi(value), 1, 2);
} else if (setting_key == "type") { } else if (setting_key == "type") {
controller.type = static_cast<InputDevice>(std::stoi(value)); controller.type = static_cast<Input::Device>(std::stoi(value));
} else if (setting_key == "button.fire_left") { } else if (setting_key == "button.fire_left") {
controller.buttons.at(0) = static_cast<SDL_GamepadButton>(std::stoi(value)); controller.buttons.at(0) = static_cast<SDL_GamepadButton>(std::stoi(value));
} else if (setting_key == "button.fire_center") { } else if (setting_key == "button.fire_center") {
@@ -272,9 +272,9 @@ auto set(const std::string& var, const std::string& value) -> bool {
void setKeyboardToPlayer(int player_id) { void setKeyboardToPlayer(int player_id) {
for (auto& controller : controllers) { for (auto& controller : controllers) {
if (controller.player_id == player_id) { if (controller.player_id == player_id) {
controller.type = InputDevice::ANY; controller.type = Input::Device::ANY;
} else { } else {
controller.type = InputDevice::CONTROLLER; controller.type = Input::Device::CONTROLLER;
} }
} }
} }
@@ -293,7 +293,7 @@ void swapControllers() {
// Averigua quien está usando el teclado // Averigua quien está usando el teclado
auto getPlayerWhoUsesKeyboard() -> int { auto getPlayerWhoUsesKeyboard() -> int {
for (const auto& controller : controllers) { for (const auto& controller : controllers) {
if (controller.type == InputDevice::ANY) { if (controller.type == Input::Device::ANY) {
return controller.player_id; return controller.player_id;
} }
} }

View File

@@ -92,10 +92,10 @@ struct SettingsOptions {
struct GamepadOptions { struct GamepadOptions {
int index; // Índice en el vector de mandos int index; // Índice en el vector de mandos
int player_id; // Jugador asociado al mando int player_id; // Jugador asociado al mando
InputDevice type{InputDevice::CONTROLLER}; // Indica si se usará teclado, mando o ambos Input::Device type{Input::Device::CONTROLLER}; // Indica si se usará teclado, mando o ambos
std::string name; // Nombre del dispositivo std::string name; // Nombre del dispositivo
bool plugged{false}; // Indica si el mando está conectado bool plugged{false}; // Indica si el mando está conectado
std::vector<InputAction> inputs; // Listado de acciones asignadas std::vector<Input::Action> inputs; // Listado de acciones asignadas
std::vector<SDL_GamepadButton> buttons; // Listado de botones asignados a cada acción std::vector<SDL_GamepadButton> buttons; // Listado de botones asignados a cada acción
// Constructor por defecto // Constructor por defecto
@@ -103,11 +103,11 @@ struct GamepadOptions {
: index(INVALID_INDEX), : index(INVALID_INDEX),
player_id(INVALID_INDEX), player_id(INVALID_INDEX),
inputs{ inputs{
InputAction::FIRE_LEFT, Input::Action::FIRE_LEFT,
InputAction::FIRE_CENTER, Input::Action::FIRE_CENTER,
InputAction::FIRE_RIGHT, Input::Action::FIRE_RIGHT,
InputAction::START, Input::Action::START,
InputAction::SERVICE}, Input::Action::SERVICE},
buttons{ buttons{
SDL_GAMEPAD_BUTTON_WEST, SDL_GAMEPAD_BUTTON_WEST,
SDL_GAMEPAD_BUTTON_NORTH, SDL_GAMEPAD_BUTTON_NORTH,

View File

@@ -66,19 +66,19 @@ void Player::init() {
shiftSprite(); shiftSprite();
// Selecciona un frame para pintar // Selecciona un frame para pintar
//player_sprite_->setCurrentAnimation("stand"); // player_sprite_->setCurrentAnimation("stand");
} }
// Actua en consecuencia de la entrada recibida // Actua en consecuencia de la entrada recibida
void Player::setInput(InputAction input) { void Player::setInput(Input::Action action) {
switch (playing_state_) { switch (playing_state_) {
case State::PLAYING: { case State::PLAYING: {
setInputPlaying(input); setInputPlaying(action);
break; break;
} }
case State::ENTERING_NAME: case State::ENTERING_NAME:
case State::ENTERING_NAME_GAME_COMPLETED: { case State::ENTERING_NAME_GAME_COMPLETED: {
setInputEnteringName(input); setInputEnteringName(action);
break; break;
} }
default: default:
@@ -87,27 +87,27 @@ void Player::setInput(InputAction input) {
} }
// Procesa inputs para cuando está jugando // Procesa inputs para cuando está jugando
void Player::setInputPlaying(InputAction input) { void Player::setInputPlaying(Input::Action action) {
switch (input) { switch (action) {
case InputAction::LEFT: { case Input::Action::LEFT: {
vel_x_ = -BASE_SPEED; vel_x_ = -BASE_SPEED;
setWalkingState(State::WALKING_LEFT); setWalkingState(State::WALKING_LEFT);
break; break;
} }
case InputAction::RIGHT: { case Input::Action::RIGHT: {
vel_x_ = BASE_SPEED; vel_x_ = BASE_SPEED;
setWalkingState(State::WALKING_RIGHT); setWalkingState(State::WALKING_RIGHT);
break; break;
} }
case InputAction::FIRE_CENTER: { case Input::Action::FIRE_CENTER: {
setFiringState(State::FIRING_UP); setFiringState(State::FIRING_UP);
break; break;
} }
case InputAction::FIRE_LEFT: { case Input::Action::FIRE_LEFT: {
setFiringState(State::FIRING_LEFT); setFiringState(State::FIRING_LEFT);
break; break;
} }
case InputAction::FIRE_RIGHT: { case Input::Action::FIRE_RIGHT: {
setFiringState(State::FIRING_RIGHT); setFiringState(State::FIRING_RIGHT);
break; break;
} }
@@ -120,21 +120,21 @@ void Player::setInputPlaying(InputAction input) {
} }
// Procesa inputs para cuando está introduciendo el nombre // Procesa inputs para cuando está introduciendo el nombre
void Player::setInputEnteringName(InputAction input) { void Player::setInputEnteringName(Input::Action action) {
switch (input) { switch (action) {
case InputAction::LEFT: case Input::Action::LEFT:
enter_name_->decPosition(); enter_name_->decPosition();
break; break;
case InputAction::RIGHT: case Input::Action::RIGHT:
enter_name_->incPosition(); enter_name_->incPosition();
break; break;
case InputAction::UP: case Input::Action::UP:
enter_name_->incIndex(); enter_name_->incIndex();
break; break;
case InputAction::DOWN: case Input::Action::DOWN:
enter_name_->decIndex(); enter_name_->decIndex();
break; break;
case InputAction::START: case Input::Action::START:
last_enter_name_ = getRecordName(); last_enter_name_ = getRecordName();
break; break;
default: default:
@@ -288,7 +288,7 @@ void Player::handleEnteringScreen() {
} }
void Player::handlePlayer1Entering() { void Player::handlePlayer1Entering() {
setInputPlaying(InputAction::RIGHT); setInputPlaying(Input::Action::RIGHT);
pos_x_ += vel_x_; pos_x_ += vel_x_;
if (pos_x_ > default_pos_x_) { if (pos_x_ > default_pos_x_) {
pos_x_ = default_pos_x_; pos_x_ = default_pos_x_;
@@ -297,7 +297,7 @@ void Player::handlePlayer1Entering() {
} }
void Player::handlePlayer2Entering() { void Player::handlePlayer2Entering() {
setInputPlaying(InputAction::LEFT); setInputPlaying(Input::Action::LEFT);
pos_x_ += vel_x_; pos_x_ += vel_x_;
if (pos_x_ < default_pos_x_) { if (pos_x_ < default_pos_x_) {
pos_x_ = default_pos_x_; pos_x_ = default_pos_x_;
@@ -351,10 +351,10 @@ void Player::updateWalkingStateForCredits() {
void Player::setInputBasedOnPlayerId() { void Player::setInputBasedOnPlayerId() {
switch (id_) { switch (id_) {
case 1: case 1:
setInputPlaying(InputAction::LEFT); setInputPlaying(Input::Action::LEFT);
break; break;
case 2: case 2:
setInputPlaying(InputAction::RIGHT); setInputPlaying(Input::Action::RIGHT);
break; break;
default: default:
break; break;

View File

@@ -14,7 +14,7 @@
#include "utils.h" // Para Circle #include "utils.h" // Para Circle
class Texture; class Texture;
enum class InputAction : int; enum class Action : int;
enum class Mode; enum class Mode;
// --- Clase Player --- // --- Clase Player ---
@@ -77,9 +77,9 @@ class Player {
void render(); // Dibuja el jugador en pantalla void render(); // Dibuja el jugador en pantalla
// --- Entrada y control --- // --- Entrada y control ---
void setInput(InputAction input); // Procesa entrada general void setInput(Input::Action action); // Procesa entrada general
void setInputPlaying(InputAction input); // Procesa entrada en modo jugando void setInputPlaying(Input::Action action); // Procesa entrada en modo jugando
void setInputEnteringName(InputAction input); // Procesa entrada al introducir nombre void setInputEnteringName(Input::Action action); // Procesa entrada al introducir nombre
// --- Movimiento y animación --- // --- Movimiento y animación ---
void move(); // Mueve el jugador void move(); // Mueve el jugador

View File

@@ -16,7 +16,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 #include "global_inputs.h" // Para check
#include "input.h" // Para Input, INPUT_ALLOW_REPEAT #include "input.h" // Para Input, Input::ALLOW_REPEAT
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamGame, ParamFade #include "param.h" // Para Param, param, ParamGame, ParamFade
#include "player.h" // Para Player, PlayerState #include "player.h" // Para Player, PlayerState
@@ -131,7 +131,7 @@ void Credits::checkInput() {
if (!ServiceMenu::get()->isEnabled()) { if (!ServiceMenu::get()->isEnabled()) {
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar) // Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT) != 0) { if (Input::get()->checkAnyButton(Input::ALLOW_REPEAT) != 0) {
want_to_pass_ = true; want_to_pass_ = true;
fading_ = mini_logo_on_position_; fading_ = mini_logo_on_position_;
} else { } else {

View File

@@ -22,7 +22,7 @@
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "hit.h" // Para Hit #include "hit.h" // Para Hit
#include "input.h" // Para InputAction, Input, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_ALLOW_REPEAT, InputDevice #include "input.h" // Para InputAction, Input, Input::DO_NOT_ALLOW_REPEAT, Input::ALLOW_REPEAT, InputDevice
#include "item.h" // Para Item, ItemType #include "item.h" // Para Item, ItemType
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry #include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry
@@ -1244,14 +1244,14 @@ void Game::checkInput() {
void Game::checkPauseInput() { 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(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { if (input_->checkInput(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
pause(!paused_); pause(!paused_);
return; return;
} }
} }
// Comprueba el teclado // Comprueba el teclado
if (input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (input_->checkInput(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
pause(!paused_); pause(!paused_);
return; return;
} }
@@ -1283,11 +1283,11 @@ void Game::demoHandlePlayerInput(const std::shared_ptr<Player> &player, int inde
const auto &demo_data = demo_.data[index][demo_.counter]; const auto &demo_data = demo_.data[index][demo_.counter];
if (demo_data.left == 1) { if (demo_data.left == 1) {
player->setInput(InputAction::LEFT); player->setInput(Input::Action::LEFT);
} else if (demo_data.right == 1) { } else if (demo_data.right == 1) {
player->setInput(InputAction::RIGHT); player->setInput(Input::Action::RIGHT);
} else if (demo_data.no_input == 1) { } else if (demo_data.no_input == 1) {
player->setInput(InputAction::NONE); player->setInput(Input::Action::NONE);
} }
if (demo_data.fire == 1) { if (demo_data.fire == 1) {
@@ -1305,17 +1305,17 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
SDL_Point bullet = {0, 0}; SDL_Point bullet = {0, 0};
switch (bullet_type) { switch (bullet_type) {
case BulletType::UP: case BulletType::UP:
player->setInput(InputAction::FIRE_CENTER); player->setInput(Input::Action::FIRE_CENTER);
bullet.x = 2 + player->getPosX() + (player->getWidth() - Bullet::WIDTH) / 2; bullet.x = 2 + player->getPosX() + (player->getWidth() - Bullet::WIDTH) / 2;
bullet.y = player->getPosY() - (Bullet::HEIGHT / 2); bullet.y = player->getPosY() - (Bullet::HEIGHT / 2);
break; break;
case BulletType::LEFT: case BulletType::LEFT:
player->setInput(InputAction::FIRE_LEFT); player->setInput(Input::Action::FIRE_LEFT);
bullet.x = player->getPosX() - (Bullet::WIDTH / 2); bullet.x = player->getPosX() - (Bullet::WIDTH / 2);
bullet.y = player->getPosY(); bullet.y = player->getPosY();
break; break;
case BulletType::RIGHT: case BulletType::RIGHT:
player->setInput(InputAction::FIRE_RIGHT); player->setInput(Input::Action::FIRE_RIGHT);
bullet.x = player->getPosX() + player->getWidth() - (Bullet::WIDTH / 2); bullet.x = player->getPosX() + player->getWidth() - (Bullet::WIDTH / 2);
bullet.y = player->getPosY(); bullet.y = player->getPosY();
break; break;
@@ -1362,18 +1362,18 @@ void Game::handlePlayersInput() {
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player) { 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());
if (input_->checkInput(InputAction::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) { if (input_->checkInput(Input::Action::LEFT, Input::ALLOW_REPEAT, controller.type, controller.index)) {
player->setInput(InputAction::LEFT); player->setInput(Input::Action::LEFT);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.left = 1; demo_.keys.left = 1;
#endif #endif
} else if (input_->checkInput(InputAction::RIGHT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) { } else if (input_->checkInput(Input::Action::RIGHT, Input::ALLOW_REPEAT, controller.type, controller.index)) {
player->setInput(InputAction::RIGHT); player->setInput(Input::Action::RIGHT);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.right = 1; demo_.keys.right = 1;
#endif #endif
} else { } else {
player->setInput(InputAction::NONE); player->setInput(Input::Action::NONE);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.no_input = 1; demo_.keys.no_input = 1;
#endif #endif
@@ -1386,17 +1386,17 @@ 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 controller_index) { void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controller_index) {
const auto CONTROLLER = Options::controllers.at(player->getController()); const auto CONTROLLER = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::FIRE_CENTER, autofire, CONTROLLER.type, CONTROLLER.index)) { if (input_->checkInput(Input::Action::FIRE_CENTER, autofire, CONTROLLER.type, CONTROLLER.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(InputAction::FIRE_LEFT, autofire, CONTROLLER.type, CONTROLLER.index)) { } else if (input_->checkInput(Input::Action::FIRE_LEFT, autofire, CONTROLLER.type, CONTROLLER.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(InputAction::FIRE_RIGHT, autofire, CONTROLLER.type, CONTROLLER.index)) { } else if (input_->checkInput(Input::Action::FIRE_RIGHT, autofire, CONTROLLER.type, CONTROLLER.index)) {
handleFireInput(player, BulletType::RIGHT); handleFireInput(player, BulletType::RIGHT);
#ifdef RECORDING #ifdef RECORDING
demo_.keys.fire_right = 1; demo_.keys.fire_right = 1;
@@ -1407,16 +1407,16 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio. // Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) { void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
const auto CONTROLLER = Options::controllers.at(player->getController()); const auto CONTROLLER = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { if (input_->checkInput(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setPlayingState(Player::State::RESPAWNING); player->setPlayingState(Player::State::RESPAWNING);
player->addCredit(); player->addCredit();
sendPlayerToTheFront(player); sendPlayerToTheFront(player);
} }
// 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(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) || if (input_->checkInput(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) || input_->checkInput(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { input_->checkInput(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (player->getContinueCounter() < param.scoreboard.skip_countdown_value) { if (player->getContinueCounter() < param.scoreboard.skip_countdown_value) {
player->decContinueCounter(); player->decContinueCounter();
} }
@@ -1426,7 +1426,7 @@ void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio. // Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) { void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
const auto CONTROLLER = Options::controllers.at(player->getController()); const auto CONTROLLER = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { if (input_->checkInput(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setPlayingState(Player::State::ENTERING_SCREEN); player->setPlayingState(Player::State::ENTERING_SCREEN);
player->addCredit(); player->addCredit();
sendPlayerToTheFront(player); sendPlayerToTheFront(player);
@@ -1436,32 +1436,32 @@ void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
// Procesa las entradas para la introducción del nombre del jugador. // Procesa las entradas para la introducción del nombre del jugador.
void Game::handleNameInput(const std::shared_ptr<Player> &player) { void Game::handleNameInput(const std::shared_ptr<Player> &player) {
const auto CONTROLLER = Options::controllers.at(player->getController()); const auto CONTROLLER = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { if (input_->checkInput(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (player->isShowingName()) { if (player->isShowingName()) {
player->setPlayingState(Player::State::CONTINUE); player->setPlayingState(Player::State::CONTINUE);
} else if (player->getEnterNamePositionOverflow()) { } else if (player->getEnterNamePositionOverflow()) {
player->setInput(InputAction::START); player->setInput(Input::Action::START);
addScoreToScoreBoard(player); addScoreToScoreBoard(player);
player->setPlayingState(Player::State::SHOWING_NAME); player->setPlayingState(Player::State::SHOWING_NAME);
} else { } else {
player->setInput(InputAction::RIGHT); player->setInput(Input::Action::RIGHT);
} }
} else if (input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) || } else if (input_->checkInput(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { input_->checkInput(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (player->isShowingName()) { if (player->isShowingName()) {
player->setPlayingState(Player::State::CONTINUE); player->setPlayingState(Player::State::CONTINUE);
} else { } else {
player->setInput(InputAction::LEFT); player->setInput(Input::Action::LEFT);
} }
} else if (input_->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { } else if (input_->checkInput(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setInput(InputAction::UP); player->setInput(Input::Action::UP);
} else if (input_->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { } else if (input_->checkInput(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setInput(InputAction::DOWN); player->setInput(Input::Action::DOWN);
} else if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { } else if (input_->checkInput(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (player->isShowingName()) { if (player->isShowingName()) {
player->setPlayingState(Player::State::CONTINUE); player->setPlayingState(Player::State::CONTINUE);
} else { } else {
player->setInput(InputAction::START); player->setInput(Input::Action::START);
addScoreToScoreBoard(player); addScoreToScoreBoard(player);
player->setPlayingState(Player::State::SHOWING_NAME); player->setPlayingState(Player::State::SHOWING_NAME);
} }
@@ -1882,7 +1882,7 @@ void Game::checkDebugEvents(const SDL_Event &event) {
case SDLK_1: // Crea una powerball case SDLK_1: // Crea una powerball
{ {
// balloon_manager_->createPowerBall(); // balloon_manager_->createPowerBall();
//throwCoffee(players_.at(0)->getPosX() + (players_.at(0)->getWidth() / 2), players_.at(0)->getPosY() + (players_.at(0)->getHeight() / 2)); // throwCoffee(players_.at(0)->getPosX() + (players_.at(0)->getWidth() / 2), players_.at(0)->getPosY() + (players_.at(0)->getHeight() / 2));
break; break;
} }
case SDLK_2: // Activa o desactiva la aparición de globos case SDLK_2: // Activa o desactiva la aparición de globos

View File

@@ -15,7 +15,7 @@
#include "game_logo.h" // Para GameLogo #include "game_logo.h" // Para GameLogo
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "input.h" // Para Input, INPUT_DO_NOT_ALLOW_REPEAT, Input... #include "input.h" // Para Input, Input::DO_NOT_ALLOW_REPEAT, Input...
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "options.h" // Para GamepadOptions, controllers, getPlayerW... #include "options.h" // Para GamepadOptions, controllers, getPlayerW...
#include "param.h" // Para Param, param, ParamGame, ParamTitle #include "param.h" // Para Param, param, ParamGame, ParamTitle
@@ -271,8 +271,8 @@ void Title::processControllerInputs() {
auto Title::isStartButtonPressed(const Options::GamepadOptions& controller) -> bool { auto Title::isStartButtonPressed(const Options::GamepadOptions& controller) -> bool {
return Input::get()->checkInput( return Input::get()->checkInput(
InputAction::START, Input::Action::START,
INPUT_DO_NOT_ALLOW_REPEAT, Input::DO_NOT_ALLOW_REPEAT,
controller.type, controller.type,
controller.index); controller.index);
} }