Mejorada la apariencia visual de la lista de logros

This commit is contained in:
2023-10-08 22:13:06 +02:00
parent bafde2a778
commit d51d564642
3 changed files with 100 additions and 87 deletions

View File

@@ -48,48 +48,8 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
initMarquee();
showCheevos = false;
// Crea la textura con el listado de logros
const std::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, 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);
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");
color_t cheevoColor;
Texture *iconTexture = new Texture(renderer, asset->get("notify.png"));
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture, renderer);
for (auto cheevo : cheevosList)
{
cheevoColor = cheevo.completed ? cheevoUnlockedColor : cheevoLockedColor;
sp->setPos({2, pos, iconSize, iconSize});
sp->setSpriteClip({iconSize * 2, 0, iconSize, iconSize});
sp->getTexture()->setColor(cheevoColor.r, cheevoColor.g, cheevoColor.b);
sp->render();
pos += 2;
infoText->writeColored(2 + iconSize + 2, pos, cheevo.caption, cheevoColor);
pos += 6;
infoText->writeColored(2 + iconSize + 2, pos, cheevo.description, cheevoColor);
pos += 9;
}
delete sp;
delete iconTexture;
// Crea el sprite para el listado de logros
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);
// Crea y rellena la textura para mostrar los logros
createCheevosTexture();
// Cambia el color del borde
screen->setBorderColor(stringToColor(options->palette, "black"));
@@ -153,7 +113,6 @@ void Title::checkEvents()
break;
case SDL_SCANCODE_2:
showCheevos = true;
break;
@@ -187,7 +146,7 @@ void Title::checkInput()
if (input->checkInput(input_exit, REPEAT_FALSE))
{
if (showCheevos)
showCheevos = false;
hideCheevosList();
else
section->name = SECTION_PROG_QUIT;
}
@@ -225,8 +184,8 @@ void Title::checkInput()
{
if (!showCheevos)
{
section->name = SECTION_PROG_GAME;
section->subsection = 0;
// section->name = SECTION_PROG_GAME;
// section->subsection = 0;
}
}
}
@@ -453,4 +412,71 @@ void Title::fillTexture()
// Devuelve el puntero del renderizador a su sitio
SDL_SetRenderTarget(renderer, nullptr);
}
// Crea y rellena la textura para mostrar los logros
void Title::createCheevosTexture()
{
// Crea la textura con el listado de logros
const std::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 = 110;
const int cheevosTexturePosY = 73;
cheevosTexture = new Texture(renderer);
cheevosTexture->createBlank(renderer, cheevosTextureWidth, cheevoHeight * cheevosList.size(), SDL_TEXTUREACCESS_TARGET);
cheevosTexture->setAsRenderTarget(renderer);
cheevosTexture->setBlendMode(SDL_BLENDMODE_BLEND);
// Rellena la textura con color sólido
const color_t cheevosBGColor = stringToColor(options->palette, "black");
SDL_SetRenderDrawColor(renderer, cheevosBGColor.r, cheevosBGColor.g, cheevosBGColor.b, 0xFF);
SDL_RenderClear(renderer);
// Escribe la lista de logros en la textura
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_green"));
int pos = 11;
const color_t cheevoLockedColor = stringToColor(options->palette, "white");
const color_t cheevoUnlockedColor = stringToColor(options->palette, "bright_green");
color_t cheevoColor;
SDL_SetRenderDrawColor(renderer, cheevoLockedColor.r, cheevoLockedColor.g, cheevoLockedColor.b, 0xFF);
const int lineX1 = (cheevosTextureWidth / 7) * 3;
const int lineX2 = lineX1 + ((cheevosTextureWidth / 7) * 1);
Texture *iconTexture = new Texture(renderer, asset->get("notify.png"));
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture, renderer);
for (auto cheevo : cheevosList)
{
cheevoColor = cheevo.completed ? cheevoUnlockedColor : cheevoLockedColor;
sp->setPos({2, pos, iconSize, iconSize});
sp->setSpriteClip({iconSize * 2, 0, iconSize, iconSize});
sp->getTexture()->setColor(cheevoColor.r, cheevoColor.g, cheevoColor.b);
// sp->render();
pos += 2;
SDL_RenderDrawLine(renderer, lineX1, pos - 3, lineX2, pos - 3);
// infoText->writeColored(2 + iconSize + 2, pos, cheevo.caption, cheevoColor);
infoText->writeDX(TXT_CENTER | TXT_COLOR, cheevosTextureWidth / 2, pos, cheevo.caption, 1, cheevoColor);
pos += 6;
// infoText->writeColored(2 + iconSize + 2, pos, cheevo.description, cheevoColor);
infoText->writeDX(TXT_CENTER | TXT_COLOR, cheevosTextureWidth / 2, pos, cheevo.description, 1, cheevoColor);
pos += 9;
}
delete sp;
delete iconTexture;
// Crea el sprite para el listado de logros
// cheevosSprite = new Sprite((GAMECANVAS_WIDTH - cheevosTexture->getWidth()) / 2, (GAMECANVAS_HEIGHT - cheevosTextureViewHeight) / 2, cheevosTexture->getWidth(), cheevosTexture->getHeight(), cheevosTexture, renderer);
cheevosSprite = new Sprite((GAMECANVAS_WIDTH - cheevosTexture->getWidth()) / 2, cheevosTexturePosY, cheevosTexture->getWidth(), cheevosTexture->getHeight(), cheevosTexture, renderer);
cheevosTextureView = {0, 0, cheevosTexture->getWidth(), cheevosTextureViewHeight};
cheevosSprite->setSpriteClip(cheevosTextureView);
}
// Oculta la lista de logros
void Title::hideCheevosList()
{
showCheevos = false;
cheevosTextureView.y = 0;
cheevosSprite->setSpriteClip(cheevosTextureView);
}