Treballant en la nova tabla de records: ja pinta amb sprites
This commit is contained in:
@@ -51,6 +51,9 @@ HiScoreTable::HiScoreTable()
|
||||
fade_->setMode(fade_mode_);
|
||||
fade_->activate();
|
||||
|
||||
// Crea los sprites con los textos
|
||||
createSprites();
|
||||
|
||||
// Crea el contenido de la textura con la lista de puntuaciones
|
||||
fillTexture();
|
||||
}
|
||||
@@ -108,13 +111,6 @@ void HiScoreTable::update()
|
||||
// Crea el contenido de la textura con la lista de puntuaciones
|
||||
void HiScoreTable::fillTexture()
|
||||
{
|
||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
|
||||
constexpr auto max_names = 10;
|
||||
constexpr auto space_between_header = 32;
|
||||
const auto space_between_lines = text_->getCharacterSize() * 2.0f;
|
||||
const auto size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize();
|
||||
const auto first_line = (param.game.height - size) / 2;
|
||||
|
||||
// Pinta en el backbuffer el texto y los sprites
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
@@ -122,22 +118,12 @@ void HiScoreTable::fillTexture()
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
// Escribe el texto: Mejores puntuaciones
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, first_line, lang::getText(42), 1, orange_color, 1, shdw_txt_color);
|
||||
header_->render();
|
||||
|
||||
// Escribe los nombres de la tabla de puntuaciones
|
||||
for (int i = 0; i < max_names; ++i)
|
||||
for (auto const &entry : entry_names_)
|
||||
{
|
||||
const auto name_lenght = options.game.hi_score_table[i].name.length();
|
||||
const auto score = format(options.game.hi_score_table[i].score);
|
||||
const auto score_lenght = score.size();
|
||||
const auto num_dots = 25 - name_lenght - score_lenght;
|
||||
std::string dots;
|
||||
for (int j = 0; j < (int)num_dots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const auto line = options.game.hi_score_table[i].name + dots + score;
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, (i * space_between_lines) + first_line + space_between_header, line, 1, orange_color, 1, shdw_txt_color);
|
||||
entry->render();
|
||||
}
|
||||
|
||||
// Cambia el destino de renderizado
|
||||
@@ -274,4 +260,37 @@ std::string HiScoreTable::format(int number)
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Crea los sprites con los textos
|
||||
void HiScoreTable::createSprites()
|
||||
{
|
||||
// Hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
|
||||
constexpr int max_names = 10;
|
||||
constexpr int space_between_header = 32;
|
||||
const int space_between_lines = text_->getCharacterSize() * 2;
|
||||
const int size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize();
|
||||
const int first_line = (param.game.height - size) / 2;
|
||||
|
||||
// Crea el sprite para el texto de cabecera
|
||||
header_ = std::make_unique<Sprite>(text_->writeDXToTexture(TEXT_COLOR | TEXT_SHADOW, lang::getText(42), 1, orange_color, 1, shdw_txt_color));
|
||||
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line);
|
||||
|
||||
// Crea los sprites para las entradas en la tabla de puntuaciones
|
||||
for (int i = 0; i < max_names; ++i)
|
||||
{
|
||||
const auto name_lenght = options.game.hi_score_table.at(i).name.length();
|
||||
const auto score = format(options.game.hi_score_table.at(i).score);
|
||||
const auto score_lenght = score.size();
|
||||
const auto num_dots = 25 - name_lenght - score_lenght;
|
||||
std::string dots;
|
||||
for (int j = 0; j < (int)num_dots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const auto line = options.game.hi_score_table.at(i).name + dots + score;
|
||||
|
||||
entry_names_.emplace_back(std::make_shared<PathSprite>(text_->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color)));
|
||||
entry_names_.back()->setPosition(param.game.game_area.center_x - (entry_names_.back()->getWidth() / 2), (i * space_between_lines) + first_line + space_between_header);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user