GlobalInputs: ja es pot eixir del joc mentre redefinixes botons
This commit is contained in:
@@ -35,14 +35,13 @@ DefineButtons::DefineButtons()
|
||||
config.text_safety_margin = 15.0F;
|
||||
config.min_width = 100;
|
||||
config.min_height = 32;
|
||||
config.animation_duration = 0.5F;
|
||||
config.animation_duration = 0.3F;
|
||||
|
||||
auto text_renderer = Resource::get()->getText("04b_25_flat");
|
||||
window_message_ = std::make_unique<WindowMessage>(
|
||||
text_renderer,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -56,20 +55,20 @@ void DefineButtons::update() {
|
||||
if (!enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Actualizar la ventana siempre
|
||||
if (window_message_) {
|
||||
window_message_->update();
|
||||
}
|
||||
|
||||
|
||||
// Manejar la secuencia de cierre si ya terminamos
|
||||
if (finished_ && message_shown_) {
|
||||
message_timer_++;
|
||||
|
||||
|
||||
// Después del delay, iniciar animación de cierre (solo una vez)
|
||||
if (message_timer_ > MESSAGE_DISPLAY_FRAMES && !closing_) {
|
||||
if (window_message_) {
|
||||
window_message_->hide(); // Iniciar animación de cierre
|
||||
window_message_->hide(); // Iniciar animación de cierre
|
||||
}
|
||||
closing_ = true;
|
||||
}
|
||||
@@ -97,6 +96,8 @@ auto DefineButtons::enable(Options::Gamepad *options_gamepad) -> bool {
|
||||
enabled_ = true;
|
||||
finished_ = false;
|
||||
index_button_ = 0;
|
||||
message_shown_ = false;
|
||||
closing_ = false;
|
||||
clearButtons();
|
||||
updateWindowMessage();
|
||||
|
||||
@@ -113,6 +114,8 @@ auto DefineButtons::enable(Options::Gamepad *options_gamepad) -> bool {
|
||||
void DefineButtons::disable() {
|
||||
enabled_ = false;
|
||||
finished_ = false;
|
||||
message_shown_ = false;
|
||||
closing_ = false;
|
||||
|
||||
if (window_message_) {
|
||||
window_message_->hide();
|
||||
@@ -187,11 +190,11 @@ void DefineButtons::checkEnd() {
|
||||
bool DefineButtons::isReadyToClose() const {
|
||||
// Solo está listo para cerrar si:
|
||||
// 1. Terminó
|
||||
// 2. Ya mostró el mensaje
|
||||
// 2. Ya mostró el mensaje
|
||||
// 3. Está cerrando
|
||||
// 4. La ventana ya no está visible (animación terminada)
|
||||
return finished_ && message_shown_ && closing_ &&
|
||||
(!window_message_ || !window_message_->isVisible());
|
||||
return finished_ && message_shown_ && closing_ &&
|
||||
(!window_message_ || !window_message_->isVisible());
|
||||
}
|
||||
|
||||
void DefineButtons::updateWindowMessage() {
|
||||
|
||||
@@ -40,7 +40,7 @@ class DefineButtons {
|
||||
|
||||
private:
|
||||
// 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
|
||||
Input *input_ = nullptr; // Entrada del usuario
|
||||
|
||||
@@ -171,109 +171,60 @@ auto checkServiceButton() -> bool {
|
||||
}
|
||||
|
||||
// Mandos
|
||||
{
|
||||
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)) {
|
||||
toggleServiceMenu();
|
||||
return true;
|
||||
}
|
||||
for (auto gamepad : Input::get()->getGamepads()) {
|
||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
toggleServiceMenu();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba las entradas para elementos del sistema
|
||||
auto checkSystemInputs() -> bool {
|
||||
using Action = Input::Action;
|
||||
|
||||
static const std::vector<std::pair<Action, std::function<void()>>> actions = {
|
||||
{Action::WINDOW_FULLSCREEN, toggleFullscreen},
|
||||
{Action::WINDOW_DEC_SIZE, decWindowSize},
|
||||
{Action::WINDOW_INC_SIZE, incWindowSize},
|
||||
{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 false;
|
||||
}
|
||||
|
||||
// Comprueba el resto de entradas
|
||||
auto checkOtherInputs() -> bool {
|
||||
// Saltar sección
|
||||
if ((Input::get()->checkAnyButton()) && !ServiceMenu::get()->isEnabled()) {
|
||||
skipSection();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba las entradas fuera del menú de servicio
|
||||
auto checkInputs() -> bool {
|
||||
// Teclado
|
||||
{
|
||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
Screen::get()->toggleFullscreen();
|
||||
const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10");
|
||||
Notifier::get()->show({MODE});
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
// Saltar sección
|
||||
if ((Input::get()->checkAnyButton()) && !ServiceMenu::get()->isEnabled()) {
|
||||
skipSection();
|
||||
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;
|
||||
// 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
|
||||
@@ -281,12 +232,15 @@ auto check() -> bool {
|
||||
if (checkServiceButton()) {
|
||||
return true;
|
||||
}
|
||||
if (ServiceMenu::get()->checkInput()) {
|
||||
if (checkServiceMenuInputs()) {
|
||||
return true;
|
||||
}
|
||||
if (checkInputs()) {
|
||||
if (checkSystemInputs()) {
|
||||
return true;
|
||||
}
|
||||
if (checkOtherInputs()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace GlobalInputs
|
||||
} // namespace GlobalInputs
|
||||
|
||||
@@ -547,7 +547,7 @@ void ServiceMenu::handleEvent(const SDL_Event &event) {
|
||||
// Si DefineButtons está activo, que maneje todos los eventos
|
||||
if (define_buttons_ && define_buttons_->isEnabled()) {
|
||||
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()) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static auto input = Input::get();
|
||||
// --- Teclado ---
|
||||
// Arriba
|
||||
if (input->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
setSelectorUp();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Abajo
|
||||
if (input->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
setSelectorDown();
|
||||
return true;
|
||||
}
|
||||
using Action = Input::Action;
|
||||
|
||||
// Derecha
|
||||
if (input->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
adjustOption(true);
|
||||
return true;
|
||||
}
|
||||
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(); } },
|
||||
};
|
||||
|
||||
// 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();
|
||||
// Teclado
|
||||
for (const auto& [action, func] : actions) {
|
||||
if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
func();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Mandos
|
||||
for (auto gamepad : input->getGamepads()) {
|
||||
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 false;
|
||||
}
|
||||
Reference in New Issue
Block a user