fix(notifier): ESC només confirma sobre el propi prompt de sortida
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Notifier> instance;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user