From cd96be80f9efedf195ebcc559d137808b4bc611c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sat, 1 Mar 2025 22:49:03 +0100 Subject: [PATCH] Afegit Cheevos::clearUnobtainableState(); --- source/cheevos.cpp | 17 +++++++++++++---- source/cheevos.h | 15 +++++++++------ source/game.cpp | 5 +++-- source/title.cpp | 2 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/source/cheevos.cpp b/source/cheevos.cpp index 2e19896..bba100a 100644 --- a/source/cheevos.cpp +++ b/source/cheevos.cpp @@ -80,7 +80,7 @@ void Cheevos::unlock(int id) const int index = find(id); // Si el índice es inválido, el logro no es válido, ya está completado o el sistema de logros no está habilitado, no hacemos nada - if (index == -1 || !cheevos_list_.at(index).valid || cheevos_list_.at(index).completed || !enabled_) + if (index == -1 || !cheevos_list_.at(index).obtainable || cheevos_list_.at(index).completed || !enabled_) { return; } @@ -94,14 +94,14 @@ void Cheevos::unlock(int id) } // Invalida un logro -void Cheevos::invalidate(int id) +void Cheevos::setUnobtainable(int id) { const int index = find(id); // Si el índice es válido, se invalida el logro if (index != -1) { - cheevos_list_.at(index).valid = false; + cheevos_list_.at(index).obtainable = false; } } @@ -184,7 +184,7 @@ void Cheevos::saveToFile() } // Devuelve el número total de logros desbloqueados -int Cheevos::unlocked() +int Cheevos::getTotalUnlockedAchievements() { int count = 0; for (const auto &cheevo : cheevos_list_) @@ -195,4 +195,13 @@ int Cheevos::unlocked() } } return count; +} + +// Elimina el estado "no obtenible" +void Cheevos::clearUnobtainableState() +{ + for (auto &cheevo : cheevos_list_) + { + cheevo.obtainable = true; + } } \ No newline at end of file diff --git a/source/cheevos.h b/source/cheevos.h index 7d5cc2a..1387094 100644 --- a/source/cheevos.h +++ b/source/cheevos.h @@ -11,14 +11,14 @@ struct Achievement std::string description; // Texto que describe el logro int icon; // Indice del icono a utilizar en la notificación bool completed; // Indica si se ha obtenido el logro - bool valid; // Indica si se puede obtener el logro + bool obtainable; // Indica si se puede obtener el logro // Constructor vacío - Achievement() : id(0), icon(0), completed(false), valid(true) {} + Achievement() : id(0), icon(0), completed(false), obtainable(true) {} // Constructor parametrizado - Achievement(int id, const std::string &caption, const std::string &description, int icon, bool completed = false, bool valid = true) - : id(id), caption(caption), description(description), icon(icon), completed(completed), valid(valid) {} + Achievement(int id, const std::string &caption, const std::string &description, int icon, bool completed = false, bool obtainable = true) + : id(id), caption(caption), description(description), icon(icon), completed(completed), obtainable(obtainable) {} }; class Cheevos @@ -64,7 +64,10 @@ public: void unlock(int id); // Invalida un logro - void invalidate(int id); + void setUnobtainable(int id); + + // Elimina el estado "no obtenible" + void clearUnobtainableState(); // Habilita o deshabilita los logros void enable(bool value) { enabled_ = value; } @@ -73,7 +76,7 @@ public: std::vector list() { return cheevos_list_; } // Devuelve el número total de logros desbloqueados - int unlocked(); + int getTotalUnlockedAchievements(); // Devuelve el número total de logros int size() { return cheevos_list_.size(); } diff --git a/source/game.cpp b/source/game.cpp index 2274796..8eea285 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -55,6 +55,7 @@ Game::Game() changeRoom(current_room_); Cheevos::get()->enable(!options.cheats.enabled()); // Deshabilita los logros si hay trucos activados + Cheevos::get()->clearUnobtainableState(); options.section.section = Section::GAME; options.section.subsection = Subsection::NONE; @@ -392,7 +393,7 @@ void Game::killPlayer() stats_->addDeath(room_->getName()); // Invalida el logro de pasarse el juego sin morir - Cheevos::get()->invalidate(11); + Cheevos::get()->setUnobtainable(11); // Sonido JA_PlaySound(Resource::get()->getSound("death.wav")); @@ -530,7 +531,7 @@ void Game::checkRestoringJail() const bool haveTheItems = board_->items >= int(total_items_ * 0.9f); if (!haveTheItems) { - Cheevos::get()->invalidate(9); + Cheevos::get()->setUnobtainable(9); } } } diff --git a/source/title.cpp b/source/title.cpp index c88b9a6..2bac751 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -371,7 +371,7 @@ void Title::createCheevosTexture() // Escribe la lista de logros en la textura const std::string CHEEVOS_OWNER = "ACHIEVEMENTS"; - const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->size()) + ")"; + const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->getTotalUnlockedAchievements()) + " / " + std::to_string(Cheevos::get()->size()) + ")"; int pos = 2; TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green")); pos += TEXT->getCharacterSize();