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