From bded70a52a93a37050535082c5a44275f3610a36 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 19 May 2026 20:03:11 +0200 Subject: [PATCH] ui: F1-F12 i ESC deixen de comptar com a any-key skip (logo/intro/instructions/title/demo) --- source/core/input/input.cpp | 34 +++++++++++++++++++++++------ source/game/scenes/instructions.cpp | 2 +- source/game/scenes/intro.cpp | 2 +- source/game/scenes/logo.cpp | 2 +- source/game/scenes/title.cpp | 11 +++++++++- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/source/core/input/input.cpp b/source/core/input/input.cpp index 22e3e16..a27c57c 100644 --- a/source/core/input/input.cpp +++ b/source/core/input/input.cpp @@ -157,25 +157,45 @@ auto Input::checkGameControllerInput(Action input, Repeat repeat, int index) -> return PRESS_EDGE; } -// Comprueba si hay almenos un input activo +// Comprueba si hay almenos un input "humano" activo (moviment, ACCEPT/CANCEL, +// FIRE_*). Exclou les accions reservades a hotkeys globals (EXIT, PAUSE, +// WINDOW_*, *SHADER*) perque prémer F1-F12 o ESC no s'ha de comptar com +// "qualsevol tecla" — ningu vol saltar una intro per modificar el zoom. auto Input::checkAnyInput(Device device, int index) -> bool { if (device == Device::ANY) { index = 0; } + auto is_skippable = [](Action a) { + switch (a) { + case Action::UP: + case Action::DOWN: + case Action::LEFT: + case Action::RIGHT: + case Action::ACCEPT: + case Action::CANCEL: + case Action::FIRE_LEFT: + case Action::FIRE_CENTER: + case Action::FIRE_RIGHT: + return true; + default: + return false; + } + }; + if (device == Device::KEYBOARD || device == Device::ANY) { const bool *key_states = SDL_GetKeyboardState(nullptr); - - if (std::ranges::any_of(key_bindings_, - [key_states](const auto &key_binding) { return key_states[key_binding.scancode]; })) { - return true; + for (std::size_t i = 0; i < key_bindings_.size(); ++i) { + if (is_skippable(static_cast(i)) && key_states[key_bindings_[i].scancode]) { + return true; + } } } if (gameControllerFound() && index >= 0 && index < (int)connected_controllers_.size()) { 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)) { + for (std::size_t i = 0; i < game_controller_bindings_.size(); ++i) { + if (is_skippable(static_cast(i)) && SDL_GetGamepadButton(connected_controllers_[index], game_controller_bindings_[i].button)) { return true; } } diff --git a/source/game/scenes/instructions.cpp b/source/game/scenes/instructions.cpp index 4f6fb79..e4d540a 100644 --- a/source/game/scenes/instructions.cpp +++ b/source/game/scenes/instructions.cpp @@ -239,7 +239,7 @@ void Instructions::checkInput() { // pulsació; el quit es propaga via Director::iterate. if (GlobalInputs::handle()) { return; } - 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 (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 { diff --git a/source/game/scenes/intro.cpp b/source/game/scenes/intro.cpp index 0aa3082..b019e7f 100644 --- a/source/game/scenes/intro.cpp +++ b/source/game/scenes/intro.cpp @@ -197,7 +197,7 @@ void Intro::checkInput() { // pulsació; el quit es propaga via Director::iterate. if (GlobalInputs::handle()) { return; } - 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 (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; diff --git a/source/game/scenes/logo.cpp b/source/game/scenes/logo.cpp index 877e3f5..e8f3cb9 100644 --- a/source/game/scenes/logo.cpp +++ b/source/game/scenes/logo.cpp @@ -65,7 +65,7 @@ void Logo::checkInput() { // pulsació; el quit es propaga via Director::iterate. if (GlobalInputs::handle()) { return; } - 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 (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; } diff --git a/source/game/scenes/title.cpp b/source/game/scenes/title.cpp index b9f2911..f6c8828 100644 --- a/source/game/scenes/title.cpp +++ b/source/game/scenes/title.cpp @@ -952,7 +952,16 @@ void Title::handleEvent(const SDL_Event *event) { } if (section_->subsection == SUBSECTION_TITLE_3) { - if ((event->type == SDL_EVENT_KEY_UP) || (event->type == SDL_EVENT_JOYSTICK_BUTTON_UP)) { + // Activa menu i reinicia el countdown de demo nomes amb tecles "humanes". + // F1-F12 i ESC son hotkeys globals (zoom, fullscreen, shaders, exit, version) + // i no han d'interferir amb el flux de l'UI del titol. + bool human_input = (event->type == SDL_EVENT_JOYSTICK_BUTTON_UP); + if (event->type == SDL_EVENT_KEY_UP) { + const SDL_Scancode S = event->key.scancode; + const bool IS_RESERVED = (S == SDL_SCANCODE_ESCAPE) || (S >= SDL_SCANCODE_F1 && S <= SDL_SCANCODE_F12); + human_input = !IS_RESERVED; + } + if (human_input) { menu_visible_ = true; demo_remaining_s_ = DEMO_TIMEOUT_S; }