From 4252f3327fa8ceaac25285fb09f8248156013dc9 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 21 May 2026 08:24:22 +0200 Subject: [PATCH] =?UTF-8?q?fix(notifier):=20ESC=20nom=C3=A9s=20confirma=20?= =?UTF-8?q?sobre=20el=20propi=20prompt=20de=20sortida?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/core/system/global_events.cpp | 14 +++++++------- source/core/system/notifier.cpp | 10 +++++++++- source/core/system/notifier.hpp | 10 ++++++++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/source/core/system/global_events.cpp b/source/core/system/global_events.cpp index a2f2183..afd1e3b 100644 --- a/source/core/system/global_events.cpp +++ b/source/core/system/global_events.cpp @@ -60,18 +60,18 @@ namespace GlobalEvents { 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. + // dispara un toast d'avís; només si aquest toast concret + // (isExitPromptActive) segueix visible, la segona ESC + // tanca el joc. Si la notificació activa és una altra + // (zoom, fullscreen, vsync...), ESC obre el prompt de + // sortida en lloc de tancar. auto* notifier = System::Notifier::get(); - if (notifier != nullptr && !notifier->isActiveWindow()) { + if (notifier != nullptr && !notifier->isExitPromptActive()) { 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. + // sobre el prompt de sortida: tanquem el joc. context.setNextScene(SceneType::EXIT); SceneManager::actual = SceneType::EXIT; return true; diff --git a/source/core/system/notifier.cpp b/source/core/system/notifier.cpp index e93fc04..b44f756 100644 --- a/source/core/system/notifier.cpp +++ b/source/core/system/notifier.cpp @@ -77,6 +77,7 @@ namespace System { current_text_ = text; current_color_ = text_color; hold_remaining_s_ = duration_s; + current_is_exit_ = false; const float TEXT_W = Graphics::VectorText::getTextWidth(text, TEXT_SCALE, TEXT_SPACING); const float TEXT_H = Graphics::VectorText::getTextHeight(TEXT_SCALE); @@ -100,7 +101,10 @@ namespace System { void Notifier::notifyInfo(const std::string& text) { notify(text, COLOR_INFO, DURATION_INFO); } void Notifier::notifyWarn(const std::string& text) { notify(text, COLOR_WARN, DURATION_WARN); } - void Notifier::notifyExit(const std::string& text) { notify(text, COLOR_EXIT, DURATION_EXIT); } + void Notifier::notifyExit(const std::string& text) { + notify(text, COLOR_EXIT, DURATION_EXIT); + current_is_exit_ = true; // notify() ho ha posat a false; restaurem. + } void Notifier::update(float delta_time) { switch (status_) { @@ -183,4 +187,8 @@ namespace System { return status_ == Status::ENTERING || status_ == Status::HOLDING; } + auto Notifier::isExitPromptActive() const -> bool { + return isActiveWindow() && current_is_exit_; + } + } // namespace System diff --git a/source/core/system/notifier.hpp b/source/core/system/notifier.hpp index 6bd3cda..b933ac7 100644 --- a/source/core/system/notifier.hpp +++ b/source/core/system/notifier.hpp @@ -47,10 +47,15 @@ namespace System { void draw() const; // Activa mentre el toast està entrant o aguantant. Quan està sortint - // o ja amagat, retorna false. Útil per a la lògica de doble-pulsació - // d'ESC: la segona pulsació només confirma sortida si encara aguanta. + // o ja amagat, retorna false. [[nodiscard]] auto isActiveWindow() const -> bool; + // Cert només si el toast actiu va ser disparat per notifyExit(). + // Per a la doble-pulsació d'ESC: la segona ESC confirma sortida + // únicament si la notificació visible és la de confirmació; si era + // de F1/F2/etc., ESC torna a obrir el prompt sense tancar. + [[nodiscard]] auto isExitPromptActive() const -> bool; + private: explicit Notifier(Rendering::Renderer* renderer); @@ -74,6 +79,7 @@ namespace System { float box_h_{0.0F}; float text_x_{0.0F}; // X esquerre del text dins la caixa float text_scale_{0.4F}; + bool current_is_exit_{false}; // true només si l'actiu ve de notifyExit() static std::unique_ptr instance; };