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: {
|
case SDL_SCANCODE_ESCAPE: {
|
||||||
// Doble pulsació per confirmar sortida: la primera ESC
|
// Doble pulsació per confirmar sortida: la primera ESC
|
||||||
// dispara un toast d'avís; mentre el toast està entrant
|
// dispara un toast d'avís; només si aquest toast concret
|
||||||
// o aguantant (isActiveWindow), la segona ESC tanca el
|
// (isExitPromptActive) segueix visible, la segona ESC
|
||||||
// joc. Si el toast ha començat a sortir o ja ha
|
// tanca el joc. Si la notificació activa és una altra
|
||||||
// desaparegut, ESC torna a obrir la finestra de
|
// (zoom, fullscreen, vsync...), ESC obre el prompt de
|
||||||
// confirmació sense tancar.
|
// sortida en lloc de tancar.
|
||||||
auto* notifier = System::Notifier::get();
|
auto* notifier = System::Notifier::get();
|
||||||
if (notifier != nullptr && !notifier->isActiveWindow()) {
|
if (notifier != nullptr && !notifier->isExitPromptActive()) {
|
||||||
notifier->notifyExit("PREMEU ESC UN ALTRE COP PER EIXIR");
|
notifier->notifyExit("PREMEU ESC UN ALTRE COP PER EIXIR");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Notifier inexistent (degradació elegant) o segona ESC
|
// 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);
|
context.setNextScene(SceneType::EXIT);
|
||||||
SceneManager::actual = SceneType::EXIT;
|
SceneManager::actual = SceneType::EXIT;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ namespace System {
|
|||||||
current_text_ = text;
|
current_text_ = text;
|
||||||
current_color_ = text_color;
|
current_color_ = text_color;
|
||||||
hold_remaining_s_ = duration_s;
|
hold_remaining_s_ = duration_s;
|
||||||
|
current_is_exit_ = false;
|
||||||
|
|
||||||
const float TEXT_W = Graphics::VectorText::getTextWidth(text, TEXT_SCALE, TEXT_SPACING);
|
const float TEXT_W = Graphics::VectorText::getTextWidth(text, TEXT_SCALE, TEXT_SPACING);
|
||||||
const float TEXT_H = Graphics::VectorText::getTextHeight(TEXT_SCALE);
|
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::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::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) {
|
void Notifier::update(float delta_time) {
|
||||||
switch (status_) {
|
switch (status_) {
|
||||||
@@ -183,4 +187,8 @@ namespace System {
|
|||||||
return status_ == Status::ENTERING || status_ == Status::HOLDING;
|
return status_ == Status::ENTERING || status_ == Status::HOLDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Notifier::isExitPromptActive() const -> bool {
|
||||||
|
return isActiveWindow() && current_is_exit_;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace System
|
} // namespace System
|
||||||
|
|||||||
@@ -47,10 +47,15 @@ namespace System {
|
|||||||
void draw() const;
|
void draw() const;
|
||||||
|
|
||||||
// Activa mentre el toast està entrant o aguantant. Quan està sortint
|
// 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ó
|
// o ja amagat, retorna false.
|
||||||
// d'ESC: la segona pulsació només confirma sortida si encara aguanta.
|
|
||||||
[[nodiscard]] auto isActiveWindow() const -> bool;
|
[[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:
|
private:
|
||||||
explicit Notifier(Rendering::Renderer* renderer);
|
explicit Notifier(Rendering::Renderer* renderer);
|
||||||
|
|
||||||
@@ -74,6 +79,7 @@ namespace System {
|
|||||||
float box_h_{0.0F};
|
float box_h_{0.0F};
|
||||||
float text_x_{0.0F}; // X esquerre del text dins la caixa
|
float text_x_{0.0F}; // X esquerre del text dins la caixa
|
||||||
float text_scale_{0.4F};
|
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;
|
static std::unique_ptr<Notifier> instance;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user