migrant input: ja funcionen coses, pero encara queda
This commit is contained in:
@@ -97,6 +97,11 @@ void Director::init() {
|
||||
Resource::init(); // Inicializa el sistema de gestión de recursos
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt")); // Carga configuración de controles
|
||||
bindInputs(); // Asigna los controles a la entrada del sistema
|
||||
|
||||
auto gamepads = Input::get()->getGamepads();
|
||||
if (!gamepads.empty())
|
||||
Options::controllers.front().gamepad = gamepads.front();
|
||||
|
||||
ServiceMenu::init(); // Inicializa el menú de servicio
|
||||
Notifier::init(std::string(), Resource::get()->getText("8bithud")); // Inicialización del sistema de notificaciones
|
||||
Screen::get()->getSingletons(); // Obtiene los punteros al resto de singletones
|
||||
|
||||
@@ -163,7 +163,7 @@ void incWindowSize() {
|
||||
// Comprueba el boton de servicio
|
||||
auto checkServiceButton() -> bool {
|
||||
// Teclado
|
||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleServiceMenu();
|
||||
return true;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ auto checkServiceButton() -> bool {
|
||||
{
|
||||
auto gamepads = Input::get()->getGamepads();
|
||||
for (auto gamepad : gamepads) {
|
||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
toggleServiceMenu();
|
||||
return true;
|
||||
}
|
||||
@@ -190,37 +190,37 @@ auto checkServiceInputs() -> bool {
|
||||
// Teclado
|
||||
{
|
||||
// Arriba
|
||||
if (Input::get()->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
ServiceMenu::get()->setSelectorUp();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Abajo
|
||||
if (Input::get()->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
ServiceMenu::get()->setSelectorDown();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Derecha
|
||||
if (Input::get()->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
ServiceMenu::get()->adjustOption(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Izquierda
|
||||
if (Input::get()->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
ServiceMenu::get()->adjustOption(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Aceptar
|
||||
if (Input::get()->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
ServiceMenu::get()->selectOption();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Atras
|
||||
if (Input::get()->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
ServiceMenu::get()->moveBack();
|
||||
return true;
|
||||
}
|
||||
@@ -231,37 +231,37 @@ auto checkServiceInputs() -> bool {
|
||||
auto gamepads = Input::get()->getGamepads();
|
||||
for (auto gamepad : gamepads) {
|
||||
// Arriba
|
||||
if (Input::get()->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
||||
if (Input::get()->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
ServiceMenu::get()->setSelectorUp();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Abajo
|
||||
if (Input::get()->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
||||
if (Input::get()->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
ServiceMenu::get()->setSelectorDown();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Derecha
|
||||
if (Input::get()->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
||||
if (Input::get()->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
ServiceMenu::get()->adjustOption(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Izquierda
|
||||
if (Input::get()->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
||||
if (Input::get()->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
ServiceMenu::get()->adjustOption(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Aceptar
|
||||
if (Input::get()->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
||||
if (Input::get()->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
ServiceMenu::get()->selectOption();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Atras
|
||||
if (Input::get()->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
||||
if (Input::get()->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
ServiceMenu::get()->moveBack();
|
||||
return true;
|
||||
}
|
||||
@@ -275,7 +275,7 @@ auto checkInputs() -> bool {
|
||||
// Teclado
|
||||
{
|
||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
Screen::get()->toggleFullscreen();
|
||||
const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10");
|
||||
Notifier::get()->show({MODE});
|
||||
@@ -283,7 +283,7 @@ auto checkInputs() -> bool {
|
||||
}
|
||||
|
||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_DEC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_DEC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
if (Screen::get()->decWindowSize()) {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||
}
|
||||
@@ -291,7 +291,7 @@ auto checkInputs() -> bool {
|
||||
}
|
||||
|
||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_INC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_INC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
if (Screen::get()->incWindowSize()) {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||
}
|
||||
@@ -299,7 +299,7 @@ auto checkInputs() -> bool {
|
||||
}
|
||||
|
||||
// Salir
|
||||
if (Input::get()->checkAction(Input::Action::EXIT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::EXIT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
quit();
|
||||
return true;
|
||||
}
|
||||
@@ -311,50 +311,50 @@ auto checkInputs() -> bool {
|
||||
}
|
||||
|
||||
// Reset
|
||||
if (Input::get()->checkAction(Input::Action::RESET, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::RESET, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Audio
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_AUDIO, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_AUDIO, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleAudio();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Autofire
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_AUTO_FIRE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_AUTO_FIRE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleFireMode();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Idioma
|
||||
if (Input::get()->checkAction(Input::Action::CHANGE_LANG, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::CHANGE_LANG, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
changeLang();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Shaders
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_SHADERS, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_SHADERS, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleShaders();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Integer Scale
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleIntegerScale();
|
||||
return true;
|
||||
}
|
||||
|
||||
// VSync
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_VSYNC, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_VSYNC, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleVSync();
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Debug info
|
||||
if (Input::get()->checkAction(Input::Action::SHOW_INFO, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (Input::get()->checkAction(Input::Action::SHOW_INFO, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
Screen::get()->toggleDebugInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ void Input::bindGameControllerButton(std::shared_ptr<Gamepad> gamepad, Action in
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
auto Input::checkAction(Action action, bool repeat, Device device, std::shared_ptr<Gamepad> gamepad) -> bool {
|
||||
auto Input::checkAction(Action action, bool repeat, bool check_keyboard, std::shared_ptr<Gamepad> gamepad) -> bool {
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
|
||||
if (device == Device::KEYBOARD || device == Device::ANY) {
|
||||
if (check_keyboard) {
|
||||
if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido)
|
||||
success_keyboard = keyboard_.bindings[action].is_held;
|
||||
} else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma)
|
||||
@@ -64,15 +64,13 @@ auto Input::checkAction(Action action, bool repeat, Device device, std::shared_p
|
||||
}
|
||||
|
||||
if (gamepad != nullptr) {
|
||||
if ((device == Device::CONTROLLER) || (device == Device::ANY)) {
|
||||
success_controller = checkAxisInput(action, gamepad, repeat);
|
||||
success_controller = checkAxisInput(action, gamepad, repeat);
|
||||
|
||||
if (!success_controller) {
|
||||
if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido)
|
||||
success_controller = gamepad->bindings[action].is_held;
|
||||
} else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma)
|
||||
success_controller = gamepad->bindings[action].just_pressed;
|
||||
}
|
||||
if (!success_controller) {
|
||||
if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido)
|
||||
success_controller = gamepad->bindings[action].is_held;
|
||||
} else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma)
|
||||
success_controller = gamepad->bindings[action].just_pressed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,11 +79,11 @@ auto Input::checkAction(Action action, bool repeat, Device device, std::shared_p
|
||||
}
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
auto Input::checkAnyInput(Device device, std::shared_ptr<Gamepad> gamepad) -> bool {
|
||||
auto Input::checkAnyInput(bool check_keyboard, std::shared_ptr<Gamepad> gamepad) -> bool {
|
||||
// Obtenemos el número total de acciones posibles para iterar sobre ellas.
|
||||
|
||||
// --- Comprobación del Teclado ---
|
||||
if (device == Device::KEYBOARD || device == Device::ANY) {
|
||||
if (check_keyboard) {
|
||||
for (const auto &pair : keyboard_.bindings) {
|
||||
// Simplemente leemos el estado pre-calculado por Input::update().
|
||||
// Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'.
|
||||
@@ -98,13 +96,11 @@ auto Input::checkAnyInput(Device device, std::shared_ptr<Gamepad> gamepad) -> bo
|
||||
// --- Comprobación del Mando ---
|
||||
// Comprobamos si hay mandos y si el índice solicitado es válido.
|
||||
if (gamepad != nullptr) {
|
||||
if (device == Device::CONTROLLER || device == Device::ANY) {
|
||||
// Iteramos sobre todas las acciones, no sobre el número de mandos.
|
||||
for (const auto &pair : gamepad->bindings) {
|
||||
// Leemos el estado pre-calculado para el mando y la acción específicos.
|
||||
if (pair.second.just_pressed) {
|
||||
return true; // Se encontró una acción recién pulsada en el mando.
|
||||
}
|
||||
// Iteramos sobre todas las acciones, no sobre el número de mandos.
|
||||
for (const auto &pair : gamepad->bindings) {
|
||||
// Leemos el estado pre-calculado para el mando y la acción específicos.
|
||||
if (pair.second.just_pressed) {
|
||||
return true; // Se encontró una acción recién pulsada en el mando.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,13 +114,13 @@ auto Input::checkAnyButton(bool repeat) -> bool {
|
||||
// Solo comprueba los botones definidos previamente
|
||||
for (auto bi : button_inputs_) {
|
||||
// Comprueba el teclado
|
||||
if (checkAction(bi, repeat, Device::KEYBOARD)) {
|
||||
if (checkAction(bi, repeat, CHECK_KEYBOARD)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Comprueba los mandos
|
||||
for (auto gamepad : gamepads_) {
|
||||
if (checkAction(bi, repeat, Device::CONTROLLER, gamepad)) {
|
||||
if (checkAction(bi, repeat, DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -144,11 +140,11 @@ auto Input::getNumControllers() const -> int { return gamepads_.size(); }
|
||||
|
||||
// Obtiene el indice del controlador a partir de un event.id
|
||||
auto Input::getJoyIndex(SDL_JoystickID id) const -> int {
|
||||
// for (int i = 0; i < num_joysticks_; ++i) {
|
||||
// if (SDL_GetJoystickID(joysticks_[i]) == id) {
|
||||
// return i;
|
||||
// }
|
||||
// }
|
||||
// for (int i = 0; i < num_joysticks_; ++i) {
|
||||
// if (SDL_GetJoystickID(joysticks_[i]) == id) {
|
||||
// return i;
|
||||
// }
|
||||
// }
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
0
source/jail_shader.cpp
Normal file
0
source/jail_shader.cpp
Normal file
@@ -19,13 +19,13 @@
|
||||
|
||||
namespace Options {
|
||||
// --- Variables globales ---
|
||||
WindowOptions window; // Opciones de la ventana
|
||||
SettingsOptions settings; // Opciones del juego
|
||||
VideoOptions video; // Opciones de vídeo
|
||||
AudioOptions audio; // Opciones de audio
|
||||
std::vector<GamepadOptions> controllers; // Opciones de mando para cada jugador
|
||||
PendingChanges pending_changes; // Opciones que se aplican al cerrar
|
||||
//std::vector<GamepadConfig> gamepad_configs; // Lista con las configuraciones registradas para cada mando
|
||||
WindowOptions window; // Opciones de la ventana
|
||||
SettingsOptions settings; // Opciones del juego
|
||||
VideoOptions video; // Opciones de vídeo
|
||||
AudioOptions audio; // Opciones de audio
|
||||
std::vector<GamepadOptions> controllers; // Opciones de mando para cada jugador
|
||||
PendingChanges pending_changes; // Opciones que se aplican al cerrar
|
||||
// std::vector<GamepadConfig> gamepad_configs; // Lista con las configuraciones registradas para cada mando
|
||||
|
||||
// Declaraciones
|
||||
auto set(const std::string& var, const std::string& value) -> bool;
|
||||
@@ -159,7 +159,6 @@ auto saveToFile() -> bool {
|
||||
file << "\n";
|
||||
file << "controller." << controller_index << ".name=" << controller.name << "\n";
|
||||
file << "controller." << controller_index << ".player=" << controller.player_id << "\n";
|
||||
file << "controller." << controller_index << ".type=" << static_cast<int>(controller.type) << "\n";
|
||||
|
||||
// Incrementa el índice
|
||||
++controller_index;
|
||||
@@ -186,8 +185,6 @@ void parseAndSetController(const std::string& var, const std::string& value) {
|
||||
controller.name = value;
|
||||
} else if (setting_key == "player") {
|
||||
controller.player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
} else if (setting_key == "type") {
|
||||
controller.type = static_cast<Input::Device>(std::stoi(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,31 +257,31 @@ auto set(const std::string& var, const std::string& value) -> bool {
|
||||
void setKeyboardToPlayer(int player_id) {
|
||||
for (auto& controller : controllers) {
|
||||
if (controller.player_id == player_id) {
|
||||
controller.type = Input::Device::ANY;
|
||||
// controller.type = Input::Device::ANY;
|
||||
} else {
|
||||
controller.type = Input::Device::CONTROLLER;
|
||||
// controller.type = Input::Device::CONTROLLER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Intercambia el teclado de jugador
|
||||
void swapKeyboard() {
|
||||
std::swap(controllers.at(0).type, controllers.at(1).type);
|
||||
// std::swap(controllers.at(0).type, controllers.at(1).type);
|
||||
}
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void swapControllers() {
|
||||
std::swap(controllers.at(0).player_id, controllers.at(1).player_id);
|
||||
std::swap(controllers.at(0).type, controllers.at(1).type);
|
||||
// std::swap(controllers.at(0).type, controllers.at(1).type);
|
||||
}
|
||||
|
||||
// Averigua quien está usando el teclado
|
||||
auto getPlayerWhoUsesKeyboard() -> int {
|
||||
for (const auto& controller : controllers) {
|
||||
if (controller.type == Input::Device::ANY) {
|
||||
return controller.player_id;
|
||||
}
|
||||
}
|
||||
// for (const auto& controller : controllers) {
|
||||
// if (controller.type == Input::Device::ANY) {
|
||||
// return controller.player_id;
|
||||
// }
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,6 @@ struct GamepadOptions {
|
||||
std::shared_ptr<Input::Gamepad> gamepad = nullptr; // Referencia al mando
|
||||
std::string name; // Nombre del mando
|
||||
int player_id; // Jugador asociado al mando
|
||||
Input::Device type = Input::Device::CONTROLLER; // Tipo de dispositivo
|
||||
|
||||
GamepadOptions(int custom_player_id = INVALID_INDEX)
|
||||
: player_id(custom_player_id) {}
|
||||
|
||||
@@ -165,6 +165,12 @@ class Player {
|
||||
void setWalkingState(State state) { walking_state_ = state; }
|
||||
void addCredit() { ++credits_used_; }
|
||||
|
||||
// Setter y getter para gamepad_
|
||||
void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = gamepad; }
|
||||
[[nodiscard]] std::shared_ptr<Input::Gamepad> getGamepad() const { return gamepad_; }
|
||||
void setUsesKeyboard(bool value) { uses_keyboard_ = value; }
|
||||
[[nodiscard]] bool getUsesKeyboard() const { return uses_keyboard_; }
|
||||
|
||||
private:
|
||||
// --- Constantes ---
|
||||
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp
|
||||
@@ -220,10 +226,8 @@ class Player {
|
||||
int credits_used_ = 0; // Indica el número de veces que ha continuado
|
||||
std::string last_enter_name_; // Último nombre introducido en la tabla de puntuaciones
|
||||
int waiting_counter_ = 0; // Contador para el estado de espera
|
||||
std::shared_ptr<Input::Gamepad> gamepad_ = nullptr; // Dispositivo asociado
|
||||
// Setter y getter para gamepad_
|
||||
void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = gamepad; }
|
||||
[[nodiscard]] std::shared_ptr<Input::Gamepad> getGamepad() const { return gamepad_; }
|
||||
std::shared_ptr<Input::Gamepad> gamepad_ = nullptr; // Dispositivo asociado
|
||||
bool uses_keyboard_ = false; // Indica si usa el teclado como dispositivo de control
|
||||
|
||||
// --- Métodos internos ---
|
||||
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
|
||||
|
||||
@@ -1250,14 +1250,14 @@ void Game::checkPauseInput() {
|
||||
// Comprueba los mandos
|
||||
auto gamepads = input_->getGamepads();
|
||||
for (auto gamepad : gamepads) {
|
||||
if (input_->checkAction(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
||||
if (input_->checkAction(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
pause(!paused_);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el teclado
|
||||
if (input_->checkAction(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
||||
if (input_->checkAction(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
pause(!paused_);
|
||||
return;
|
||||
}
|
||||
@@ -1366,14 +1366,12 @@ void Game::handlePlayersInput() {
|
||||
|
||||
// Maneja las entradas de movimiento y disparo para un jugador en modo normal.
|
||||
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player) {
|
||||
const auto &controller = Options::controllers.at(0);
|
||||
|
||||
if (input_->checkAction(Input::Action::LEFT, Input::ALLOW_REPEAT, controller.type, controller.gamepad)) {
|
||||
if (input_->checkAction(Input::Action::LEFT, Input::ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
#ifdef RECORDING
|
||||
demo_.keys.left = 1;
|
||||
#endif
|
||||
} else if (input_->checkAction(Input::Action::RIGHT, Input::ALLOW_REPEAT, controller.type, controller.gamepad)) {
|
||||
} else if (input_->checkAction(Input::Action::RIGHT, Input::ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setInput(Input::Action::RIGHT);
|
||||
#ifdef RECORDING
|
||||
demo_.keys.right = 1;
|
||||
@@ -1391,18 +1389,17 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player) {
|
||||
|
||||
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
|
||||
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire) {
|
||||
const auto CONTROLLER = Options::controllers.at(0);
|
||||
if (input_->checkAction(Input::Action::FIRE_CENTER, autofire, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
if (input_->checkAction(Input::Action::FIRE_CENTER, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
handleFireInput(player, BulletType::UP);
|
||||
#ifdef RECORDING
|
||||
demo_.keys.fire = 1;
|
||||
#endif
|
||||
} else if (input_->checkAction(Input::Action::FIRE_LEFT, autofire, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
} else if (input_->checkAction(Input::Action::FIRE_LEFT, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
handleFireInput(player, BulletType::LEFT);
|
||||
#ifdef RECORDING
|
||||
demo_.keys.fire_left = 1;
|
||||
#endif
|
||||
} else if (input_->checkAction(Input::Action::FIRE_RIGHT, autofire, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
} else if (input_->checkAction(Input::Action::FIRE_RIGHT, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
handleFireInput(player, BulletType::RIGHT);
|
||||
#ifdef RECORDING
|
||||
demo_.keys.fire_right = 1;
|
||||
@@ -1412,17 +1409,16 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
|
||||
|
||||
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
|
||||
void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
|
||||
const auto CONTROLLER = Options::controllers.at(0);
|
||||
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setPlayingState(Player::State::RESPAWNING);
|
||||
player->addCredit();
|
||||
sendPlayerToTheFront(player);
|
||||
}
|
||||
|
||||
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
|
||||
if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad) ||
|
||||
input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad) ||
|
||||
input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad()) ||
|
||||
input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad()) ||
|
||||
input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
if (player->getContinueCounter() < param.scoreboard.skip_countdown_value) {
|
||||
player->decContinueCounter();
|
||||
}
|
||||
@@ -1431,8 +1427,7 @@ void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
|
||||
|
||||
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
|
||||
void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
|
||||
const auto CONTROLLER = Options::controllers.at(0);
|
||||
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setPlayingState(Player::State::ENTERING_SCREEN);
|
||||
player->addCredit();
|
||||
sendPlayerToTheFront(player);
|
||||
@@ -1441,8 +1436,7 @@ void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
|
||||
|
||||
// Procesa las entradas para la introducción del nombre del jugador.
|
||||
void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
||||
const auto CONTROLLER = Options::controllers.at(0);
|
||||
if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
if (player->isShowingName()) {
|
||||
player->setPlayingState(Player::State::CONTINUE);
|
||||
} else if (player->getEnterNamePositionOverflow()) {
|
||||
@@ -1452,18 +1446,18 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
||||
} else {
|
||||
player->setInput(Input::Action::RIGHT);
|
||||
}
|
||||
} else if (input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad) ||
|
||||
input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
} else if (input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad()) ||
|
||||
input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
if (player->isShowingName()) {
|
||||
player->setPlayingState(Player::State::CONTINUE);
|
||||
} else {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
}
|
||||
} else if (input_->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
} else if (input_->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setInput(Input::Action::UP);
|
||||
} else if (input_->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
} else if (input_->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setInput(Input::Action::DOWN);
|
||||
} else if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
||||
} else if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
if (player->isShowingName()) {
|
||||
player->setPlayingState(Player::State::CONTINUE);
|
||||
} else {
|
||||
@@ -1594,14 +1588,16 @@ void Game::initPlayers(int player_id) {
|
||||
players_.emplace_back(std::make_unique<Player>(1, param.game.play_area.first_quarter_x - (Player::WIDTH / 2), Y, demo_.enabled, param.game.play_area.rect, player_textures_.at(0), player_animations_));
|
||||
players_.back()->setScoreBoardPanel(Scoreboard::Id::LEFT);
|
||||
players_.back()->setName(Lang::getText("[SCOREBOARD] 1"));
|
||||
players_.back()->setController(getController(players_.back()->getId()));
|
||||
//players_.back()->setController(getController(players_.back()->getId()));
|
||||
players_.back()->setGamepad(Options::controllers.front().gamepad);
|
||||
players_.back()->setUsesKeyboard(true);
|
||||
players_.back()->setPlayingState(Player::State::WAITING);
|
||||
|
||||
// Crea al jugador dos y lo pone en modo espera
|
||||
players_.emplace_back(std::make_unique<Player>(2, param.game.play_area.third_quarter_x - (Player::WIDTH / 2), Y, demo_.enabled, param.game.play_area.rect, player_textures_.at(1), player_animations_));
|
||||
players_.back()->setScoreBoardPanel(Scoreboard::Id::RIGHT);
|
||||
players_.back()->setName(Lang::getText("[SCOREBOARD] 2"));
|
||||
players_.back()->setController(getController(players_.back()->getId()));
|
||||
//players_.back()->setController(getController(players_.back()->getId()));
|
||||
players_.back()->setPlayingState(Player::State::WAITING);
|
||||
|
||||
// Activa el jugador que coincide con el "player_id" o ambos si es "0"
|
||||
|
||||
@@ -273,7 +273,7 @@ auto Title::isStartButtonPressed(const Options::GamepadOptions& controller) -> b
|
||||
return Input::get()->checkAction(
|
||||
Input::Action::START,
|
||||
Input::DO_NOT_ALLOW_REPEAT,
|
||||
controller.type,
|
||||
Input::CHECK_KEYBOARD,
|
||||
controller.gamepad);
|
||||
}
|
||||
|
||||
|
||||
0
source/service_menu.cpp
Normal file
0
source/service_menu.cpp
Normal file
0
source/service_menu.h
Normal file
0
source/service_menu.h
Normal file
Reference in New Issue
Block a user