Acabada la primera versión de la lista de logros

This commit is contained in:
2023-09-16 12:29:52 +02:00
parent 16cc725cb3
commit 71be364141
3 changed files with 31 additions and 4 deletions

View File

@@ -246,4 +246,22 @@ void Cheevos::saveToFile()
std::vector<cheevos_t> Cheevos::list()
{
return cheevos;
}
// Devuelve el número total de logros desbloqueados
int Cheevos::unlocked()
{
int count = 0;
for (auto cheevo : cheevos)
{
if (cheevo.completed)
count++;
}
return count;
}
// Devuelve el número total de logros
int Cheevos::count()
{
return cheevos.size();
}

View File

@@ -60,6 +60,12 @@ public:
// Lista los logros
std::vector<cheevos_t> list();
// Devuelve el número total de logros desbloqueados
int unlocked();
// Devuelve el número total de logros
int count();
};
#endif

View File

@@ -59,14 +59,17 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
const vector<cheevos_t> cheevosList = cheevos->list();
const int iconSize = 16; // Altura del icono que representa a cada logro
const int cheevoHeight = iconSize + 2; // EL espacio que ocupa cada logro es igual a la altura del icono mas dos pixeles de separación
const int cheevosTextureWidth = 200;
const int cheevosTextureViewHeight = GAMECANVAS_HEIGHT - 32;
cheevosTexture = new Texture(renderer);
cheevosTexture->createBlank(renderer, GAMECANVAS_WIDTH - 8, cheevoHeight * cheevosList.size(), SDL_TEXTUREACCESS_TARGET);
cheevosTexture->createBlank(renderer, cheevosTextureWidth, cheevoHeight * cheevosList.size(), SDL_TEXTUREACCESS_TARGET);
cheevosTexture->setAsRenderTarget(renderer);
cheevosTexture->setBlendMode(SDL_BLENDMODE_BLEND);
const color_t cheevosBGColor = stringToColor(options->palette, "blue");
SDL_SetRenderDrawColor(renderer, cheevosBGColor.r, cheevosBGColor.g, cheevosBGColor.b, 0xFF);
SDL_RenderClear(renderer);
infoText->writeDX(TXT_CENTER | TXT_COLOR, cheevosTexture->getWidth() / 2, 2, "ACHIEVEMENTS (0 / 12)", 1, stringToColor(options->palette, "bright_white"));
const std::string cheevosListCaption = "ACHIEVEMENTS (" + std::to_string(cheevos->unlocked()) + " / " + std::to_string(cheevos->count()) + ")";
infoText->writeDX(TXT_CENTER | TXT_COLOR, cheevosTexture->getWidth() / 2, 2, cheevosListCaption, 1, stringToColor(options->palette, "bright_white"));
int pos = 9;
const color_t cheevoLockedColor = stringToColor(options->palette, "white");
const color_t cheevoUnlockedColor = stringToColor(options->palette, "bright_white");
@@ -91,8 +94,8 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
delete iconTexture;
// Crea el sprite para el listado de logros
cheevosSprite = new Sprite(4, 4, cheevosTexture->getWidth(), cheevosTexture->getHeight(), cheevosTexture, renderer);
cheevosTextureView = {0, 0, GAMECANVAS_WIDTH - 8, GAMECANVAS_HEIGHT - 8};
cheevosSprite = new Sprite((GAMECANVAS_WIDTH - cheevosTexture->getWidth()) / 2, (GAMECANVAS_HEIGHT - cheevosTextureViewHeight) / 2, cheevosTexture->getWidth(), cheevosTexture->getHeight(), cheevosTexture, renderer);
cheevosTextureView = {0, 0, cheevosTexture->getWidth(), cheevosTextureViewHeight};
cheevosSprite->setSpriteClip(cheevosTextureView);
// Cambia el color del borde