Merge branch 'refactor/input-enum-class'

This commit is contained in:
2026-05-16 20:01:40 +02:00
15 changed files with 184 additions and 177 deletions
+6 -6
View File
@@ -8,29 +8,29 @@ namespace GlobalInputs {
auto handle() -> bool { auto handle() -> bool {
if (Screen::get() == nullptr || Input::get() == nullptr) { return false; } if (Screen::get() == nullptr || Input::get() == nullptr) { return false; }
if (Input::get()->checkInput(WINDOW_FULLSCREEN, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::WINDOW_FULLSCREEN, Input::Repeat::OFF)) {
Screen::get()->toggleVideoMode(); Screen::get()->toggleVideoMode();
return true; return true;
} }
if (Input::get()->checkInput(WINDOW_DEC_ZOOM, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::WINDOW_DEC_ZOOM, Input::Repeat::OFF)) {
Screen::get()->decWindowZoom(); Screen::get()->decWindowZoom();
return true; return true;
} }
if (Input::get()->checkInput(WINDOW_INC_ZOOM, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::WINDOW_INC_ZOOM, Input::Repeat::OFF)) {
Screen::get()->incWindowZoom(); Screen::get()->incWindowZoom();
return true; return true;
} }
if (Input::get()->checkInput(TOGGLE_SHADER, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::TOGGLE_SHADER, Input::Repeat::OFF)) {
Screen::get()->toggleShaderEnabled(); Screen::get()->toggleShaderEnabled();
return true; return true;
} }
// F5/F6 només actuen quan el post-procesado està actiu. // F5/F6 només actuen quan el post-procesado està actiu.
if (Screen::isShaderEnabled()) { if (Screen::isShaderEnabled()) {
if (Input::get()->checkInput(TOGGLE_SHADER_TYPE, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::TOGGLE_SHADER_TYPE, Input::Repeat::OFF)) {
Screen::get()->toggleActiveShader(); Screen::get()->toggleActiveShader();
return true; return true;
} }
if (Input::get()->checkInput(NEXT_SHADER_PRESET, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::NEXT_SHADER_PRESET, Input::Repeat::OFF)) {
Screen::get()->nextPreset(); Screen::get()->nextPreset();
return true; return true;
} }
+29 -27
View File
@@ -65,12 +65,12 @@ Input::Input(std::string file)
KeyBindings kb; KeyBindings kb;
kb.scancode = 0; kb.scancode = 0;
kb.active = false; kb.active = false;
key_bindings_.resize(NUMBER_OF_INPUTS, kb); key_bindings_.resize(static_cast<std::size_t>(Action::NUMBER_OF_INPUTS), kb);
GameControllerBindings gcb; GameControllerBindings gcb;
gcb.button = SDL_GAMEPAD_BUTTON_INVALID; gcb.button = SDL_GAMEPAD_BUTTON_INVALID;
gcb.active = false; gcb.active = false;
game_controller_bindings_.resize(NUMBER_OF_INPUTS, gcb); game_controller_bindings_.resize(static_cast<std::size_t>(Action::NUMBER_OF_INPUTS), gcb);
} }
// Destructor // Destructor
@@ -88,38 +88,38 @@ Input::~Input() {
// Actualiza el estado del objeto // Actualiza el estado del objeto
void Input::update() { void Input::update() {
if (disabled_until_ == KEY_PRESSED && !checkAnyInput()) { if (disabled_until_ == Disable::KEY_PRESSED && !checkAnyInput()) {
enable(); enable();
} }
} }
// Asigna inputs a teclas // Asigna inputs a teclas
void Input::bindKey(Uint8 input, SDL_Scancode code) { void Input::bindKey(Action input, SDL_Scancode code) {
key_bindings_[input].scancode = code; key_bindings_[static_cast<std::size_t>(input)].scancode = code;
} }
// Asigna inputs a botones del mando // Asigna inputs a botones del mando
void Input::bindGameControllerButton(Uint8 input, SDL_GamepadButton button) { void Input::bindGameControllerButton(Action input, SDL_GamepadButton button) {
game_controller_bindings_[input].button = button; game_controller_bindings_[static_cast<std::size_t>(input)].button = button;
} }
// Comprueba si un input esta activo // Comprueba si un input esta activo
auto Input::checkInput(Uint8 input, bool repeat, int device, int index) -> bool { auto Input::checkInput(Action input, Repeat repeat, Device device, int index) -> bool {
if (!enabled_) { if (!enabled_) {
return false; return false;
} }
if (device == INPUT_USE_ANY) { if (device == Device::ANY) {
index = 0; index = 0;
} }
bool success_keyboard = false; bool success_keyboard = false;
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY) { if (device == Device::KEYBOARD || device == Device::ANY) {
success_keyboard = checkKeyboardInput(input, repeat); success_keyboard = checkKeyboardInput(input, repeat);
} }
bool success_game_controller = false; bool success_game_controller = false;
if ((device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY) && gameControllerFound() && index >= 0 && index < (int)connected_controllers_.size()) { if ((device == Device::GAMECONTROLLER || device == Device::ANY) && gameControllerFound() && index >= 0 && index < (int)connected_controllers_.size()) {
success_game_controller = checkGameControllerInput(input, repeat, index); success_game_controller = checkGameControllerInput(input, repeat, index);
} }
@@ -127,41 +127,43 @@ auto Input::checkInput(Uint8 input, bool repeat, int device, int index) -> bool
} }
// Helper de checkInput: comprueba el estado de una tecla // Helper de checkInput: comprueba el estado de una tecla
auto Input::checkKeyboardInput(Uint8 input, bool repeat) -> bool { auto Input::checkKeyboardInput(Action input, Repeat repeat) -> bool {
const auto IDX = static_cast<std::size_t>(input);
const bool *key_states = SDL_GetKeyboardState(nullptr); const bool *key_states = SDL_GetKeyboardState(nullptr);
const bool IS_DOWN = key_states[key_bindings_[input].scancode]; const bool IS_DOWN = key_states[key_bindings_[IDX].scancode];
if (repeat) { if (repeat == Repeat::ON) {
return IS_DOWN; return IS_DOWN;
} }
// Modo edge-trigger: éxito sólo en el frame en que la tecla pasa de up a down // Modo edge-trigger: éxito sólo en el frame en que la tecla pasa de up a down
const bool PRESS_EDGE = IS_DOWN && !key_bindings_[input].active; const bool PRESS_EDGE = IS_DOWN && !key_bindings_[IDX].active;
key_bindings_[input].active = IS_DOWN; key_bindings_[IDX].active = IS_DOWN;
return PRESS_EDGE; return PRESS_EDGE;
} }
// Helper de checkInput: comprueba el estado de un botón de mando // Helper de checkInput: comprueba el estado de un botón de mando
auto Input::checkGameControllerInput(Uint8 input, bool repeat, int index) -> bool { auto Input::checkGameControllerInput(Action input, Repeat repeat, int index) -> bool {
const bool IS_DOWN = SDL_GetGamepadButton(connected_controllers_[index], game_controller_bindings_[input].button); const auto IDX = static_cast<std::size_t>(input);
const bool IS_DOWN = SDL_GetGamepadButton(connected_controllers_[index], game_controller_bindings_[IDX].button);
if (repeat) { if (repeat == Repeat::ON) {
return IS_DOWN; return IS_DOWN;
} }
// Modo edge-trigger: éxito sólo en el frame en que el botón pasa de up a down // Modo edge-trigger: éxito sólo en el frame en que el botón pasa de up a down
const bool PRESS_EDGE = IS_DOWN && !game_controller_bindings_[input].active; const bool PRESS_EDGE = IS_DOWN && !game_controller_bindings_[IDX].active;
game_controller_bindings_[input].active = IS_DOWN; game_controller_bindings_[IDX].active = IS_DOWN;
return PRESS_EDGE; return PRESS_EDGE;
} }
// Comprueba si hay almenos un input activo // Comprueba si hay almenos un input activo
auto Input::checkAnyInput(int device, int index) -> bool { auto Input::checkAnyInput(Device device, int index) -> bool {
if (device == INPUT_USE_ANY) { if (device == Device::ANY) {
index = 0; index = 0;
} }
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY) { if (device == Device::KEYBOARD || device == Device::ANY) {
const bool *key_states = SDL_GetKeyboardState(nullptr); const bool *key_states = SDL_GetKeyboardState(nullptr);
if (std::ranges::any_of(key_bindings_, if (std::ranges::any_of(key_bindings_,
@@ -171,7 +173,7 @@ auto Input::checkAnyInput(int device, int index) -> bool {
} }
if (gameControllerFound() && index >= 0 && index < (int)connected_controllers_.size()) { if (gameControllerFound() && index >= 0 && index < (int)connected_controllers_.size()) {
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY) { if (device == Device::GAMECONTROLLER || device == Device::ANY) {
for (auto &game_controller_binding : game_controller_bindings_) { for (auto &game_controller_binding : game_controller_bindings_) {
if (SDL_GetGamepadButton(connected_controllers_[index], game_controller_binding.button)) { if (SDL_GetGamepadButton(connected_controllers_[index], game_controller_binding.button)) {
return true; return true;
@@ -376,7 +378,7 @@ void Input::setVerbose(bool value) {
} }
// Deshabilita las entradas durante un periodo de tiempo // Deshabilita las entradas durante un periodo de tiempo
void Input::disableUntil(InputDisable value) { void Input::disableUntil(Disable value) {
disabled_until_ = value; disabled_until_ = value;
enabled_ = false; enabled_ = false;
} }
@@ -384,5 +386,5 @@ void Input::disableUntil(InputDisable value) {
// Hablita las entradas // Hablita las entradas
void Input::enable() { void Input::enable() {
enabled_ = true; enabled_ = true;
disabled_until_ = NOT_DISABLED; disabled_until_ = Disable::NOT_DISABLED;
} }
+54 -52
View File
@@ -6,52 +6,54 @@
#include <string> // for string, basic_string #include <string> // for string, basic_string
#include <vector> // for vector #include <vector> // for vector
// Valores de repetición
constexpr bool REPEAT_TRUE = true;
constexpr bool REPEAT_FALSE = false;
// Métodos de entrada
constexpr int INPUT_USE_KEYBOARD = 0;
constexpr int INPUT_USE_GAMECONTROLLER = 1;
constexpr int INPUT_USE_ANY = 2;
enum InputAction : std::uint8_t {
// Inputs obligatorios
INVALID,
UP,
DOWN,
LEFT,
RIGHT,
PAUSE,
EXIT,
ACCEPT,
CANCEL,
// Inputs personalizados
FIRE_LEFT,
FIRE_CENTER,
FIRE_RIGHT,
WINDOW_FULLSCREEN,
WINDOW_INC_ZOOM,
WINDOW_DEC_ZOOM,
// GPU / shaders (hotkeys provisionales hasta que haya menú de opciones)
NEXT_SHADER_PRESET,
TOGGLE_SHADER,
TOGGLE_SHADER_TYPE,
// Input obligatorio
NUMBER_OF_INPUTS
};
enum InputDisable : std::uint8_t {
NOT_DISABLED,
FOREVER,
KEY_PRESSED
};
class Input { class Input {
public: public:
enum class Repeat : std::uint8_t {
OFF,
ON
};
enum class Device : std::uint8_t {
KEYBOARD,
GAMECONTROLLER,
ANY
};
enum class Disable : std::uint8_t {
NOT_DISABLED,
FOREVER,
KEY_PRESSED
};
enum class Action : std::uint8_t {
// Inputs obligatorios
INVALID,
UP,
DOWN,
LEFT,
RIGHT,
PAUSE,
EXIT,
ACCEPT,
CANCEL,
// Inputs personalizados
FIRE_LEFT,
FIRE_CENTER,
FIRE_RIGHT,
WINDOW_FULLSCREEN,
WINDOW_INC_ZOOM,
WINDOW_DEC_ZOOM,
// GPU / shaders (hotkeys provisionales hasta que haya menú de opciones)
NEXT_SHADER_PRESET,
TOGGLE_SHADER,
TOGGLE_SHADER_TYPE,
// Centinela final (usar para sizing)
NUMBER_OF_INPUTS
};
// Singleton API // Singleton API
static void init(const std::string &game_controller_db_path); // Crea la instancia static void init(const std::string &game_controller_db_path); // Crea la instancia
static void destroy(); // Libera la instancia static void destroy(); // Libera la instancia
@@ -60,11 +62,11 @@ class Input {
~Input(); // Destructor ~Input(); // Destructor
void update(); // Actualiza el estado del objeto void update(); // Actualiza el estado del objeto
void bindKey(Uint8 input, SDL_Scancode code); // Asigna inputs a teclas void bindKey(Action input, SDL_Scancode code); // Asigna inputs a teclas
void bindGameControllerButton(Uint8 input, SDL_GamepadButton button); // Asigna inputs a botones del mando void bindGameControllerButton(Action input, SDL_GamepadButton button); // Asigna inputs a botones del mando
auto checkInput(Uint8 input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si un input esta activo auto checkInput(Action input, Repeat repeat = Repeat::ON, Device device = Device::ANY, int index = 0) -> bool; // Comprueba si un input esta activo
auto checkAnyInput(int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo auto checkAnyInput(Device device = Device::ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo
auto discoverGameController() -> bool; // Busca si hay un mando conectado auto discoverGameController() -> bool; // Busca si hay un mando conectado
@@ -81,7 +83,7 @@ class Input {
auto getControllerName(int index) -> std::string; // Obten el nombre de un mando de juego auto getControllerName(int index) -> std::string; // Obten el nombre de un mando de juego
void setVerbose(bool value); // Establece si ha de mostrar mensajes void setVerbose(bool value); // Establece si ha de mostrar mensajes
void disableUntil(InputDisable value); // Deshabilita las entradas durante un periodo de tiempo void disableUntil(Disable value); // Deshabilita las entradas durante un periodo de tiempo
void enable(); // Hablita las entradas void enable(); // Hablita las entradas
private: private:
@@ -106,7 +108,7 @@ class Input {
int num_gamepads_{0}; // Numero de mandos conectados int num_gamepads_{0}; // Numero de mandos conectados
std::string db_path_; // Ruta al archivo gamecontrollerdb.txt std::string db_path_; // Ruta al archivo gamecontrollerdb.txt
bool verbose_{true}; // Indica si ha de mostrar mensajes bool verbose_{true}; // Indica si ha de mostrar mensajes
InputDisable disabled_until_{NOT_DISABLED}; // Tiempo que esta deshabilitado Disable disabled_until_{Disable::NOT_DISABLED}; // Tiempo que esta deshabilitado
bool enabled_{true}; // Indica si está habilitado bool enabled_{true}; // Indica si está habilitado
static Input *instance; // Instancia única static Input *instance; // Instancia única
@@ -117,8 +119,8 @@ class Input {
static auto buildControllerName(SDL_Gamepad *pad, int pad_index) -> std::string; static auto buildControllerName(SDL_Gamepad *pad, int pad_index) -> std::string;
// Helpers de checkInput // Helpers de checkInput
auto checkKeyboardInput(Uint8 input, bool repeat) -> bool; auto checkKeyboardInput(Action input, Repeat repeat) -> bool;
auto checkGameControllerInput(Uint8 input, bool repeat, int index) -> bool; auto checkGameControllerInput(Action input, Repeat repeat, int index) -> bool;
// Helpers de discoverGameController // Helpers de discoverGameController
void resetGameControllerState(); void resetGameControllerState();
+28 -28
View File
@@ -17,7 +17,7 @@
#include <string> // for basic_string, operator+, char_t... #include <string> // for basic_string, operator+, char_t...
#include "core/audio/audio.hpp" // for Audio::init, Audio::destroy #include "core/audio/audio.hpp" // for Audio::init, Audio::destroy
#include "core/input/input.h" // for Input, InputAction, INPUT_USE_GAME... #include "core/input/input.h" // for Input, InputAction
#include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda... #include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
#include "core/locale/lang.h" // for Lang, Lang::Code #include "core/locale/lang.h" // for Lang, Lang::Code
#include "core/rendering/screen.h" // for Screen #include "core/rendering/screen.h" // for Screen
@@ -208,44 +208,44 @@ void Director::initInput() {
Input::get()->discoverGameController(); Input::get()->discoverGameController();
// Teclado - Movimiento del jugador // Teclado - Movimiento del jugador
Input::get()->bindKey(UP, SDL_SCANCODE_UP); Input::get()->bindKey(Input::Action::UP, SDL_SCANCODE_UP);
Input::get()->bindKey(DOWN, SDL_SCANCODE_DOWN); Input::get()->bindKey(Input::Action::DOWN, SDL_SCANCODE_DOWN);
Input::get()->bindKey(LEFT, SDL_SCANCODE_LEFT); Input::get()->bindKey(Input::Action::LEFT, SDL_SCANCODE_LEFT);
Input::get()->bindKey(RIGHT, SDL_SCANCODE_RIGHT); Input::get()->bindKey(Input::Action::RIGHT, SDL_SCANCODE_RIGHT);
Input::get()->bindKey(FIRE_LEFT, SDL_SCANCODE_Q); Input::get()->bindKey(Input::Action::FIRE_LEFT, SDL_SCANCODE_Q);
Input::get()->bindKey(FIRE_CENTER, SDL_SCANCODE_W); Input::get()->bindKey(Input::Action::FIRE_CENTER, SDL_SCANCODE_W);
Input::get()->bindKey(FIRE_RIGHT, SDL_SCANCODE_E); Input::get()->bindKey(Input::Action::FIRE_RIGHT, SDL_SCANCODE_E);
// Teclado - Otros // Teclado - Otros
Input::get()->bindKey(ACCEPT, SDL_SCANCODE_RETURN); Input::get()->bindKey(Input::Action::ACCEPT, SDL_SCANCODE_RETURN);
Input::get()->bindKey(CANCEL, SDL_SCANCODE_ESCAPE); Input::get()->bindKey(Input::Action::CANCEL, SDL_SCANCODE_ESCAPE);
Input::get()->bindKey(PAUSE, SDL_SCANCODE_ESCAPE); Input::get()->bindKey(Input::Action::PAUSE, SDL_SCANCODE_ESCAPE);
Input::get()->bindKey(EXIT, SDL_SCANCODE_ESCAPE); Input::get()->bindKey(Input::Action::EXIT, SDL_SCANCODE_ESCAPE);
Input::get()->bindKey(WINDOW_DEC_ZOOM, SDL_SCANCODE_F1); Input::get()->bindKey(Input::Action::WINDOW_DEC_ZOOM, SDL_SCANCODE_F1);
Input::get()->bindKey(WINDOW_INC_ZOOM, SDL_SCANCODE_F2); Input::get()->bindKey(Input::Action::WINDOW_INC_ZOOM, SDL_SCANCODE_F2);
Input::get()->bindKey(WINDOW_FULLSCREEN, SDL_SCANCODE_F3); Input::get()->bindKey(Input::Action::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
Input::get()->bindKey(TOGGLE_SHADER, SDL_SCANCODE_F4); Input::get()->bindKey(Input::Action::TOGGLE_SHADER, SDL_SCANCODE_F4);
Input::get()->bindKey(TOGGLE_SHADER_TYPE, SDL_SCANCODE_F5); Input::get()->bindKey(Input::Action::TOGGLE_SHADER_TYPE, SDL_SCANCODE_F5);
Input::get()->bindKey(NEXT_SHADER_PRESET, SDL_SCANCODE_F6); Input::get()->bindKey(Input::Action::NEXT_SHADER_PRESET, SDL_SCANCODE_F6);
// Mando - Movimiento del jugador // Mando - Movimiento del jugador
Input::get()->bindGameControllerButton(UP, SDL_GAMEPAD_BUTTON_DPAD_UP); Input::get()->bindGameControllerButton(Input::Action::UP, SDL_GAMEPAD_BUTTON_DPAD_UP);
Input::get()->bindGameControllerButton(DOWN, SDL_GAMEPAD_BUTTON_DPAD_DOWN); Input::get()->bindGameControllerButton(Input::Action::DOWN, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
Input::get()->bindGameControllerButton(LEFT, SDL_GAMEPAD_BUTTON_DPAD_LEFT); Input::get()->bindGameControllerButton(Input::Action::LEFT, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
Input::get()->bindGameControllerButton(RIGHT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT); Input::get()->bindGameControllerButton(Input::Action::RIGHT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
Input::get()->bindGameControllerButton(FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST); Input::get()->bindGameControllerButton(Input::Action::FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST);
Input::get()->bindGameControllerButton(FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH); Input::get()->bindGameControllerButton(Input::Action::FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH);
Input::get()->bindGameControllerButton(FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST); Input::get()->bindGameControllerButton(Input::Action::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST);
// Mando - Otros // Mando - Otros
// SOUTH queda sin asignar para evitar salidas accidentales: pausa/cancel se hace con START/BACK. // SOUTH queda sin asignar para evitar salidas accidentales: pausa/cancel se hace con START/BACK.
Input::get()->bindGameControllerButton(ACCEPT, SDL_GAMEPAD_BUTTON_EAST); Input::get()->bindGameControllerButton(Input::Action::ACCEPT, SDL_GAMEPAD_BUTTON_EAST);
#ifdef GAME_CONSOLE #ifdef GAME_CONSOLE
Input::get()->bindGameControllerButton(input_pause, SDL_GAMEPAD_BUTTON_BACK); Input::get()->bindGameControllerButton(input_pause, SDL_GAMEPAD_BUTTON_BACK);
Input::get()->bindGameControllerButton(input_exit, SDL_GAMEPAD_BUTTON_START); Input::get()->bindGameControllerButton(input_exit, SDL_GAMEPAD_BUTTON_START);
#else #else
Input::get()->bindGameControllerButton(PAUSE, SDL_GAMEPAD_BUTTON_START); Input::get()->bindGameControllerButton(Input::Action::PAUSE, SDL_GAMEPAD_BUTTON_START);
Input::get()->bindGameControllerButton(EXIT, SDL_GAMEPAD_BUTTON_BACK); Input::get()->bindGameControllerButton(Input::Action::EXIT, SDL_GAMEPAD_BUTTON_BACK);
#endif #endif
} }
+6 -6
View File
@@ -95,27 +95,27 @@ void Player::init() {
} }
// Actua en consecuencia de la entrada recibida // Actua en consecuencia de la entrada recibida
void Player::setInput(Uint8 input) { void Player::setInput(Input::Action input) {
switch (input) { switch (input) {
case LEFT: case Input::Action::LEFT:
vel_x_ = -base_speed_; vel_x_ = -base_speed_;
setWalkingStatus(STATUS_WALKING_LEFT); setWalkingStatus(STATUS_WALKING_LEFT);
break; break;
case RIGHT: case Input::Action::RIGHT:
vel_x_ = base_speed_; vel_x_ = base_speed_;
setWalkingStatus(STATUS_WALKING_RIGHT); setWalkingStatus(STATUS_WALKING_RIGHT);
break; break;
case FIRE_CENTER: case Input::Action::FIRE_CENTER:
setFiringStatus(STATUS_FIRING_UP); setFiringStatus(STATUS_FIRING_UP);
break; break;
case FIRE_LEFT: case Input::Action::FIRE_LEFT:
setFiringStatus(STATUS_FIRING_LEFT); setFiringStatus(STATUS_FIRING_LEFT);
break; break;
case FIRE_RIGHT: case Input::Action::FIRE_RIGHT:
setFiringStatus(STATUS_FIRING_RIGHT); setFiringStatus(STATUS_FIRING_RIGHT);
break; break;
+2 -1
View File
@@ -6,6 +6,7 @@
#include <vector> // for vector #include <vector> // for vector
#include "utils/utils.h" // for Circle #include "utils/utils.h" // for Circle
#include "core/input/input.h" // for Input::Action
class AnimatedSprite; class AnimatedSprite;
class Texture; class Texture;
@@ -26,7 +27,7 @@ class Player {
void move(); // Mueve el jugador a la posición y animación que le corresponde void move(); // Mueve el jugador a la posición y animación que le corresponde
void setPlayerTextures(const std::vector<Texture *> &texture); // Pone las texturas del jugador void setPlayerTextures(const std::vector<Texture *> &texture); // Pone las texturas del jugador
void setInput(Uint8 input); // Actua en consecuencia de la entrada recibida void setInput(Input::Action input); // Actua en consecuencia de la entrada recibida
void setAnimation(); // Establece la animación correspondiente al estado void setAnimation(); // Establece la animación correspondiente al estado
[[nodiscard]] auto getPosX() const -> int; // Obtiene el valor de la variable [[nodiscard]] auto getPosX() const -> int; // Obtiene el valor de la variable
+20 -20
View File
@@ -9,7 +9,7 @@
#include "core/audio/audio.hpp" // for Audio #include "core/audio/audio.hpp" // for Audio
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle #include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for InputAction, Input, REPEAT_TRUE, REPEAT_FALSE #include "core/input/input.h" // for InputAction, Input, Input::Repeat::ON, Input::Repeat::OFF
#include "core/locale/lang.h" // for Lang #include "core/locale/lang.h" // for Lang
#include "core/rendering/fade.h" // for Fade, FADE_CENTER #include "core/rendering/fade.h" // for Fade, FADE_CENTER
#include "core/rendering/movingsprite.h" // for MovingSprite #include "core/rendering/movingsprite.h" // for MovingSprite
@@ -70,7 +70,7 @@ Game::Game(int num_players, int current_stage, SDL_Renderer *renderer, bool demo
#endif #endif
if (num_players == 1) { // Si solo juega un jugador, permite jugar tanto con teclado como con mando if (num_players == 1) { // Si solo juega un jugador, permite jugar tanto con teclado como con mando
player_one_control_ = Options::inputs[0].device_type; player_one_control_ = Options::inputs[0].device_type;
Options::inputs[0].device_type = INPUT_USE_ANY; Options::inputs[0].device_type = Input::Device::ANY;
} }
difficulty_ = Options::settings.difficulty; difficulty_ = Options::settings.difficulty;
@@ -2473,29 +2473,29 @@ void Game::processDemoInput() {
const DemoKeys &keys = demo_.data_file[demo_.counter]; const DemoKeys &keys = demo_.data_file[demo_.counter];
if (keys.left == 1) { if (keys.left == 1) {
players_[INDEX]->setInput(LEFT); players_[INDEX]->setInput(Input::Action::LEFT);
} }
if (keys.right == 1) { if (keys.right == 1) {
players_[INDEX]->setInput(RIGHT); players_[INDEX]->setInput(Input::Action::RIGHT);
} }
if (keys.no_input == 1) { if (keys.no_input == 1) {
players_[INDEX]->setInput(INVALID); players_[INDEX]->setInput(Input::Action::INVALID);
} }
if (keys.fire == 1 && players_[INDEX]->canFire()) { if (keys.fire == 1 && players_[INDEX]->canFire()) {
players_[INDEX]->setInput(FIRE_CENTER); players_[INDEX]->setInput(Input::Action::FIRE_CENTER);
createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::UP, players_[INDEX]->isPowerUp(), INDEX); createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::UP, players_[INDEX]->isPowerUp(), INDEX);
players_[INDEX]->setFireCooldown(10); players_[INDEX]->setFireCooldown(10);
} }
if (keys.fire_left == 1 && players_[INDEX]->canFire()) { if (keys.fire_left == 1 && players_[INDEX]->canFire()) {
players_[INDEX]->setInput(FIRE_LEFT); players_[INDEX]->setInput(Input::Action::FIRE_LEFT);
createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::LEFT, players_[INDEX]->isPowerUp(), INDEX); createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::LEFT, players_[INDEX]->isPowerUp(), INDEX);
players_[INDEX]->setFireCooldown(10); players_[INDEX]->setFireCooldown(10);
} }
if (keys.fire_right == 1 && players_[INDEX]->canFire()) { if (keys.fire_right == 1 && players_[INDEX]->canFire()) {
players_[INDEX]->setInput(FIRE_RIGHT); players_[INDEX]->setInput(Input::Action::FIRE_RIGHT);
createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::RIGHT, players_[INDEX]->isPowerUp(), INDEX); createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::RIGHT, players_[INDEX]->isPowerUp(), INDEX);
players_[INDEX]->setFireCooldown(10); players_[INDEX]->setFireCooldown(10);
} }
@@ -2531,20 +2531,20 @@ void Game::processPlayerLiveInput(Player *player, int i) {
const auto &device = Options::inputs[i]; const auto &device = Options::inputs[i];
// Movimiento izquierda / derecha / nada // Movimiento izquierda / derecha / nada
if (input->checkInput(LEFT, REPEAT_TRUE, device.device_type, device.id)) { if (input->checkInput(Input::Action::LEFT, Input::Repeat::ON, device.device_type, device.id)) {
player->setInput(LEFT); player->setInput(Input::Action::LEFT);
demo_.keys.left = 1; demo_.keys.left = 1;
} else if (input->checkInput(RIGHT, REPEAT_TRUE, device.device_type, device.id)) { } else if (input->checkInput(Input::Action::RIGHT, Input::Repeat::ON, device.device_type, device.id)) {
player->setInput(RIGHT); player->setInput(Input::Action::RIGHT);
demo_.keys.right = 1; demo_.keys.right = 1;
} else { } else {
player->setInput(INVALID); player->setInput(Input::Action::INVALID);
demo_.keys.no_input = 1; demo_.keys.no_input = 1;
} }
// Disparo al centro // Disparo al centro
if (input->checkInput(FIRE_CENTER, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) { if (input->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
player->setInput(FIRE_CENTER); player->setInput(Input::Action::FIRE_CENTER);
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::UP, player->isPowerUp(), i); createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::UP, player->isPowerUp(), i);
player->setFireCooldown(10); player->setFireCooldown(10);
Audio::get()->playSound(bullet_sound_); Audio::get()->playSound(bullet_sound_);
@@ -2552,8 +2552,8 @@ void Game::processPlayerLiveInput(Player *player, int i) {
} }
// Disparo a la izquierda // Disparo a la izquierda
if (input->checkInput(FIRE_LEFT, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) { if (input->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
player->setInput(FIRE_LEFT); player->setInput(Input::Action::FIRE_LEFT);
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::LEFT, player->isPowerUp(), i); createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::LEFT, player->isPowerUp(), i);
player->setFireCooldown(10); player->setFireCooldown(10);
Audio::get()->playSound(bullet_sound_); Audio::get()->playSound(bullet_sound_);
@@ -2561,8 +2561,8 @@ void Game::processPlayerLiveInput(Player *player, int i) {
} }
// Disparo a la derecha // Disparo a la derecha
if (input->checkInput(FIRE_RIGHT, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) { if (input->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
player->setInput(FIRE_RIGHT); player->setInput(Input::Action::FIRE_RIGHT);
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::RIGHT, player->isPowerUp(), i); createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::RIGHT, player->isPowerUp(), i);
player->setFireCooldown(10); player->setFireCooldown(10);
Audio::get()->playSound(bullet_sound_); Audio::get()->playSound(bullet_sound_);
@@ -2570,7 +2570,7 @@ void Game::processPlayerLiveInput(Player *player, int i) {
} }
// Pausa // Pausa
if (input->checkInput(PAUSE, REPEAT_FALSE, device.device_type, device.id)) { if (input->checkInput(Input::Action::PAUSE, Input::Repeat::OFF, device.device_type, device.id)) {
section_->subsection = SUBSECTION_GAME_PAUSE; section_->subsection = SUBSECTION_GAME_PAUSE;
} }
+1 -1
View File
@@ -372,7 +372,7 @@ class Game {
Uint8 difficulty_; // Dificultad del juego Uint8 difficulty_; // Dificultad del juego
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
Color difficulty_color_; // Color asociado a la dificultad Color difficulty_color_; // Color asociado a la dificultad
Uint8 player_one_control_; // Variable para almacenar el valor de las opciones Input::Device player_one_control_; // Variable para almacenar el valor de las opciones
EnemyFormation enemy_formation_[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas EnemyFormation enemy_formation_[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
EnemyPool enemy_pool_[10]; // Variable con los diferentes conjuntos de formaciones enemigas EnemyPool enemy_pool_[10]; // Variable con los diferentes conjuntos de formaciones enemigas
Uint8 last_stage_reached_; // Contiene el numero de la última pantalla que se ha alcanzado Uint8 last_stage_reached_; // Contiene el numero de la última pantalla que se ha alcanzado
+7 -7
View File
@@ -7,7 +7,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "core/input/input.h" // for INPUT_USE_KEYBOARD, INPUT_USE_GAMECONTROLLER #include "core/input/input.h" // for Input::Device::KEYBOARD, Input::Device::GAMECONTROLLER
#include "core/locale/lang.h" // for Lang::Code, Lang::MAX_LANGUAGES #include "core/locale/lang.h" // for Lang::Code, Lang::MAX_LANGUAGES
#include "external/fkyaml_node.hpp" // for fkyaml::node #include "external/fkyaml_node.hpp" // for fkyaml::node
#include "utils/utils.h" // for boolToString #include "utils/utils.h" // for boolToString
@@ -163,9 +163,9 @@ namespace Options {
size_t i = 0; size_t i = 0;
for (const auto &entry : ins) { for (const auto &entry : ins) {
if (i >= inputs.size()) { break; } if (i >= inputs.size()) { break; }
int device_type_int = inputs[i].device_type; int device_type_int = static_cast<int>(inputs[i].device_type);
if (tryGet<int>(entry, "device_type", device_type_int)) { if (tryGet<int>(entry, "device_type", device_type_int)) {
inputs[i].device_type = static_cast<Uint8>(device_type_int); inputs[i].device_type = static_cast<Input::Device>(device_type_int);
} }
++i; ++i;
} }
@@ -202,13 +202,13 @@ namespace Options {
InputDevice kb; InputDevice kb;
kb.id = 0; kb.id = 0;
kb.name = "KEYBOARD"; kb.name = "KEYBOARD";
kb.device_type = INPUT_USE_KEYBOARD; kb.device_type = Input::Device::KEYBOARD;
inputs.push_back(kb); inputs.push_back(kb);
InputDevice gc; InputDevice gc;
gc.id = 0; gc.id = 0;
gc.name = "GAME CONTROLLER"; gc.name = "GAME CONTROLLER";
gc.device_type = INPUT_USE_GAMECONTROLLER; gc.device_type = Input::Device::GAMECONTROLLER;
inputs.push_back(gc); inputs.push_back(gc);
} }
@@ -325,8 +325,8 @@ namespace Options {
// INPUT // INPUT
file << "# INPUT DEVICES (device_type: " file << "# INPUT DEVICES (device_type: "
<< static_cast<int>(INPUT_USE_KEYBOARD) << "=KEYBOARD, " << static_cast<int>(Input::Device::KEYBOARD) << "=KEYBOARD, "
<< static_cast<int>(INPUT_USE_GAMECONTROLLER) << "=GAMECONTROLLER)\n"; << static_cast<int>(Input::Device::GAMECONTROLLER) << "=GAMECONTROLLER)\n";
file << "input:\n"; file << "input:\n";
for (size_t i = 0; i < inputs.size(); ++i) { for (size_t i = 0; i < inputs.size(); ++i) {
file << " - slot: " << i << "\n"; file << " - slot: " << i << "\n";
+3 -3
View File
@@ -8,7 +8,7 @@
#include "core/audio/audio.hpp" // for Audio::update #include "core/audio/audio.hpp" // for Audio::update
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle #include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction #include "core/input/input.h" // for Input, Input::Repeat::OFF, InputAction
#include "core/locale/lang.h" // for Lang #include "core/locale/lang.h" // for Lang
#include "core/rendering/screen.h" // for Screen #include "core/rendering/screen.h" // for Screen
#include "core/rendering/sprite.h" // for Sprite #include "core/rendering/sprite.h" // for Sprite
@@ -211,7 +211,7 @@ void Instructions::checkEvents() {
// Comprueba las entradas // Comprueba las entradas
void Instructions::checkInput() { void Instructions::checkInput() {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
quit_requested_ = true; quit_requested_ = true;
finished_ = true; finished_ = true;
return; return;
@@ -219,7 +219,7 @@ void Instructions::checkInput() {
#endif #endif
if (GlobalInputs::handle()) { return; } if (GlobalInputs::handle()) { return; }
if (Input::get()->checkInput(PAUSE, REPEAT_FALSE) || Input::get()->checkInput(ACCEPT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_LEFT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_CENTER, REPEAT_FALSE) || Input::get()->checkInput(FIRE_RIGHT, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
if (mode_ == Mode::AUTO) { if (mode_ == Mode::AUTO) {
finished_ = true; finished_ = true;
} else { } else {
+3 -3
View File
@@ -6,7 +6,7 @@
#include "core/audio/audio.hpp" // for Audio::get, Audio::update #include "core/audio/audio.hpp" // for Audio::get, Audio::update
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle #include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction #include "core/input/input.h" // for Input, Input::Repeat::OFF, InputAction
#include "core/locale/lang.h" // for Lang #include "core/locale/lang.h" // for Lang
#include "core/rendering/screen.h" // for Screen #include "core/rendering/screen.h" // for Screen
#include "core/rendering/smartsprite.h" // for SmartSprite #include "core/rendering/smartsprite.h" // for SmartSprite
@@ -167,14 +167,14 @@ Intro::~Intro() {
// Comprueba las entradas // Comprueba las entradas
void Intro::checkInput() { void Intro::checkInput() {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
section_->name = SECTION_PROG_QUIT; section_->name = SECTION_PROG_QUIT;
return; return;
} }
#endif #endif
if (GlobalInputs::handle()) { return; } if (GlobalInputs::handle()) { return; }
if (Input::get()->checkInput(PAUSE, REPEAT_FALSE) || Input::get()->checkInput(ACCEPT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_LEFT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_CENTER, REPEAT_FALSE) || Input::get()->checkInput(FIRE_RIGHT, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
Audio::get()->stopMusic(); Audio::get()->stopMusic();
section_->name = SECTION_PROG_TITLE; section_->name = SECTION_PROG_TITLE;
section_->subsection = SUBSECTION_TITLE_1; section_->subsection = SUBSECTION_TITLE_1;
+3 -3
View File
@@ -7,7 +7,7 @@
#include "core/audio/audio.hpp" // for Audio::get, Audio::update #include "core/audio/audio.hpp" // for Audio::get, Audio::update
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle #include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction #include "core/input/input.h" // for Input, Input::Repeat::OFF, InputAction
#include "core/rendering/screen.h" // for Screen #include "core/rendering/screen.h" // for Screen
#include "core/rendering/sprite.h" // for Sprite #include "core/rendering/sprite.h" // for Sprite
#include "core/resources/resource.h" #include "core/resources/resource.h"
@@ -57,14 +57,14 @@ void Logo::checkLogoEnd() {
// Comprueba las entradas // Comprueba las entradas
void Logo::checkInput() { void Logo::checkInput() {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
section_->name = SECTION_PROG_QUIT; section_->name = SECTION_PROG_QUIT;
return; return;
} }
#endif #endif
if (GlobalInputs::handle()) { return; } if (GlobalInputs::handle()) { return; }
if (Input::get()->checkInput(PAUSE, REPEAT_FALSE) || Input::get()->checkInput(ACCEPT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_LEFT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_CENTER, REPEAT_FALSE) || Input::get()->checkInput(FIRE_RIGHT, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
section_->name = SECTION_PROG_TITLE; section_->name = SECTION_PROG_TITLE;
section_->subsection = SUBSECTION_TITLE_1; section_->subsection = SUBSECTION_TITLE_1;
} }
+12 -12
View File
@@ -8,7 +8,7 @@
#include "core/audio/audio.hpp" // for Audio #include "core/audio/audio.hpp" // for Audio
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle #include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for Input, INPUT_USE_GAMECONTROLLER, INPUT_... #include "core/input/input.h" // for Input, Input::Device::GAMECONTROLLER, INPUT_...
#include "core/locale/lang.h" // for Lang, Lang::Code #include "core/locale/lang.h" // for Lang, Lang::Code
#include "core/rendering/animatedsprite.h" // for AnimatedSprite #include "core/rendering/animatedsprite.h" // for AnimatedSprite
#include "core/rendering/fade.h" // for Fade #include "core/rendering/fade.h" // for Fade
@@ -115,12 +115,12 @@ void Title::init() {
InputDevice inp; InputDevice inp;
inp.id = 0; inp.id = 0;
inp.name = "KEYBOARD"; inp.name = "KEYBOARD";
inp.device_type = INPUT_USE_KEYBOARD; inp.device_type = Input::Device::KEYBOARD;
Options::inputs.push_back(inp); Options::inputs.push_back(inp);
inp.id = 0; inp.id = 0;
inp.name = "GAME CONTROLLER"; inp.name = "GAME CONTROLLER";
inp.device_type = INPUT_USE_GAMECONTROLLER; inp.device_type = Input::Device::GAMECONTROLLER;
Options::inputs.push_back(inp); Options::inputs.push_back(inp);
// Comprueba si hay mandos conectados // Comprueba si hay mandos conectados
@@ -622,7 +622,7 @@ void Title::render() {
// Comprueba las entradas // Comprueba las entradas
void Title::checkInput() { void Title::checkInput() {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
section_->name = SECTION_PROG_QUIT; section_->name = SECTION_PROG_QUIT;
return; return;
} }
@@ -676,12 +676,12 @@ void Title::updateMenuLabels() const {
i++; i++;
// PLAYER 1 CONTROLS - OPTIONS // PLAYER 1 CONTROLS - OPTIONS
switch (Options::inputs[0].device_type) { switch (Options::inputs[0].device_type) {
case INPUT_USE_KEYBOARD: case Input::Device::KEYBOARD:
menu_.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD menu_.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD
menu_.options->setGreyed(i, false); menu_.options->setGreyed(i, false);
break; break;
case INPUT_USE_GAMECONTROLLER: case Input::Device::GAMECONTROLLER:
menu_.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER menu_.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
if (!Input::get()->gameControllerFound()) { if (!Input::get()->gameControllerFound()) {
menu_.options->setGreyed(i, true); menu_.options->setGreyed(i, true);
@@ -703,12 +703,12 @@ void Title::updateMenuLabels() const {
i++; i++;
// PLAYER 2 CONTROLS - OPTIONS // PLAYER 2 CONTROLS - OPTIONS
switch (Options::inputs[1].device_type) { switch (Options::inputs[1].device_type) {
case INPUT_USE_KEYBOARD: case Input::Device::KEYBOARD:
menu_.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD menu_.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD
menu_.options->setGreyed(i, false); menu_.options->setGreyed(i, false);
break; break;
case INPUT_USE_GAMECONTROLLER: case Input::Device::GAMECONTROLLER:
menu_.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER menu_.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
if (!Input::get()->gameControllerFound()) { if (!Input::get()->gameControllerFound()) {
menu_.options->setGreyed(i, true); menu_.options->setGreyed(i, true);
@@ -963,11 +963,11 @@ auto Title::updatePlayerInputs(int num_player) -> bool {
Options::inputs[0].id = -1; Options::inputs[0].id = -1;
Options::inputs[0].name = "KEYBOARD"; Options::inputs[0].name = "KEYBOARD";
Options::inputs[0].device_type = INPUT_USE_KEYBOARD; Options::inputs[0].device_type = Input::Device::KEYBOARD;
Options::inputs[1].id = 0; Options::inputs[1].id = 0;
Options::inputs[1].name = "GAME CONTROLLER"; Options::inputs[1].name = "GAME CONTROLLER";
Options::inputs[1].device_type = INPUT_USE_GAMECONTROLLER; Options::inputs[1].device_type = Input::Device::GAMECONTROLLER;
return true; return true;
} // Si hay mas de un dispositivo, se recorre el vector } // Si hay mas de un dispositivo, se recorre el vector
@@ -1059,7 +1059,7 @@ void Title::checkInputDevices() {
for (int i = 0; i < NUM_CONTROLLERS; ++i) { for (int i = 0; i < NUM_CONTROLLERS; ++i) {
temp.id = i; temp.id = i;
temp.name = Input::get()->getControllerName(i); temp.name = Input::get()->getControllerName(i);
temp.device_type = INPUT_USE_GAMECONTROLLER; temp.device_type = Input::Device::GAMECONTROLLER;
available_input_devices_.push_back(temp); available_input_devices_.push_back(temp);
if (Options::settings.console) { if (Options::settings.console) {
std::cout << "Device " << (int)available_input_devices_.size() << " - " << temp.name.c_str() << '\n'; std::cout << "Device " << (int)available_input_devices_.size() << " - " << temp.name.c_str() << '\n';
@@ -1070,7 +1070,7 @@ void Title::checkInputDevices() {
// Añade el teclado al final // Añade el teclado al final
temp.id = -1; temp.id = -1;
temp.name = "KEYBOARD"; temp.name = "KEYBOARD";
temp.device_type = INPUT_USE_KEYBOARD; temp.device_type = Input::Device::KEYBOARD;
available_input_devices_.push_back(temp); available_input_devices_.push_back(temp);
if (Options::settings.console) { if (Options::settings.console) {
std::cout << "Device " << (int)available_input_devices_.size() << " - " << temp.name.c_str() << '\n'; std::cout << "Device " << (int)available_input_devices_.size() << " - " << temp.name.c_str() << '\n';
+5 -5
View File
@@ -6,7 +6,7 @@
#include "core/audio/audio.hpp" // for Audio::get (playSound) #include "core/audio/audio.hpp" // for Audio::get (playSound)
#include "core/audio/jail_audio.hpp" // for Ja::loadSound, Ja::deleteSound (propietat local) #include "core/audio/jail_audio.hpp" // for Ja::loadSound, Ja::deleteSound (propietat local)
#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction #include "core/input/input.h" // for Input, Input::Repeat::OFF, InputAction
#include "core/rendering/text.h" // for Text #include "core/rendering/text.h" // for Text
#include "core/resources/asset.h" // for Asset #include "core/resources/asset.h" // for Asset
#include "core/resources/resource_helper.h" #include "core/resources/resource_helper.h"
@@ -740,28 +740,28 @@ void Menu::setDefaultActionWhenCancel(int item) {
// Gestiona la entrada de teclado y mando durante el menu // Gestiona la entrada de teclado y mando durante el menu
void Menu::checkInput() { void Menu::checkInput() {
if (Input::get()->checkInput(UP, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::UP, Input::Repeat::OFF)) {
decreaseSelectorIndex(); decreaseSelectorIndex();
if (sound_move_ != nullptr) { if (sound_move_ != nullptr) {
Audio::get()->playSound(sound_move_); Audio::get()->playSound(sound_move_);
} }
} }
if (Input::get()->checkInput(DOWN, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::DOWN, Input::Repeat::OFF)) {
increaseSelectorIndex(); increaseSelectorIndex();
if (sound_move_ != nullptr) { if (sound_move_ != nullptr) {
Audio::get()->playSound(sound_move_); Audio::get()->playSound(sound_move_);
} }
} }
if (Input::get()->checkInput(ACCEPT, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF)) {
item_selected_ = selector_.index; item_selected_ = selector_.index;
if (sound_accept_ != nullptr) { if (sound_accept_ != nullptr) {
Audio::get()->playSound(sound_accept_); Audio::get()->playSound(sound_accept_);
} }
} }
if (Input::get()->checkInput(CANCEL, REPEAT_FALSE)) { if (Input::get()->checkInput(Input::Action::CANCEL, Input::Repeat::OFF)) {
item_selected_ = default_action_when_cancel_; item_selected_ = default_action_when_cancel_;
if (sound_cancel_ != nullptr) { if (sound_cancel_ != nullptr) {
Audio::get()->playSound(sound_cancel_); Audio::get()->playSound(sound_cancel_);
+5 -3
View File
@@ -4,6 +4,8 @@
#include <string> // for string, basic_string #include <string> // for string, basic_string
#include "core/input/input.h" // for Input::Device
// Dificultad del juego // Dificultad del juego
constexpr int DIFFICULTY_EASY = 0; constexpr int DIFFICULTY_EASY = 0;
constexpr int DIFFICULTY_NORMAL = 1; constexpr int DIFFICULTY_NORMAL = 1;
@@ -70,9 +72,9 @@ struct DemoKeys {
// Estructura para albergar métodos de control // Estructura para albergar métodos de control
struct InputDevice { struct InputDevice {
int id; // Identificador en el vector de mandos int id; // Identificador en el vector de mandos
std::string name; // Nombre del dispositivo std::string name; // Nombre del dispositivo
Uint8 device_type; // Tipo de dispositivo (teclado o mando) Input::Device device_type; // Tipo de dispositivo (teclado o mando)
}; };
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos