From 9eb8c58d87a6b69d1a51d99aea45b25f7f738626 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 20 May 2026 22:11:43 +0200 Subject: [PATCH] =?UTF-8?q?feat(notifier):=20doble=20pulsaci=C3=B3=20d'ESC?= =?UTF-8?q?=20per=20confirmar=20sortida?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La primera ESC ja no tanca el joc directament: dispara un toast "PREMEU ESC UN ALTRE COP PER EIXIR" en vermell. Mentre el toast està entrant o aguantant (Notifier::isActiveWindow()), una segona ESC confirma i tanca. Si l'usuari espera a que el toast comenci a sortir o desaparegui, ESC torna a obrir la finestra de confirmació sense tancar — només una doble pulsació consecutiva tanca. Si el Notifier no existeix (no hauria de passar dins runFrameLoop), ESC manté el comportament antic de tancar directament. Co-Authored-By: Claude Opus 4.7 (1M context) --- source/core/system/global_events.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/core/system/global_events.cpp b/source/core/system/global_events.cpp index 3615126..a2f2183 100644 --- a/source/core/system/global_events.cpp +++ b/source/core/system/global_events.cpp @@ -8,6 +8,7 @@ #include "core/input/input.hpp" #include "core/input/mouse.hpp" #include "core/rendering/sdl_manager.hpp" +#include "core/system/notifier.hpp" #include "scene_context.hpp" // Using declarations per simplificar el codi @@ -57,10 +58,24 @@ namespace GlobalEvents { sdl.toggleAntialias(); return true; - case SDL_SCANCODE_ESCAPE: + case SDL_SCANCODE_ESCAPE: { + // Doble pulsació per confirmar sortida: la primera ESC + // dispara un toast d'avís; mentre el toast està entrant + // o aguantant (isActiveWindow), la segona ESC tanca el + // joc. Si el toast ha començat a sortir o ja ha + // desaparegut, ESC torna a obrir la finestra de + // confirmació sense tancar. + auto* notifier = System::Notifier::get(); + if (notifier != nullptr && !notifier->isActiveWindow()) { + notifier->notifyExit("PREMEU ESC UN ALTRE COP PER EIXIR"); + return true; + } + // Notifier inexistent (degradació elegant) o segona ESC + // dins la finestra activa: tanquem el joc. context.setNextScene(SceneType::EXIT); SceneManager::actual = SceneType::EXIT; return true; + } default: // Tecla no global