From b36740ad58b584823d0aaace0cc36329eb9cbff3 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 17 May 2026 14:45:54 +0200 Subject: [PATCH] global_inputs: getPressedAction usa helpers per a mods i llistes --- source/core/input/global_inputs.cpp | 96 ++++++++++++----------------- 1 file changed, 39 insertions(+), 57 deletions(-) diff --git a/source/core/input/global_inputs.cpp b/source/core/input/global_inputs.cpp index d99e650..3e73cea 100644 --- a/source/core/input/global_inputs.cpp +++ b/source/core/input/global_inputs.cpp @@ -2,8 +2,10 @@ #include -#include // Para allocator, operator+, char_traits, string -#include // Para vector +#include // Para ranges::find_if +#include // Para initializer_list +#include // Para allocator, operator+, char_traits, string +#include // Para vector #include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT #include "core/locale/locale.hpp" // Para Locale @@ -151,68 +153,48 @@ namespace GlobalInputs { Notifier::get()->show({Locale::get()->get(Options::video.vertical_sync ? "ui.vsync_enabled" : "ui.vsync_disabled")}); } + // F4 amb modificadors: Ctrl=supersampling, Shift=next preset, sense modificador=toggle shader + auto getShaderAction() -> InputAction { + if (!Screen::get()->isHardwareAccelerated()) { return InputAction::NONE; } + if (!Input::get()->checkAction(InputAction::TOGGLE_SHADER, Input::DO_NOT_ALLOW_REPEAT)) { return InputAction::NONE; } + const SDL_Keymod MOD = SDL_GetModState(); + if ((MOD & SDL_KMOD_CTRL) != 0U) { return InputAction::TOGGLE_SUPERSAMPLING; } + if (Options::video.shader.enabled && ((MOD & SDL_KMOD_SHIFT) != 0U)) { return InputAction::NEXT_SHADER_PRESET; } + return InputAction::TOGGLE_SHADER; + } + + // F5 amb modificador Ctrl per a paleta anterior + auto getPaletteAction() -> InputAction { + if (!Input::get()->checkAction(InputAction::NEXT_PALETTE, Input::DO_NOT_ALLOW_REPEAT)) { return InputAction::NONE; } + return ((SDL_GetModState() & SDL_KMOD_CTRL) != 0U) ? InputAction::PREVIOUS_PALETTE : InputAction::NEXT_PALETTE; + } + + // Comprova una llista d'accions 1:1 (sense modificadors); retorna la primera que dispare + auto firstPressedFrom(std::initializer_list actions) -> InputAction { + const auto* const IT = std::ranges::find_if(actions, [](const InputAction act) { + return Input::get()->checkAction(act, Input::DO_NOT_ALLOW_REPEAT); + }); + return (IT != actions.end()) ? *IT : InputAction::NONE; + } + // Detecta qué acción global ha sido presionada (si alguna) - auto getPressedAction() -> InputAction { // NOLINT(readability-function-cognitive-complexity) + auto getPressedAction() -> InputAction { // Qualsevol botó del comandament actua com a ACCEPT (saltar escenes // d'attract mode: logo, loading, credits, demo, ending...). El botó // BACK queda filtrat prèviament a GlobalEvents per no colidir amb EXIT // (excepte en emscripten, on BACK no pot sortir i sí pot saltar). - if (GlobalEvents::consumeGamepadButtonPressed()) { - return InputAction::ACCEPT; - } - if (Input::get()->checkAction(InputAction::EXIT, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::EXIT; - } - if (Input::get()->checkAction(InputAction::ACCEPT, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::ACCEPT; - } - if (Input::get()->checkAction(InputAction::TOGGLE_BORDER, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::TOGGLE_BORDER; - } + if (GlobalEvents::consumeGamepadButtonPressed()) { return InputAction::ACCEPT; } + + if (const InputAction ACT = firstPressedFrom({InputAction::EXIT, InputAction::ACCEPT, InputAction::TOGGLE_BORDER}); ACT != InputAction::NONE) { return ACT; } + if (!Options::kiosk.enabled) { - if (Input::get()->checkAction(InputAction::TOGGLE_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::TOGGLE_FULLSCREEN; - } - if (Input::get()->checkAction(InputAction::WINDOW_DEC_ZOOM, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::WINDOW_DEC_ZOOM; - } - if (Input::get()->checkAction(InputAction::WINDOW_INC_ZOOM, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::WINDOW_INC_ZOOM; - } + if (const InputAction ACT = firstPressedFrom({InputAction::TOGGLE_FULLSCREEN, InputAction::WINDOW_DEC_ZOOM, InputAction::WINDOW_INC_ZOOM}); ACT != InputAction::NONE) { return ACT; } } - if (Screen::get()->isHardwareAccelerated()) { - if (Input::get()->checkAction(InputAction::TOGGLE_SHADER, Input::DO_NOT_ALLOW_REPEAT)) { - if ((SDL_GetModState() & SDL_KMOD_CTRL) != 0U) { - return InputAction::TOGGLE_SUPERSAMPLING; // Ctrl+F4 - } - if (Options::video.shader.enabled && ((SDL_GetModState() & SDL_KMOD_SHIFT) != 0U)) { - return InputAction::NEXT_SHADER_PRESET; // Shift+F4 - } - return InputAction::TOGGLE_SHADER; // F4 - } - } - if (Input::get()->checkAction(InputAction::NEXT_PALETTE, Input::DO_NOT_ALLOW_REPEAT)) { - if ((SDL_GetModState() & SDL_KMOD_CTRL) != 0U) { - return InputAction::PREVIOUS_PALETTE; // Ctrl+F5 - } - return InputAction::NEXT_PALETTE; // F5 - } - if (Input::get()->checkAction(InputAction::NEXT_PALETTE_SORT, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::NEXT_PALETTE_SORT; // F6 - } - if (Input::get()->checkAction(InputAction::TOGGLE_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::TOGGLE_INTEGER_SCALE; - } - if (Input::get()->checkAction(InputAction::TOGGLE_VSYNC, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::TOGGLE_VSYNC; - } - if (Input::get()->checkAction(InputAction::TOGGLE_INFO, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::TOGGLE_INFO; - } - if (Input::get()->checkAction(InputAction::TOGGLE_CONSOLE, Input::DO_NOT_ALLOW_REPEAT)) { - return InputAction::TOGGLE_CONSOLE; - } - return InputAction::NONE; + + if (const InputAction ACT = getShaderAction(); ACT != InputAction::NONE) { return ACT; } + if (const InputAction ACT = getPaletteAction(); ACT != InputAction::NONE) { return ACT; } + + return firstPressedFrom({InputAction::NEXT_PALETTE_SORT, InputAction::TOGGLE_INTEGER_SCALE, InputAction::TOGGLE_VSYNC, InputAction::TOGGLE_INFO, InputAction::TOGGLE_CONSOLE}); } } // namespace