ESC global amb doble pulsació: F12=pausa, BACKSPACE=cancel, text pausa més clar

This commit is contained in:
2026-05-17 18:10:15 +02:00
parent 659e37e5a1
commit a40931c7ca
12 changed files with 104 additions and 66 deletions
+4 -1
View File
@@ -140,7 +140,7 @@ CONTINUAR?
CONTINUAR CONTINUAR
## 47 - MENU DE PAUSA ## 47 - MENU DE PAUSA
EIXIR DEL JOC TORNAR AL TITOL
## 48 - MENU GAME OVER ## 48 - MENU GAME OVER
SI SI
@@ -300,3 +300,6 @@ Shader
## 100 - NOTIFICACIO HOTKEY ## 100 - NOTIFICACIO HOTKEY
Preset Preset
## 101 - NOTIFICACIO HOTKEY
Torna a premer ESC per a eixir
+4 -1
View File
@@ -140,7 +140,7 @@ CONTINUE?
CONTINUE CONTINUE
## 47 - MENU DE PAUSA ## 47 - MENU DE PAUSA
LEAVE GAME BACK TO TITLE
## 48 - MENU GAME OVER ## 48 - MENU GAME OVER
YES YES
@@ -300,3 +300,6 @@ Shader
## 100 - HOTKEY NOTIFICATION ## 100 - HOTKEY NOTIFICATION
Preset Preset
## 101 - HOTKEY NOTIFICATION
Press ESC again to quit
+4 -1
View File
@@ -140,7 +140,7 @@ CONTINUAR?
CONTINUAR CONTINUAR
## 47 - MENU DE PAUSA ## 47 - MENU DE PAUSA
SALIR DEL JUEGO VOLVER AL TITULO
## 48 - MENU GAME OVER ## 48 - MENU GAME OVER
SI SI
@@ -300,3 +300,6 @@ Shader
## 100 - NOTIFICACION HOTKEY ## 100 - NOTIFICACION HOTKEY
Preset Preset
## 101 - NOTIFICACION HOTKEY
Vuelve a pulsar ESC para salir
+29
View File
@@ -17,13 +17,24 @@ namespace GlobalInputs {
constexpr int LANG_WINDOW = 98; constexpr int LANG_WINDOW = 98;
constexpr int LANG_SHADER = 99; constexpr int LANG_SHADER = 99;
constexpr int LANG_PRESET = 100; constexpr int LANG_PRESET = 100;
constexpr int LANG_EXIT_CONFIRM = 101;
constexpr Uint32 NOTIFY_MS = 1500; constexpr Uint32 NOTIFY_MS = 1500;
constexpr Uint32 EXIT_CONFIRM_MS = 2000;
const Color BLACK = {0x00, 0x00, 0x00}; const Color BLACK = {0x00, 0x00, 0x00};
const Color CYAN = {0x00, 0xFF, 0xFF}; const Color CYAN = {0x00, 0xFF, 0xFF};
const Color YELLOW = {0xFF, 0xE0, 0x40}; const Color YELLOW = {0xFF, 0xE0, 0x40};
const Color MAGENTA = {0xFF, 0x00, 0xFF}; const Color MAGENTA = {0xFF, 0x00, 0xFF};
const Color GREEN = {0x00, 0xFF, 0x80}; const Color GREEN = {0x00, 0xFF, 0x80};
const Color RED = {0xFF, 0x40, 0x40};
// Patró de doble pulsació: la primera pulsació d'EXIT mostra una
// notificació en vermell i obre una finestra de confirmació; una
// segona pulsació dins la finestra activa `quit_requested`. La
// finestra coincideix amb la durada del missatge perquè usuari i
// sistema sempre estiguin sincronitzats.
Uint32 exit_window_until_ticks = 0;
bool quit_requested = false;
void notifyZoom() { void notifyZoom() {
const std::string MSG = Lang::get()->getText(LANG_ZOOM) + " " + std::to_string(Options::window.zoom) + "x"; const std::string MSG = Lang::get()->getText(LANG_ZOOM) + " " + std::to_string(Options::window.zoom) + "x";
@@ -51,11 +62,25 @@ namespace GlobalInputs {
const std::string MSG = Lang::get()->getText(LANG_PRESET) + " " + Screen::get()->getCurrentPresetName(); const std::string MSG = Lang::get()->getText(LANG_PRESET) + " " + Screen::get()->getCurrentPresetName();
Screen::get()->notify(MSG, GREEN, BLACK, NOTIFY_MS); Screen::get()->notify(MSG, GREEN, BLACK, NOTIFY_MS);
} }
void onExit() {
const Uint32 NOW = SDL_GetTicks();
if (NOW < exit_window_until_ticks) {
quit_requested = true;
return;
}
exit_window_until_ticks = NOW + EXIT_CONFIRM_MS;
Screen::get()->notify(Lang::get()->getText(LANG_EXIT_CONFIRM), RED, BLACK, EXIT_CONFIRM_MS);
}
} // namespace } // namespace
auto handle() -> bool { auto handle() -> bool {
if (Screen::get() == nullptr || Input::get() == nullptr) { return false; } if (Screen::get() == nullptr || Input::get() == nullptr) { return false; }
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
onExit();
return true;
}
if (Input::get()->checkInput(Input::Action::WINDOW_FULLSCREEN, Input::Repeat::OFF)) { if (Input::get()->checkInput(Input::Action::WINDOW_FULLSCREEN, Input::Repeat::OFF)) {
Screen::get()->toggleVideoMode(); Screen::get()->toggleVideoMode();
notifyFullscreen(); notifyFullscreen();
@@ -95,4 +120,8 @@ namespace GlobalInputs {
return false; return false;
} }
auto wantsQuit() -> bool {
return quit_requested;
}
} // namespace GlobalInputs } // namespace GlobalInputs
+6 -1
View File
@@ -3,9 +3,14 @@
namespace GlobalInputs { namespace GlobalInputs {
// Gestiona els atalls globals disponibles en qualsevol escena: zoom de // Gestiona els atalls globals disponibles en qualsevol escena: zoom de
// finestra (F1/F2), fullscreen (F3), toggle shader (F4), tipus de shader // finestra (F1/F2), fullscreen (F3), toggle shader (F4), tipus de shader
// POSTFX↔CRTPI (F5) i següent preset (F6). Cada hotkey emet una // POSTFX↔CRTPI (F5), següent preset (F6) i la confirmació d'eixida amb
// ESC (Action::EXIT) en dues pulsacions. Cada hotkey emet una
// notificació localitzada. Retorna true si ha consumit alguna tecla (per // notificació localitzada. Retorna true si ha consumit alguna tecla (per
// si la capa cridant vol suprimir-la del processament específic de // si la capa cridant vol suprimir-la del processament específic de
// l'escena). // l'escena).
auto handle() -> bool; auto handle() -> bool;
// True si la doble pulsació d'ESC s'ha confirmat. Director consulta açò
// a iterate() per a posar `section_->name = SECTION_PROG_QUIT`.
[[nodiscard]] auto wantsQuit() -> bool;
} // namespace GlobalInputs } // namespace GlobalInputs
+13 -2
View File
@@ -17,6 +17,7 @@
#include <string> // for basic_string, operator+, char_t... #include <string> // for basic_string, operator+, char_t...
#include "core/audio/audio.hpp" // for Audio::init, Audio::destroy #include "core/audio/audio.hpp" // for Audio::init, Audio::destroy
#include "core/input/global_inputs.hpp" // for GlobalInputs::wantsQuit
#include "core/input/input.h" // for Input, InputAction #include "core/input/input.h" // for Input, InputAction
#include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda... #include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
#include "core/locale/lang.h" // for Lang, Lang::Code #include "core/locale/lang.h" // for Lang, Lang::Code
@@ -218,9 +219,12 @@ void Director::initInput() {
// Teclado - Otros // Teclado - Otros
Input::get()->bindKey(Input::Action::ACCEPT, SDL_SCANCODE_RETURN); Input::get()->bindKey(Input::Action::ACCEPT, SDL_SCANCODE_RETURN);
Input::get()->bindKey(Input::Action::CANCEL, SDL_SCANCODE_ESCAPE); // ESC només dispara EXIT (gestionat globalment per GlobalInputs com a
Input::get()->bindKey(Input::Action::PAUSE, SDL_SCANCODE_ESCAPE); // confirmació de doble pulsació). PAUSE i CANCEL tenen tecles dedicades
// perquè cap escena ha de tractar ESC localment.
Input::get()->bindKey(Input::Action::EXIT, SDL_SCANCODE_ESCAPE); Input::get()->bindKey(Input::Action::EXIT, SDL_SCANCODE_ESCAPE);
Input::get()->bindKey(Input::Action::CANCEL, SDL_SCANCODE_BACKSPACE);
Input::get()->bindKey(Input::Action::PAUSE, SDL_SCANCODE_F12);
Input::get()->bindKey(Input::Action::WINDOW_DEC_ZOOM, SDL_SCANCODE_F1); Input::get()->bindKey(Input::Action::WINDOW_DEC_ZOOM, SDL_SCANCODE_F1);
Input::get()->bindKey(Input::Action::WINDOW_INC_ZOOM, SDL_SCANCODE_F2); Input::get()->bindKey(Input::Action::WINDOW_INC_ZOOM, SDL_SCANCODE_F2);
Input::get()->bindKey(Input::Action::WINDOW_FULLSCREEN, SDL_SCANCODE_F3); Input::get()->bindKey(Input::Action::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
@@ -579,6 +583,13 @@ void Director::handleSectionTransition() {
// Ejecuta un frame del juego // Ejecuta un frame del juego
auto Director::iterate() -> SDL_AppResult { auto Director::iterate() -> SDL_AppResult {
#ifndef __EMSCRIPTEN__
// Doble pulsació d'ESC confirmada des de qualsevol escena.
if (GlobalInputs::wantsQuit()) {
section_->name = SECTION_PROG_QUIT;
}
#endif
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
// En WASM no se puede salir: reinicia al logo // En WASM no se puede salir: reinicia al logo
if (section->name == SECTION_PROG_QUIT) { if (section->name == SECTION_PROG_QUIT) {
+10 -9
View File
@@ -2809,6 +2809,16 @@ void Game::updatePauseMenuUI() {
pause_menu_->update(); pause_menu_->update();
pause_menu_->checkInput(); pause_menu_->checkInput();
// F12 (Action::PAUSE) també tanca el menú de pausa — mateix comportament
// que seleccionar "Continue" / cancel·lar amb BACKSPACE.
if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF)) {
leaving_pause_menu_ = true;
if (!Options::gameplay.pause_countdown) {
pause_counter_ = 0;
}
return;
}
switch (pause_menu_->getItemSelected()) { switch (pause_menu_->getItemSelected()) {
case 1: case 1:
leaving_pause_menu_ = true; leaving_pause_menu_ = true;
@@ -2884,15 +2894,6 @@ void Game::enterPausedGame() {
Audio::get()->pauseMusic(); Audio::get()->pauseMusic();
} }
// ESC esta vinculada a PAUSE, CANCEL y EXIT a la vez (director.cpp), y cada
// Action tiene su propio flag de edge-trigger. La pulsacion que nos ha
// traido aqui solo ha actualizado el flag de PAUSE; CANCEL y EXIT siguen
// a false y dispararian un falso flanco la primera vez que el menu de
// pausa los lea. Hacemos una lectura sincronizadora descartada para
// ponerlos al dia con el estado real de la tecla.
Input::get()->checkInput(Input::Action::CANCEL, Input::Repeat::OFF);
Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF);
// Reinicia el menu // Reinicia el menu
pause_menu_->reset(); pause_menu_->reset();
leaving_pause_menu_ = false; leaving_pause_menu_ = false;
+2 -7
View File
@@ -210,13 +210,8 @@ void Instructions::checkEvents() {
// Comprueba las entradas // Comprueba las entradas
void Instructions::checkInput() { void Instructions::checkInput() {
#ifndef __EMSCRIPTEN__ // ESC (Action::EXIT) ja el gestiona GlobalInputs::handle() amb doble
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) { // pulsació; el quit es propaga via Director::iterate.
quit_requested_ = true;
finished_ = true;
return;
}
#endif
if (GlobalInputs::handle()) { return; } if (GlobalInputs::handle()) { return; }
if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) { if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
+2 -6
View File
@@ -166,12 +166,8 @@ Intro::~Intro() {
// Comprueba las entradas // Comprueba las entradas
void Intro::checkInput() { void Intro::checkInput() {
#ifndef __EMSCRIPTEN__ // ESC (Action::EXIT) ja el gestiona GlobalInputs::handle() amb doble
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) { // pulsació; el quit es propaga via Director::iterate.
section_->name = SECTION_PROG_QUIT;
return;
}
#endif
if (GlobalInputs::handle()) { return; } if (GlobalInputs::handle()) { return; }
if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) { if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
+2 -6
View File
@@ -56,12 +56,8 @@ void Logo::checkLogoEnd() {
// Comprueba las entradas // Comprueba las entradas
void Logo::checkInput() { void Logo::checkInput() {
#ifndef __EMSCRIPTEN__ // ESC (Action::EXIT) ja el gestiona GlobalInputs::handle() amb doble
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) { // pulsació; el quit es propaga via Director::iterate.
section_->name = SECTION_PROG_QUIT;
return;
}
#endif
if (GlobalInputs::handle()) { return; } if (GlobalInputs::handle()) { return; }
if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) { if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
+3 -7
View File
@@ -619,14 +619,10 @@ void Title::render() {
} }
} }
// Comprueba las entradas // Comprueba las entradas. ESC (Action::EXIT) ja el gestiona
// GlobalInputs::handle() amb doble pulsació; el quit es propaga via
// Director::iterate.
void Title::checkInput() { void Title::checkInput() {
#ifndef __EMSCRIPTEN__
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
section_->name = SECTION_PROG_QUIT;
return;
}
#endif
GlobalInputs::handle(); GlobalInputs::handle();
} }
+1 -1
View File
@@ -108,7 +108,7 @@ class Title {
void init(); // Inicializa los valores void init(); // Inicializa los valores
void update(); // Actualiza las variables del objeto void update(); // Actualiza las variables del objeto
void render(); // Dibuja el objeto en pantalla void render(); // Dibuja el objeto en pantalla
void checkInput(); // Comprueba las entradas static void checkInput(); // Comprueba las entradas (només delega a GlobalInputs)
// Helpers de update, uno por cada subsección y por cada switch dentro del título 3 // Helpers de update, uno por cada subsección y por cada switch dentro del título 3
void updateTitle1(); void updateTitle1();