Afegit Cheevos::clearUnobtainableState();

This commit is contained in:
2025-03-01 22:49:03 +01:00
parent aca2be98af
commit cd96be80f9
4 changed files with 26 additions and 13 deletions

View File

@@ -80,7 +80,7 @@ void Cheevos::unlock(int id)
const int index = find(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 // 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; return;
} }
@@ -94,14 +94,14 @@ void Cheevos::unlock(int id)
} }
// Invalida un logro // Invalida un logro
void Cheevos::invalidate(int id) void Cheevos::setUnobtainable(int id)
{ {
const int index = find(id); const int index = find(id);
// Si el índice es válido, se invalida el logro // Si el índice es válido, se invalida el logro
if (index != -1) 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 // Devuelve el número total de logros desbloqueados
int Cheevos::unlocked() int Cheevos::getTotalUnlockedAchievements()
{ {
int count = 0; int count = 0;
for (const auto &cheevo : cheevos_list_) for (const auto &cheevo : cheevos_list_)
@@ -196,3 +196,12 @@ int Cheevos::unlocked()
} }
return count; return count;
} }
// Elimina el estado "no obtenible"
void Cheevos::clearUnobtainableState()
{
for (auto &cheevo : cheevos_list_)
{
cheevo.obtainable = true;
}
}

View File

@@ -11,14 +11,14 @@ struct Achievement
std::string description; // Texto que describe el logro std::string description; // Texto que describe el logro
int icon; // Indice del icono a utilizar en la notificación int icon; // Indice del icono a utilizar en la notificación
bool completed; // Indica si se ha obtenido el logro 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 // Constructor vacío
Achievement() : id(0), icon(0), completed(false), valid(true) {} Achievement() : id(0), icon(0), completed(false), obtainable(true) {}
// Constructor parametrizado // Constructor parametrizado
Achievement(int id, const std::string &caption, const std::string &description, int icon, bool completed = false, bool valid = true) 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), valid(valid) {} : id(id), caption(caption), description(description), icon(icon), completed(completed), obtainable(obtainable) {}
}; };
class Cheevos class Cheevos
@@ -64,7 +64,10 @@ public:
void unlock(int id); void unlock(int id);
// Invalida un logro // Invalida un logro
void invalidate(int id); void setUnobtainable(int id);
// Elimina el estado "no obtenible"
void clearUnobtainableState();
// Habilita o deshabilita los logros // Habilita o deshabilita los logros
void enable(bool value) { enabled_ = value; } void enable(bool value) { enabled_ = value; }
@@ -73,7 +76,7 @@ public:
std::vector<Achievement> list() { return cheevos_list_; } std::vector<Achievement> list() { return cheevos_list_; }
// Devuelve el número total de logros desbloqueados // Devuelve el número total de logros desbloqueados
int unlocked(); int getTotalUnlockedAchievements();
// Devuelve el número total de logros // Devuelve el número total de logros
int size() { return cheevos_list_.size(); } int size() { return cheevos_list_.size(); }

View File

@@ -55,6 +55,7 @@ Game::Game()
changeRoom(current_room_); changeRoom(current_room_);
Cheevos::get()->enable(!options.cheats.enabled()); // Deshabilita los logros si hay trucos activados Cheevos::get()->enable(!options.cheats.enabled()); // Deshabilita los logros si hay trucos activados
Cheevos::get()->clearUnobtainableState();
options.section.section = Section::GAME; options.section.section = Section::GAME;
options.section.subsection = Subsection::NONE; options.section.subsection = Subsection::NONE;
@@ -392,7 +393,7 @@ void Game::killPlayer()
stats_->addDeath(room_->getName()); stats_->addDeath(room_->getName());
// Invalida el logro de pasarse el juego sin morir // Invalida el logro de pasarse el juego sin morir
Cheevos::get()->invalidate(11); Cheevos::get()->setUnobtainable(11);
// Sonido // Sonido
JA_PlaySound(Resource::get()->getSound("death.wav")); JA_PlaySound(Resource::get()->getSound("death.wav"));
@@ -530,7 +531,7 @@ void Game::checkRestoringJail()
const bool haveTheItems = board_->items >= int(total_items_ * 0.9f); const bool haveTheItems = board_->items >= int(total_items_ * 0.9f);
if (!haveTheItems) if (!haveTheItems)
{ {
Cheevos::get()->invalidate(9); Cheevos::get()->setUnobtainable(9);
} }
} }
} }

View File

@@ -371,7 +371,7 @@ void Title::createCheevosTexture()
// Escribe la lista de logros en la textura // Escribe la lista de logros en la textura
const std::string CHEEVOS_OWNER = "ACHIEVEMENTS"; 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; int pos = 2;
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green")); TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green"));
pos += TEXT->getCharacterSize(); pos += TEXT->getCharacterSize();