GlobalInputs: ja es pot eixir del joc mentre redefinixes botons

This commit is contained in:
2025-08-08 18:55:18 +02:00
parent 3b07b2e130
commit 6f120dd4d2
4 changed files with 95 additions and 184 deletions

View File

@@ -35,14 +35,13 @@ DefineButtons::DefineButtons()
config.text_safety_margin = 15.0F; config.text_safety_margin = 15.0F;
config.min_width = 100; config.min_width = 100;
config.min_height = 32; config.min_height = 32;
config.animation_duration = 0.5F; config.animation_duration = 0.3F;
auto text_renderer = Resource::get()->getText("04b_25_flat"); auto text_renderer = Resource::get()->getText("04b_25_flat");
window_message_ = std::make_unique<WindowMessage>( window_message_ = std::make_unique<WindowMessage>(
text_renderer, text_renderer,
Lang::getText("[DEFINE_BUTTONS] TITLE"), Lang::getText("[DEFINE_BUTTONS] TITLE"),
config config);
);
window_message_->setPosition(param.game.game_area.center_x, param.game.game_area.center_y, WindowMessage::PositionMode::CENTERED); window_message_->setPosition(param.game.game_area.center_x, param.game.game_area.center_y, WindowMessage::PositionMode::CENTERED);
} }
@@ -97,6 +96,8 @@ auto DefineButtons::enable(Options::Gamepad *options_gamepad) -> bool {
enabled_ = true; enabled_ = true;
finished_ = false; finished_ = false;
index_button_ = 0; index_button_ = 0;
message_shown_ = false;
closing_ = false;
clearButtons(); clearButtons();
updateWindowMessage(); updateWindowMessage();
@@ -113,6 +114,8 @@ auto DefineButtons::enable(Options::Gamepad *options_gamepad) -> bool {
void DefineButtons::disable() { void DefineButtons::disable() {
enabled_ = false; enabled_ = false;
finished_ = false; finished_ = false;
message_shown_ = false;
closing_ = false;
if (window_message_) { if (window_message_) {
window_message_->hide(); window_message_->hide();

View File

@@ -40,7 +40,7 @@ class DefineButtons {
private: private:
// Constante para cuánto tiempo mostrar el mensaje (en frames) // Constante para cuánto tiempo mostrar el mensaje (en frames)
static constexpr size_t MESSAGE_DISPLAY_FRAMES = 180; // ~3 segundos a 60fps static constexpr size_t MESSAGE_DISPLAY_FRAMES = 120; // ~2 segundos a 60fps
// Punteros // Punteros
Input *input_ = nullptr; // Entrada del usuario Input *input_ = nullptr; // Entrada del usuario

View File

@@ -171,120 +171,74 @@ auto checkServiceButton() -> bool {
} }
// Mandos // Mandos
{ for (auto gamepad : Input::get()->getGamepads()) {
auto gamepads = Input::get()->getGamepads();
for (auto gamepad : gamepads) {
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) { if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
toggleServiceMenu(); toggleServiceMenu();
return true; return true;
} }
} }
}
return false; return false;
} }
// Comprueba las entradas fuera del menú de servicio // Comprueba las entradas para elementos del sistema
auto checkInputs() -> bool { auto checkSystemInputs() -> bool {
// Teclado using Action = Input::Action;
{
// Comprueba el teclado para cambiar entre pantalla completa y ventana static const std::vector<std::pair<Action, std::function<void()>>> actions = {
if (Input::get()->checkAction(Input::Action::WINDOW_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) { {Action::WINDOW_FULLSCREEN, toggleFullscreen},
Screen::get()->toggleFullscreen(); {Action::WINDOW_DEC_SIZE, decWindowSize},
const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10"); {Action::WINDOW_INC_SIZE, incWindowSize},
Notifier::get()->show({MODE}); {Action::EXIT, quit},
{Action::RESET, reset},
{Action::TOGGLE_AUDIO, toggleAudio},
{Action::TOGGLE_AUTO_FIRE, toggleFireMode},
{Action::CHANGE_LANG, changeLang},
{Action::TOGGLE_VIDEO_SHADERS, toggleShaders},
{Action::TOGGLE_VIDEO_INTEGER_SCALE, toggleIntegerScale},
{Action::TOGGLE_VIDEO_VSYNC, toggleVSync},
#ifdef _DEBUG
{Action::SHOW_INFO, [] { Screen::get()->toggleDebugInfo(); }},
#endif
};
for (const auto& [action, func] : actions) {
if (Input::get()->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
func();
return true; return true;
} }
// Comprueba el teclado para decrementar el tamaño de la ventana
if (Input::get()->checkAction(Input::Action::WINDOW_DEC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
if (Screen::get()->decWindowSize()) {
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
}
return true;
} }
// Comprueba el teclado para incrementar el tamaño de la ventana return false;
if (Input::get()->checkAction(Input::Action::WINDOW_INC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) { }
if (Screen::get()->incWindowSize()) {
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
}
return true;
}
// Salir
if (Input::get()->checkAction(Input::Action::EXIT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
quit();
return true;
}
// Comprueba el resto de entradas
auto checkOtherInputs() -> bool {
// Saltar sección // Saltar sección
if ((Input::get()->checkAnyButton()) && !ServiceMenu::get()->isEnabled()) { if ((Input::get()->checkAnyButton()) && !ServiceMenu::get()->isEnabled()) {
skipSection(); skipSection();
return true; return true;
} }
// Reset
if (Input::get()->checkAction(Input::Action::RESET, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
reset();
return true;
}
// Audio
if (Input::get()->checkAction(Input::Action::TOGGLE_AUDIO, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
toggleAudio();
return true;
}
// Autofire
if (Input::get()->checkAction(Input::Action::TOGGLE_AUTO_FIRE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
toggleFireMode();
return true;
}
// Idioma
if (Input::get()->checkAction(Input::Action::CHANGE_LANG, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
changeLang();
return true;
}
// Shaders
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_SHADERS, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
toggleShaders();
return true;
}
// Integer Scale
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
toggleIntegerScale();
return true;
}
// VSync
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_VSYNC, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
toggleVSync();
return true;
}
#ifdef _DEBUG
// Debug info
if (Input::get()->checkAction(Input::Action::SHOW_INFO, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
Screen::get()->toggleDebugInfo();
return true;
}
#endif
}
return false; return false;
} }
// Comprueba las entradas del Menu de Servicio
inline auto checkServiceMenuInputs() -> bool {
return ServiceMenu::get()->checkInput();
}
// Comprueba los inputs que se pueden introducir en cualquier sección del juego // Comprueba los inputs que se pueden introducir en cualquier sección del juego
auto check() -> bool { auto check() -> bool {
if (checkServiceButton()) { if (checkServiceButton()) {
return true; return true;
} }
if (ServiceMenu::get()->checkInput()) { if (checkServiceMenuInputs()) {
return true; return true;
} }
if (checkInputs()) { if (checkSystemInputs()) {
return true;
}
if (checkOtherInputs()) {
return true; return true;
} }
return false; return false;

View File

@@ -547,7 +547,7 @@ void ServiceMenu::handleEvent(const SDL_Event &event) {
// Si DefineButtons está activo, que maneje todos los eventos // Si DefineButtons está activo, que maneje todos los eventos
if (define_buttons_ && define_buttons_->isEnabled()) { if (define_buttons_ && define_buttons_->isEnabled()) {
define_buttons_->checkEvents(event); define_buttons_->checkEvents(event);
return; // No procesar otros eventos mientras DefineButtons está activo //return; // No procesar otros eventos mientras DefineButtons está activo
} }
} }
@@ -557,85 +557,39 @@ bool ServiceMenu::checkInput() {
} }
if (define_buttons_ && define_buttons_->isEnabled()) { if (define_buttons_ && define_buttons_->isEnabled()) {
return true; return false;
} }
static auto input = Input::get(); static auto input = Input::get();
// --- Teclado ---
// Arriba using Action = Input::Action;
if (input->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
setSelectorUp(); const std::vector<std::pair<Action, std::function<void()>>> actions = {
{ Action::UP, [this]() { setSelectorUp(); } },
{ Action::DOWN, [this]() { setSelectorDown(); } },
{ Action::RIGHT, [this]() { adjustOption(true); } },
{ Action::LEFT, [this]() { adjustOption(false); } },
{ Action::SM_SELECT, [this]() { selectOption(); } },
{ Action::SM_BACK, [this]() { moveBack(); } },
};
// Teclado
for (const auto& [action, func] : actions) {
if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
func();
return true; return true;
} }
}
// Abajo // Mandos
if (input->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) { for (auto gamepad : input->getGamepads()) {
setSelectorDown(); for (const auto& [action, func] : actions) {
if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
func();
return true; return true;
} }
}
}
// Derecha
if (input->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
adjustOption(true);
return true;
}
// Izquierda
if (input->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
adjustOption(false);
return true;
}
// Aceptar
if (input->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
selectOption();
return true;
}
// Atras
if (input->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
moveBack();
return true;
}
// --- Mandos ---
auto gamepads = input->getGamepads();
for (auto gamepad : gamepads) {
// Arriba
if (input->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
setSelectorUp();
return true;
}
// Abajo
if (input->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
setSelectorDown();
return true;
}
// Derecha
if (input->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
adjustOption(true);
return true;
}
// Izquierda
if (input->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
adjustOption(false);
return true;
}
// Aceptar
if (input->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
selectOption();
return true;
}
// Atras
if (input->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
moveBack();
return true;
}
}
return false; return false;
} }