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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user