ui: F1-F12 i ESC deixen de comptar com a any-key skip (logo/intro/instructions/title/demo)
This commit is contained in:
@@ -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<Action>(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<Action>(i)) && SDL_GetGamepadButton(connected_controllers_[index], game_controller_bindings_[i].button)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user