ESC global amb doble pulsació: F12=pausa, BACKSPACE=cancel, text pausa més clar
This commit is contained in:
@@ -17,13 +17,24 @@ namespace GlobalInputs {
|
||||
constexpr int LANG_WINDOW = 98;
|
||||
constexpr int LANG_SHADER = 99;
|
||||
constexpr int LANG_PRESET = 100;
|
||||
constexpr int LANG_EXIT_CONFIRM = 101;
|
||||
|
||||
constexpr Uint32 NOTIFY_MS = 1500;
|
||||
constexpr Uint32 EXIT_CONFIRM_MS = 2000;
|
||||
const Color BLACK = {0x00, 0x00, 0x00};
|
||||
const Color CYAN = {0x00, 0xFF, 0xFF};
|
||||
const Color YELLOW = {0xFF, 0xE0, 0x40};
|
||||
const Color MAGENTA = {0xFF, 0x00, 0xFF};
|
||||
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() {
|
||||
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();
|
||||
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
|
||||
|
||||
auto handle() -> bool {
|
||||
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)) {
|
||||
Screen::get()->toggleVideoMode();
|
||||
notifyFullscreen();
|
||||
@@ -95,4 +120,8 @@ namespace GlobalInputs {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto wantsQuit() -> bool {
|
||||
return quit_requested;
|
||||
}
|
||||
|
||||
} // namespace GlobalInputs
|
||||
|
||||
@@ -3,9 +3,14 @@
|
||||
namespace GlobalInputs {
|
||||
// Gestiona els atalls globals disponibles en qualsevol escena: zoom de
|
||||
// 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
|
||||
// si la capa cridant vol suprimir-la del processament específic de
|
||||
// l'escena).
|
||||
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
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
#include <memory>
|
||||
#include <string> // for basic_string, operator+, char_t...
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio::init, Audio::destroy
|
||||
#include "core/input/input.h" // for Input, InputAction
|
||||
#include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
|
||||
#include "core/locale/lang.h" // for Lang, Lang::Code
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/resources/asset.h" // for Asset, Asset::Type
|
||||
#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/mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
|
||||
#include "core/locale/lang.h" // for Lang, Lang::Code
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/resources/asset.h" // for Asset, Asset::Type
|
||||
#include "core/resources/resource.h"
|
||||
#include "core/resources/resource_helper.h"
|
||||
#include "game/defaults.hpp" // for SECTION_PROG_LOGO, GAMECANVAS_H...
|
||||
@@ -218,9 +219,12 @@ void Director::initInput() {
|
||||
|
||||
// Teclado - Otros
|
||||
Input::get()->bindKey(Input::Action::ACCEPT, SDL_SCANCODE_RETURN);
|
||||
Input::get()->bindKey(Input::Action::CANCEL, SDL_SCANCODE_ESCAPE);
|
||||
Input::get()->bindKey(Input::Action::PAUSE, SDL_SCANCODE_ESCAPE);
|
||||
// ESC només dispara EXIT (gestionat globalment per GlobalInputs com a
|
||||
// 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::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_INC_ZOOM, SDL_SCANCODE_F2);
|
||||
Input::get()->bindKey(Input::Action::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
|
||||
@@ -579,6 +583,13 @@ void Director::handleSectionTransition() {
|
||||
|
||||
// Ejecuta un frame del juego
|
||||
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__
|
||||
// En WASM no se puede salir: reinicia al logo
|
||||
if (section->name == SECTION_PROG_QUIT) {
|
||||
|
||||
Reference in New Issue
Block a user