global_inputs: getPressedAction usa helpers per a mods i llistes
This commit is contained in:
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <string> // Para allocator, operator+, char_traits, string
|
#include <algorithm> // Para ranges::find_if
|
||||||
#include <vector> // Para vector
|
#include <initializer_list> // Para initializer_list
|
||||||
|
#include <string> // Para allocator, operator+, char_traits, string
|
||||||
|
#include <vector> // Para vector
|
||||||
|
|
||||||
#include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT
|
#include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT
|
||||||
#include "core/locale/locale.hpp" // Para Locale
|
#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")});
|
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<InputAction> 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)
|
// 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
|
// Qualsevol botó del comandament actua com a ACCEPT (saltar escenes
|
||||||
// d'attract mode: logo, loading, credits, demo, ending...). El botó
|
// d'attract mode: logo, loading, credits, demo, ending...). El botó
|
||||||
// BACK queda filtrat prèviament a GlobalEvents per no colidir amb EXIT
|
// BACK queda filtrat prèviament a GlobalEvents per no colidir amb EXIT
|
||||||
// (excepte en emscripten, on BACK no pot sortir i sí pot saltar).
|
// (excepte en emscripten, on BACK no pot sortir i sí pot saltar).
|
||||||
if (GlobalEvents::consumeGamepadButtonPressed()) {
|
if (GlobalEvents::consumeGamepadButtonPressed()) { return InputAction::ACCEPT; }
|
||||||
return InputAction::ACCEPT;
|
|
||||||
}
|
if (const InputAction ACT = firstPressedFrom({InputAction::EXIT, InputAction::ACCEPT, InputAction::TOGGLE_BORDER}); ACT != InputAction::NONE) { return ACT; }
|
||||||
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 (!Options::kiosk.enabled) {
|
if (!Options::kiosk.enabled) {
|
||||||
if (Input::get()->checkAction(InputAction::TOGGLE_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT)) {
|
if (const InputAction ACT = firstPressedFrom({InputAction::TOGGLE_FULLSCREEN, InputAction::WINDOW_DEC_ZOOM, InputAction::WINDOW_INC_ZOOM}); ACT != InputAction::NONE) { return ACT; }
|
||||||
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 (Screen::get()->isHardwareAccelerated()) {
|
|
||||||
if (Input::get()->checkAction(InputAction::TOGGLE_SHADER, Input::DO_NOT_ALLOW_REPEAT)) {
|
if (const InputAction ACT = getShaderAction(); ACT != InputAction::NONE) { return ACT; }
|
||||||
if ((SDL_GetModState() & SDL_KMOD_CTRL) != 0U) {
|
if (const InputAction ACT = getPaletteAction(); ACT != InputAction::NONE) { return ACT; }
|
||||||
return InputAction::TOGGLE_SUPERSAMPLING; // Ctrl+F4
|
|
||||||
}
|
return firstPressedFrom({InputAction::NEXT_PALETTE_SORT, InputAction::TOGGLE_INTEGER_SCALE, InputAction::TOGGLE_VSYNC, InputAction::TOGGLE_INFO, InputAction::TOGGLE_CONSOLE});
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user