centralitzada la gestio d'SKIP per a les escenes

This commit is contained in:
2025-12-16 08:33:29 +01:00
parent 3d0057220d
commit 8b896912b2
7 changed files with 25 additions and 30 deletions

View File

@@ -188,6 +188,16 @@ auto Input::checkAnyButton(bool repeat) -> bool {
return false;
}
// Comprueba si algún jugador (P1 o P2) presionó alguna acción de una lista
auto Input::checkAnyPlayerAction(const std::span<const InputAction>& actions, bool repeat) -> bool {
for (const auto& action : actions) {
if (checkActionPlayer1(action, repeat) || checkActionPlayer2(action, repeat)) {
return true;
}
}
return false;
}
// Comprueba si hay algun mando conectado
auto Input::gameControllerFound() const -> bool { return !gamepads_.empty(); }

View File

@@ -4,6 +4,7 @@
#include <array> // Para array
#include <memory> // Para shared_ptr
#include <span> // Para span
#include <string> // Para string, basic_string
#include <unordered_map> // Para unordered_map
#include <utility> // Para pair
@@ -108,6 +109,9 @@ class Input {
auto checkActionPlayer1(Action action, bool repeat = true) -> bool;
auto checkActionPlayer2(Action action, bool repeat = true) -> bool;
// Check if any player pressed any action from a list
auto checkAnyPlayerAction(const std::span<const InputAction>& actions, bool repeat = DO_NOT_ALLOW_REPEAT) -> bool;
// --- Gestión de gamepads ---
[[nodiscard]] auto gameControllerFound() const -> bool;
[[nodiscard]] auto getNumGamepads() const -> int;

View File

@@ -2,6 +2,7 @@
#include <SDL3/SDL.h>
#include <array>
#include <string>
#include <unordered_map>
@@ -31,3 +32,11 @@ extern const std::unordered_map<InputAction, std::string> ACTION_TO_STRING;
extern const std::unordered_map<std::string, InputAction> STRING_TO_ACTION; // Mapeo de string a acción
extern const std::unordered_map<SDL_GamepadButton, std::string> BUTTON_TO_STRING; // Mapeo de botón a string
extern const std::unordered_map<std::string, SDL_GamepadButton> STRING_TO_BUTTON; // Mapeo de string a botón
// --- Constantes ---
// Physical arcade buttons (excludes directional controls LEFT/RIGHT)
static constexpr std::array<InputAction, 3> ARCADE_BUTTONS = {
InputAction::SHOOT,
InputAction::THRUST,
InputAction::START
};

View File

@@ -415,14 +415,7 @@ void EscenaLogo::dibuixar() {
}
auto EscenaLogo::checkSkipButtonPressed() -> bool {
auto* input = Input::get();
for (auto action : SKIP_BUTTONS_LOGO) {
if (input->checkActionPlayer1(action, Input::DO_NOT_ALLOW_REPEAT) ||
input->checkActionPlayer2(action, Input::DO_NOT_ALLOW_REPEAT)) {
return true;
}
}
return false;
return Input::get()->checkAnyPlayerAction(ARCADE_BUTTONS);
}
void EscenaLogo::processar_events(const SDL_Event& event) {

View File

@@ -18,11 +18,6 @@
#include "core/system/context_escenes.hpp"
#include "core/types.hpp"
// Botones que permiten saltar la escena (extensible)
static constexpr std::array<InputAction, 1> SKIP_BUTTONS_LOGO = {
InputAction::SHOOT
};
class EscenaLogo {
public:
explicit EscenaLogo(SDLManager& sdl, GestorEscenes::ContextEscenes& context);

View File

@@ -585,16 +585,7 @@ void EscenaTitol::dibuixar() {
}
auto EscenaTitol::checkSkipButtonPressed() -> bool {
auto* input = Input::get();
for (auto action : SKIP_BUTTONS_TITOL) {
if (input->checkActionPlayer1(action, Input::DO_NOT_ALLOW_REPEAT) ||
input->checkActionPlayer2(action, Input::DO_NOT_ALLOW_REPEAT)) {
return true; // Don't track players here, just skip
}
}
return false;
return Input::get()->checkAnyPlayerAction(ARCADE_BUTTONS);
}
auto EscenaTitol::checkStartGameButtonPressed() -> bool {

View File

@@ -20,13 +20,6 @@
#include "core/system/game_config.hpp"
#include "core/types.hpp"
// Botones que permiten saltar/avanzar escenas ANTES de MAIN (extensible)
static constexpr std::array<InputAction, 3> SKIP_BUTTONS_TITOL = {
InputAction::SHOOT, // FIRE
InputAction::THRUST, // THRUST
InputAction::START // START
};
// Botones para INICIAR PARTIDA desde MAIN (solo START)
static constexpr std::array<InputAction, 1> START_GAME_BUTTONS = {
InputAction::START