Merge branch 'refactor/input-enum-class'
This commit is contained in:
@@ -8,29 +8,29 @@ namespace GlobalInputs {
|
||||
auto handle() -> bool {
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
if (Input::get()->checkInput(TOGGLE_SHADER, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(Input::Action::TOGGLE_SHADER, Input::Repeat::OFF)) {
|
||||
Screen::get()->toggleShaderEnabled();
|
||||
return true;
|
||||
}
|
||||
// F5/F6 només actuen quan el post-procesado està actiu.
|
||||
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();
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
|
||||
+29
-27
@@ -65,12 +65,12 @@ Input::Input(std::string file)
|
||||
KeyBindings kb;
|
||||
kb.scancode = 0;
|
||||
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;
|
||||
gcb.button = SDL_GAMEPAD_BUTTON_INVALID;
|
||||
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
|
||||
@@ -88,38 +88,38 @@ Input::~Input() {
|
||||
|
||||
// Actualiza el estado del objeto
|
||||
void Input::update() {
|
||||
if (disabled_until_ == KEY_PRESSED && !checkAnyInput()) {
|
||||
if (disabled_until_ == Disable::KEY_PRESSED && !checkAnyInput()) {
|
||||
enable();
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void Input::bindKey(Uint8 input, SDL_Scancode code) {
|
||||
key_bindings_[input].scancode = code;
|
||||
void Input::bindKey(Action input, SDL_Scancode code) {
|
||||
key_bindings_[static_cast<std::size_t>(input)].scancode = code;
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(Uint8 input, SDL_GamepadButton button) {
|
||||
game_controller_bindings_[input].button = button;
|
||||
void Input::bindGameControllerButton(Action input, SDL_GamepadButton button) {
|
||||
game_controller_bindings_[static_cast<std::size_t>(input)].button = button;
|
||||
}
|
||||
|
||||
// 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_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_ANY) {
|
||||
if (device == Device::ANY) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
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 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
key_bindings_[input].active = IS_DOWN;
|
||||
const bool PRESS_EDGE = IS_DOWN && !key_bindings_[IDX].active;
|
||||
key_bindings_[IDX].active = IS_DOWN;
|
||||
return PRESS_EDGE;
|
||||
}
|
||||
|
||||
// Helper de checkInput: comprueba el estado de un botón de mando
|
||||
auto Input::checkGameControllerInput(Uint8 input, bool repeat, int index) -> bool {
|
||||
const bool IS_DOWN = SDL_GetGamepadButton(connected_controllers_[index], game_controller_bindings_[input].button);
|
||||
auto Input::checkGameControllerInput(Action input, Repeat repeat, int index) -> bool {
|
||||
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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
game_controller_bindings_[input].active = IS_DOWN;
|
||||
const bool PRESS_EDGE = IS_DOWN && !game_controller_bindings_[IDX].active;
|
||||
game_controller_bindings_[IDX].active = IS_DOWN;
|
||||
return PRESS_EDGE;
|
||||
}
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
auto Input::checkAnyInput(int device, int index) -> bool {
|
||||
if (device == INPUT_USE_ANY) {
|
||||
auto Input::checkAnyInput(Device device, int index) -> bool {
|
||||
if (device == Device::ANY) {
|
||||
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);
|
||||
|
||||
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 (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY) {
|
||||
if (device == Device::GAMECONTROLLER || device == Device::ANY) {
|
||||
for (auto &game_controller_binding : game_controller_bindings_) {
|
||||
if (SDL_GetGamepadButton(connected_controllers_[index], game_controller_binding.button)) {
|
||||
return true;
|
||||
@@ -376,7 +378,7 @@ void Input::setVerbose(bool value) {
|
||||
}
|
||||
|
||||
// Deshabilita las entradas durante un periodo de tiempo
|
||||
void Input::disableUntil(InputDisable value) {
|
||||
void Input::disableUntil(Disable value) {
|
||||
disabled_until_ = value;
|
||||
enabled_ = false;
|
||||
}
|
||||
@@ -384,5 +386,5 @@ void Input::disableUntil(InputDisable value) {
|
||||
// Hablita las entradas
|
||||
void Input::enable() {
|
||||
enabled_ = true;
|
||||
disabled_until_ = NOT_DISABLED;
|
||||
disabled_until_ = Disable::NOT_DISABLED;
|
||||
}
|
||||
|
||||
+54
-52
@@ -6,52 +6,54 @@
|
||||
#include <string> // for string, basic_string
|
||||
#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 {
|
||||
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
|
||||
static void init(const std::string &game_controller_db_path); // Crea la instancia
|
||||
static void destroy(); // Libera la instancia
|
||||
@@ -60,11 +62,11 @@ class Input {
|
||||
~Input(); // Destructor
|
||||
|
||||
void update(); // Actualiza el estado del objeto
|
||||
void bindKey(Uint8 input, SDL_Scancode code); // Asigna inputs a teclas
|
||||
void bindGameControllerButton(Uint8 input, SDL_GamepadButton button); // Asigna inputs a botones del mando
|
||||
void bindKey(Action input, SDL_Scancode code); // Asigna inputs a teclas
|
||||
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 checkAnyInput(int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si hay almenos un input 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(Device device = Device::ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
private:
|
||||
@@ -106,7 +108,7 @@ class Input {
|
||||
int num_gamepads_{0}; // Numero de mandos conectados
|
||||
std::string db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||
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
|
||||
|
||||
static Input *instance; // Instancia única
|
||||
@@ -117,8 +119,8 @@ class Input {
|
||||
static auto buildControllerName(SDL_Gamepad *pad, int pad_index) -> std::string;
|
||||
|
||||
// Helpers de checkInput
|
||||
auto checkKeyboardInput(Uint8 input, bool repeat) -> bool;
|
||||
auto checkGameControllerInput(Uint8 input, bool repeat, int index) -> bool;
|
||||
auto checkKeyboardInput(Action input, Repeat repeat) -> bool;
|
||||
auto checkGameControllerInput(Action input, Repeat repeat, int index) -> bool;
|
||||
|
||||
// Helpers de discoverGameController
|
||||
void resetGameControllerState();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <string> // for basic_string, operator+, char_t...
|
||||
|
||||
#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/locale/lang.h" // for Lang, Lang::Code
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
@@ -208,44 +208,44 @@ void Director::initInput() {
|
||||
Input::get()->discoverGameController();
|
||||
|
||||
// Teclado - Movimiento del jugador
|
||||
Input::get()->bindKey(UP, SDL_SCANCODE_UP);
|
||||
Input::get()->bindKey(DOWN, SDL_SCANCODE_DOWN);
|
||||
Input::get()->bindKey(LEFT, SDL_SCANCODE_LEFT);
|
||||
Input::get()->bindKey(RIGHT, SDL_SCANCODE_RIGHT);
|
||||
Input::get()->bindKey(FIRE_LEFT, SDL_SCANCODE_Q);
|
||||
Input::get()->bindKey(FIRE_CENTER, SDL_SCANCODE_W);
|
||||
Input::get()->bindKey(FIRE_RIGHT, SDL_SCANCODE_E);
|
||||
Input::get()->bindKey(Input::Action::UP, SDL_SCANCODE_UP);
|
||||
Input::get()->bindKey(Input::Action::DOWN, SDL_SCANCODE_DOWN);
|
||||
Input::get()->bindKey(Input::Action::LEFT, SDL_SCANCODE_LEFT);
|
||||
Input::get()->bindKey(Input::Action::RIGHT, SDL_SCANCODE_RIGHT);
|
||||
Input::get()->bindKey(Input::Action::FIRE_LEFT, SDL_SCANCODE_Q);
|
||||
Input::get()->bindKey(Input::Action::FIRE_CENTER, SDL_SCANCODE_W);
|
||||
Input::get()->bindKey(Input::Action::FIRE_RIGHT, SDL_SCANCODE_E);
|
||||
|
||||
// Teclado - Otros
|
||||
Input::get()->bindKey(ACCEPT, SDL_SCANCODE_RETURN);
|
||||
Input::get()->bindKey(CANCEL, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(PAUSE, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(EXIT, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(WINDOW_DEC_ZOOM, SDL_SCANCODE_F1);
|
||||
Input::get()->bindKey(WINDOW_INC_ZOOM, SDL_SCANCODE_F2);
|
||||
Input::get()->bindKey(WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
|
||||
Input::get()->bindKey(TOGGLE_SHADER, SDL_SCANCODE_F4);
|
||||
Input::get()->bindKey(TOGGLE_SHADER_TYPE, SDL_SCANCODE_F5);
|
||||
Input::get()->bindKey(NEXT_SHADER_PRESET, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(Input::Action::ACCEPT, SDL_SCANCODE_RETURN);
|
||||
Input::get()->bindKey(Input::Action::CANCEL, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(Input::Action::PAUSE, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(Input::Action::EXIT, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(Input::Action::WINDOW_DEC_ZOOM, SDL_SCANCODE_F1);
|
||||
Input::get()->bindKey(Input::Action::WINDOW_INC_ZOOM, SDL_SCANCODE_F2);
|
||||
Input::get()->bindKey(Input::Action::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
|
||||
Input::get()->bindKey(Input::Action::TOGGLE_SHADER, SDL_SCANCODE_F4);
|
||||
Input::get()->bindKey(Input::Action::TOGGLE_SHADER_TYPE, SDL_SCANCODE_F5);
|
||||
Input::get()->bindKey(Input::Action::NEXT_SHADER_PRESET, SDL_SCANCODE_F6);
|
||||
|
||||
// Mando - Movimiento del jugador
|
||||
Input::get()->bindGameControllerButton(UP, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
||||
Input::get()->bindGameControllerButton(DOWN, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
|
||||
Input::get()->bindGameControllerButton(LEFT, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
|
||||
Input::get()->bindGameControllerButton(RIGHT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
||||
Input::get()->bindGameControllerButton(FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST);
|
||||
Input::get()->bindGameControllerButton(FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH);
|
||||
Input::get()->bindGameControllerButton(FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST);
|
||||
Input::get()->bindGameControllerButton(Input::Action::UP, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
||||
Input::get()->bindGameControllerButton(Input::Action::DOWN, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
|
||||
Input::get()->bindGameControllerButton(Input::Action::LEFT, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
|
||||
Input::get()->bindGameControllerButton(Input::Action::RIGHT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
||||
Input::get()->bindGameControllerButton(Input::Action::FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST);
|
||||
Input::get()->bindGameControllerButton(Input::Action::FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH);
|
||||
Input::get()->bindGameControllerButton(Input::Action::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST);
|
||||
|
||||
// Mando - Otros
|
||||
// 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
|
||||
Input::get()->bindGameControllerButton(input_pause, SDL_GAMEPAD_BUTTON_BACK);
|
||||
Input::get()->bindGameControllerButton(input_exit, SDL_GAMEPAD_BUTTON_START);
|
||||
#else
|
||||
Input::get()->bindGameControllerButton(PAUSE, SDL_GAMEPAD_BUTTON_START);
|
||||
Input::get()->bindGameControllerButton(EXIT, SDL_GAMEPAD_BUTTON_BACK);
|
||||
Input::get()->bindGameControllerButton(Input::Action::PAUSE, SDL_GAMEPAD_BUTTON_START);
|
||||
Input::get()->bindGameControllerButton(Input::Action::EXIT, SDL_GAMEPAD_BUTTON_BACK);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -95,27 +95,27 @@ void Player::init() {
|
||||
}
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void Player::setInput(Uint8 input) {
|
||||
void Player::setInput(Input::Action input) {
|
||||
switch (input) {
|
||||
case LEFT:
|
||||
case Input::Action::LEFT:
|
||||
vel_x_ = -base_speed_;
|
||||
setWalkingStatus(STATUS_WALKING_LEFT);
|
||||
break;
|
||||
|
||||
case RIGHT:
|
||||
case Input::Action::RIGHT:
|
||||
vel_x_ = base_speed_;
|
||||
setWalkingStatus(STATUS_WALKING_RIGHT);
|
||||
break;
|
||||
|
||||
case FIRE_CENTER:
|
||||
case Input::Action::FIRE_CENTER:
|
||||
setFiringStatus(STATUS_FIRING_UP);
|
||||
break;
|
||||
|
||||
case FIRE_LEFT:
|
||||
case Input::Action::FIRE_LEFT:
|
||||
setFiringStatus(STATUS_FIRING_LEFT);
|
||||
break;
|
||||
|
||||
case FIRE_RIGHT:
|
||||
case Input::Action::FIRE_RIGHT:
|
||||
setFiringStatus(STATUS_FIRING_RIGHT);
|
||||
break;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "utils/utils.h" // for Circle
|
||||
#include "core/input/input.h" // for Input::Action
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
@@ -26,7 +27,7 @@ class Player {
|
||||
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 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
|
||||
|
||||
[[nodiscard]] auto getPosX() const -> int; // Obtiene el valor de la variable
|
||||
|
||||
+20
-20
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio
|
||||
#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/rendering/fade.h" // for Fade, FADE_CENTER
|
||||
#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
|
||||
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;
|
||||
Options::inputs[0].device_type = INPUT_USE_ANY;
|
||||
Options::inputs[0].device_type = Input::Device::ANY;
|
||||
}
|
||||
difficulty_ = Options::settings.difficulty;
|
||||
|
||||
@@ -2473,29 +2473,29 @@ void Game::processDemoInput() {
|
||||
const DemoKeys &keys = demo_.data_file[demo_.counter];
|
||||
|
||||
if (keys.left == 1) {
|
||||
players_[INDEX]->setInput(LEFT);
|
||||
players_[INDEX]->setInput(Input::Action::LEFT);
|
||||
}
|
||||
if (keys.right == 1) {
|
||||
players_[INDEX]->setInput(RIGHT);
|
||||
players_[INDEX]->setInput(Input::Action::RIGHT);
|
||||
}
|
||||
if (keys.no_input == 1) {
|
||||
players_[INDEX]->setInput(INVALID);
|
||||
players_[INDEX]->setInput(Input::Action::INVALID);
|
||||
}
|
||||
|
||||
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);
|
||||
players_[INDEX]->setFireCooldown(10);
|
||||
}
|
||||
|
||||
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);
|
||||
players_[INDEX]->setFireCooldown(10);
|
||||
}
|
||||
|
||||
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);
|
||||
players_[INDEX]->setFireCooldown(10);
|
||||
}
|
||||
@@ -2531,20 +2531,20 @@ void Game::processPlayerLiveInput(Player *player, int i) {
|
||||
const auto &device = Options::inputs[i];
|
||||
|
||||
// Movimiento izquierda / derecha / nada
|
||||
if (input->checkInput(LEFT, REPEAT_TRUE, device.device_type, device.id)) {
|
||||
player->setInput(LEFT);
|
||||
if (input->checkInput(Input::Action::LEFT, Input::Repeat::ON, device.device_type, device.id)) {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
demo_.keys.left = 1;
|
||||
} else if (input->checkInput(RIGHT, REPEAT_TRUE, device.device_type, device.id)) {
|
||||
player->setInput(RIGHT);
|
||||
} else if (input->checkInput(Input::Action::RIGHT, Input::Repeat::ON, device.device_type, device.id)) {
|
||||
player->setInput(Input::Action::RIGHT);
|
||||
demo_.keys.right = 1;
|
||||
} else {
|
||||
player->setInput(INVALID);
|
||||
player->setInput(Input::Action::INVALID);
|
||||
demo_.keys.no_input = 1;
|
||||
}
|
||||
|
||||
// Disparo al centro
|
||||
if (input->checkInput(FIRE_CENTER, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(FIRE_CENTER);
|
||||
if (input->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(Input::Action::FIRE_CENTER);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::UP, player->isPowerUp(), i);
|
||||
player->setFireCooldown(10);
|
||||
Audio::get()->playSound(bullet_sound_);
|
||||
@@ -2552,8 +2552,8 @@ void Game::processPlayerLiveInput(Player *player, int i) {
|
||||
}
|
||||
|
||||
// Disparo a la izquierda
|
||||
if (input->checkInput(FIRE_LEFT, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(FIRE_LEFT);
|
||||
if (input->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(Input::Action::FIRE_LEFT);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::LEFT, player->isPowerUp(), i);
|
||||
player->setFireCooldown(10);
|
||||
Audio::get()->playSound(bullet_sound_);
|
||||
@@ -2561,8 +2561,8 @@ void Game::processPlayerLiveInput(Player *player, int i) {
|
||||
}
|
||||
|
||||
// Disparo a la derecha
|
||||
if (input->checkInput(FIRE_RIGHT, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(FIRE_RIGHT);
|
||||
if (input->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(Input::Action::FIRE_RIGHT);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::RIGHT, player->isPowerUp(), i);
|
||||
player->setFireCooldown(10);
|
||||
Audio::get()->playSound(bullet_sound_);
|
||||
@@ -2570,7 +2570,7 @@ void Game::processPlayerLiveInput(Player *player, int i) {
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -372,7 +372,7 @@ class Game {
|
||||
Uint8 difficulty_; // Dificultad del juego
|
||||
float difficulty_score_multiplier_; // Multiplicador de puntos en función de 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
|
||||
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
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <iostream>
|
||||
#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 "external/fkyaml_node.hpp" // for fkyaml::node
|
||||
#include "utils/utils.h" // for boolToString
|
||||
@@ -163,9 +163,9 @@ namespace Options {
|
||||
size_t i = 0;
|
||||
for (const auto &entry : ins) {
|
||||
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)) {
|
||||
inputs[i].device_type = static_cast<Uint8>(device_type_int);
|
||||
inputs[i].device_type = static_cast<Input::Device>(device_type_int);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@@ -202,13 +202,13 @@ namespace Options {
|
||||
InputDevice kb;
|
||||
kb.id = 0;
|
||||
kb.name = "KEYBOARD";
|
||||
kb.device_type = INPUT_USE_KEYBOARD;
|
||||
kb.device_type = Input::Device::KEYBOARD;
|
||||
inputs.push_back(kb);
|
||||
|
||||
InputDevice gc;
|
||||
gc.id = 0;
|
||||
gc.name = "GAME CONTROLLER";
|
||||
gc.device_type = INPUT_USE_GAMECONTROLLER;
|
||||
gc.device_type = Input::Device::GAMECONTROLLER;
|
||||
inputs.push_back(gc);
|
||||
}
|
||||
|
||||
@@ -325,8 +325,8 @@ namespace Options {
|
||||
|
||||
// INPUT
|
||||
file << "# INPUT DEVICES (device_type: "
|
||||
<< static_cast<int>(INPUT_USE_KEYBOARD) << "=KEYBOARD, "
|
||||
<< static_cast<int>(INPUT_USE_GAMECONTROLLER) << "=GAMECONTROLLER)\n";
|
||||
<< static_cast<int>(Input::Device::KEYBOARD) << "=KEYBOARD, "
|
||||
<< static_cast<int>(Input::Device::GAMECONTROLLER) << "=GAMECONTROLLER)\n";
|
||||
file << "input:\n";
|
||||
for (size_t i = 0; i < inputs.size(); ++i) {
|
||||
file << " - slot: " << i << "\n";
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio::update
|
||||
#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/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/sprite.h" // for Sprite
|
||||
@@ -211,7 +211,7 @@ void Instructions::checkEvents() {
|
||||
// Comprueba las entradas
|
||||
void Instructions::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
||||
quit_requested_ = true;
|
||||
finished_ = true;
|
||||
return;
|
||||
@@ -219,7 +219,7 @@ void Instructions::checkInput() {
|
||||
#endif
|
||||
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) {
|
||||
finished_ = true;
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio::get, Audio::update
|
||||
#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/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/smartsprite.h" // for SmartSprite
|
||||
@@ -167,14 +167,14 @@ Intro::~Intro() {
|
||||
// Comprueba las entradas
|
||||
void Intro::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
||||
section_->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
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();
|
||||
section_->name = SECTION_PROG_TITLE;
|
||||
section_->subsection = SUBSECTION_TITLE_1;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio::get, Audio::update
|
||||
#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/sprite.h" // for Sprite
|
||||
#include "core/resources/resource.h"
|
||||
@@ -57,14 +57,14 @@ void Logo::checkLogoEnd() {
|
||||
// Comprueba las entradas
|
||||
void Logo::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
||||
section_->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
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_->subsection = SUBSECTION_TITLE_1;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio
|
||||
#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/rendering/animatedsprite.h" // for AnimatedSprite
|
||||
#include "core/rendering/fade.h" // for Fade
|
||||
@@ -115,12 +115,12 @@ void Title::init() {
|
||||
InputDevice inp;
|
||||
inp.id = 0;
|
||||
inp.name = "KEYBOARD";
|
||||
inp.device_type = INPUT_USE_KEYBOARD;
|
||||
inp.device_type = Input::Device::KEYBOARD;
|
||||
Options::inputs.push_back(inp);
|
||||
|
||||
inp.id = 0;
|
||||
inp.name = "GAME CONTROLLER";
|
||||
inp.device_type = INPUT_USE_GAMECONTROLLER;
|
||||
inp.device_type = Input::Device::GAMECONTROLLER;
|
||||
Options::inputs.push_back(inp);
|
||||
|
||||
// Comprueba si hay mandos conectados
|
||||
@@ -622,7 +622,7 @@ void Title::render() {
|
||||
// Comprueba las entradas
|
||||
void Title::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
||||
section_->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
@@ -676,12 +676,12 @@ void Title::updateMenuLabels() const {
|
||||
i++;
|
||||
// PLAYER 1 CONTROLS - OPTIONS
|
||||
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->setGreyed(i, false);
|
||||
break;
|
||||
|
||||
case INPUT_USE_GAMECONTROLLER:
|
||||
case Input::Device::GAMECONTROLLER:
|
||||
menu_.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
|
||||
if (!Input::get()->gameControllerFound()) {
|
||||
menu_.options->setGreyed(i, true);
|
||||
@@ -703,12 +703,12 @@ void Title::updateMenuLabels() const {
|
||||
i++;
|
||||
// PLAYER 2 CONTROLS - OPTIONS
|
||||
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->setGreyed(i, false);
|
||||
break;
|
||||
|
||||
case INPUT_USE_GAMECONTROLLER:
|
||||
case Input::Device::GAMECONTROLLER:
|
||||
menu_.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
|
||||
if (!Input::get()->gameControllerFound()) {
|
||||
menu_.options->setGreyed(i, true);
|
||||
@@ -963,11 +963,11 @@ auto Title::updatePlayerInputs(int num_player) -> bool {
|
||||
|
||||
Options::inputs[0].id = -1;
|
||||
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].name = "GAME CONTROLLER";
|
||||
Options::inputs[1].device_type = INPUT_USE_GAMECONTROLLER;
|
||||
Options::inputs[1].device_type = Input::Device::GAMECONTROLLER;
|
||||
|
||||
return true;
|
||||
} // 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) {
|
||||
temp.id = 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);
|
||||
if (Options::settings.console) {
|
||||
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
|
||||
temp.id = -1;
|
||||
temp.name = "KEYBOARD";
|
||||
temp.device_type = INPUT_USE_KEYBOARD;
|
||||
temp.device_type = Input::Device::KEYBOARD;
|
||||
available_input_devices_.push_back(temp);
|
||||
if (Options::settings.console) {
|
||||
std::cout << "Device " << (int)available_input_devices_.size() << " - " << temp.name.c_str() << '\n';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio::get (playSound)
|
||||
#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/resources/asset.h" // for Asset
|
||||
#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
|
||||
void Menu::checkInput() {
|
||||
if (Input::get()->checkInput(UP, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(Input::Action::UP, Input::Repeat::OFF)) {
|
||||
decreaseSelectorIndex();
|
||||
if (sound_move_ != nullptr) {
|
||||
Audio::get()->playSound(sound_move_);
|
||||
}
|
||||
}
|
||||
|
||||
if (Input::get()->checkInput(DOWN, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(Input::Action::DOWN, Input::Repeat::OFF)) {
|
||||
increaseSelectorIndex();
|
||||
if (sound_move_ != nullptr) {
|
||||
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;
|
||||
if (sound_accept_ != nullptr) {
|
||||
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_;
|
||||
if (sound_cancel_ != nullptr) {
|
||||
Audio::get()->playSound(sound_cancel_);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <string> // for string, basic_string
|
||||
|
||||
#include "core/input/input.h" // for Input::Device
|
||||
|
||||
// Dificultad del juego
|
||||
constexpr int DIFFICULTY_EASY = 0;
|
||||
constexpr int DIFFICULTY_NORMAL = 1;
|
||||
@@ -70,9 +72,9 @@ struct DemoKeys {
|
||||
|
||||
// Estructura para albergar métodos de control
|
||||
struct InputDevice {
|
||||
int id; // Identificador en el vector de mandos
|
||||
std::string name; // Nombre del dispositivo
|
||||
Uint8 device_type; // Tipo de dispositivo (teclado o mando)
|
||||
int id; // Identificador en el vector de mandos
|
||||
std::string name; // Nombre del dispositivo
|
||||
Input::Device device_type; // Tipo de dispositivo (teclado o mando)
|
||||
};
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
|
||||
Reference in New Issue
Block a user