migrant input: ja funcionen coses, pero encara queda
This commit is contained in:
@@ -24,6 +24,9 @@ class Input {
|
||||
static constexpr bool ALLOW_REPEAT = true;
|
||||
static constexpr bool DO_NOT_ALLOW_REPEAT = false;
|
||||
|
||||
static constexpr bool CHECK_KEYBOARD = true;
|
||||
static constexpr bool DO_NOT_CHECK_KEYBOARD = false;
|
||||
|
||||
// Acciones de entrada posibles en el juego
|
||||
enum class Action : int {
|
||||
// Inputs de movimiento
|
||||
@@ -66,13 +69,6 @@ class Input {
|
||||
SIZE,
|
||||
};
|
||||
|
||||
// Tipos de dispositivos de entrada
|
||||
enum class Device : int {
|
||||
KEYBOARD = 0,
|
||||
CONTROLLER = 1,
|
||||
ANY = 2,
|
||||
};
|
||||
|
||||
// --- Estructuras ---
|
||||
struct KeyState {
|
||||
Uint8 scancode; // Scancode asociado
|
||||
@@ -98,29 +94,41 @@ class Input {
|
||||
|
||||
Keyboard()
|
||||
: bindings{
|
||||
// Teclado - Movimiento del jugador
|
||||
{Input::Action::UP, KeyState(SDL_SCANCODE_UP)},
|
||||
{Input::Action::DOWN, KeyState(SDL_SCANCODE_DOWN)},
|
||||
{Input::Action::LEFT, KeyState(SDL_SCANCODE_LEFT)},
|
||||
{Input::Action::RIGHT, KeyState(SDL_SCANCODE_RIGHT)},
|
||||
|
||||
// Teclado - Disparo del jugador
|
||||
{Input::Action::FIRE_LEFT, KeyState(SDL_SCANCODE_Q)},
|
||||
{Input::Action::FIRE_CENTER, KeyState(SDL_SCANCODE_W)},
|
||||
{Input::Action::FIRE_RIGHT, KeyState(SDL_SCANCODE_E)},
|
||||
|
||||
// Teclado - Interfaz
|
||||
{Input::Action::START, KeyState(SDL_SCANCODE_RETURN)},
|
||||
|
||||
// Teclado - Menu de servicio
|
||||
{Input::Action::SERVICE, KeyState(SDL_SCANCODE_0)},
|
||||
{Input::Action::SM_SELECT, KeyState(SDL_SCANCODE_RETURN)},
|
||||
{Input::Action::SM_BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
||||
|
||||
// Teclado - Control del programa
|
||||
{Input::Action::EXIT, KeyState(SDL_SCANCODE_ESCAPE)},
|
||||
{Input::Action::PAUSE, KeyState(SDL_SCANCODE_P)},
|
||||
{Input::Action::BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
||||
|
||||
{Input::Action::WINDOW_DEC_SIZE, KeyState(SDL_SCANCODE_F1)},
|
||||
{Input::Action::WINDOW_INC_SIZE, KeyState(SDL_SCANCODE_F2)},
|
||||
{Input::Action::WINDOW_FULLSCREEN, KeyState(SDL_SCANCODE_F3)},
|
||||
{Input::Action::TOGGLE_VIDEO_SHADERS, KeyState(SDL_SCANCODE_F4)},
|
||||
{Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, KeyState(SDL_SCANCODE_F5)},
|
||||
{Input::Action::TOGGLE_VIDEO_VSYNC, KeyState(SDL_SCANCODE_F6)},
|
||||
|
||||
{Input::Action::TOGGLE_AUDIO, KeyState(SDL_SCANCODE_F7)},
|
||||
{Input::Action::TOGGLE_AUTO_FIRE, KeyState(SDL_SCANCODE_F8)},
|
||||
{Input::Action::CHANGE_LANG, KeyState(SDL_SCANCODE_F9)},
|
||||
|
||||
{Input::Action::RESET, KeyState(SDL_SCANCODE_F10)},
|
||||
{Input::Action::SHOW_INFO, KeyState(SDL_SCANCODE_F12)}} {}
|
||||
};
|
||||
@@ -136,9 +144,18 @@ class Input {
|
||||
instance_id(SDL_GetJoystickID(SDL_GetGamepadJoystick(gamepad))),
|
||||
name(std::string(SDL_GetGamepadName(gamepad)) + " #" + std::to_string(instance_id)),
|
||||
bindings{
|
||||
// Mando - Movimiento del jugador
|
||||
{Input::Action::UP, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_UP)},
|
||||
{Input::Action::DOWN, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_DOWN)},
|
||||
{Input::Action::LEFT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_LEFT)},
|
||||
{Input::Action::RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)},
|
||||
|
||||
// Mando - Disparo del jugador
|
||||
{Input::Action::FIRE_LEFT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)},
|
||||
{Input::Action::FIRE_CENTER, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)},
|
||||
{Input::Action::FIRE_RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_EAST)},
|
||||
|
||||
// Mando - Interfaz
|
||||
{Input::Action::START, ButtonState(SDL_GAMEPAD_BUTTON_START)},
|
||||
{Input::Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}} {}
|
||||
|
||||
@@ -160,10 +177,10 @@ class Input {
|
||||
void bindGameControllerButton(std::shared_ptr<Gamepad> gamepad, Action input_target, Action input_source); // Asigna inputs a otros inputs del mando
|
||||
|
||||
// --- Métodos de consulta de entrada ---
|
||||
void update(); // Comprueba fisicamente los botones y teclas que se han pulsado
|
||||
auto checkAction(Action input, bool repeat = true, Device device = Device::ANY, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool; // Comprueba si un input está activo
|
||||
auto checkAnyInput(Device device = Device::ANY, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool; // Comprueba si hay al menos un input activo
|
||||
auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> bool; // Comprueba si hay algún botón pulsado
|
||||
void update(); // Comprueba fisicamente los botones y teclas que se han pulsado
|
||||
auto checkAction(Action input, bool repeat = true, bool check_keyboard = true, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool; // Comprueba si un input está activo
|
||||
auto checkAnyInput(bool check_keyboard = true, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool; // Comprueba si hay al menos un input activo
|
||||
auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> bool; // Comprueba si hay algún botón pulsado
|
||||
|
||||
// --- Métodos de gestión de mandos ---
|
||||
[[nodiscard]] auto gameControllerFound() const -> bool; // Comprueba si hay algún mando conectado
|
||||
|
||||
Reference in New Issue
Block a user