treballan en el carrusel per a posar el nom
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// .at(SINGLETON) Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Scoreboard *Scoreboard::instance = nullptr;
|
||||
Scoreboard* Scoreboard::instance = nullptr;
|
||||
|
||||
// .at(SINGLETON) Crearemos el objeto score_board con esta función estática
|
||||
void Scoreboard::init() {
|
||||
@@ -31,7 +31,7 @@ void Scoreboard::destroy() {
|
||||
}
|
||||
|
||||
// .at(SINGLETON) Con este método obtenemos el objeto score_board y podemos trabajar con él
|
||||
auto Scoreboard::get() -> Scoreboard * {
|
||||
auto Scoreboard::get() -> Scoreboard* {
|
||||
return Scoreboard::instance;
|
||||
}
|
||||
|
||||
@@ -40,12 +40,11 @@ Scoreboard::Scoreboard()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
game_power_meter_texture_(Resource::get()->getTexture("game_power_meter.png")),
|
||||
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
||||
text_(Resource::get()->getText("8bithud")),
|
||||
enter_name_text_(Resource::get()->getText("smb2")) {
|
||||
text_(Resource::get()->getText("8bithud")) {
|
||||
// Inicializa variables
|
||||
for (size_t i = 0; i < static_cast<size_t>(Id::SIZE); ++i) {
|
||||
name_.at(i).clear();
|
||||
record_name_.at(i).clear();
|
||||
enter_name_.at(i).clear();
|
||||
selector_pos_.at(i) = 0;
|
||||
score_.at(i) = 0;
|
||||
mult_.at(i) = 0;
|
||||
@@ -74,8 +73,9 @@ Scoreboard::Scoreboard()
|
||||
// Rellena la textura de fondo
|
||||
fillBackgroundTexture();
|
||||
|
||||
// Inicializa el vector de colores para el nombre
|
||||
iniNameColors();
|
||||
// Inicializa el ciclo de colores para el nombre
|
||||
name_color_cycle_ = Colors::generateMirroredCycle(color_.INVERSE(), ColorCycleStyle::VIBRANT);
|
||||
animated_color_ = name_color_cycle_.at(0);
|
||||
}
|
||||
|
||||
Scoreboard::~Scoreboard() {
|
||||
@@ -83,7 +83,7 @@ Scoreboard::~Scoreboard() {
|
||||
SDL_DestroyTexture(background_);
|
||||
}
|
||||
|
||||
for (auto *texture : panel_texture_) {
|
||||
for (auto* texture : panel_texture_) {
|
||||
if (texture != nullptr) {
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
@@ -107,11 +107,24 @@ void Scoreboard::updateTimeCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el índice del color animado del nombre
|
||||
void Scoreboard::updateNameColorIndex() {
|
||||
constexpr Uint64 COLOR_UPDATE_INTERVAL = 100; // 100ms entre cambios de color
|
||||
|
||||
if (SDL_GetTicks() - name_color_last_update_ >= COLOR_UPDATE_INTERVAL) {
|
||||
++name_color_index_;
|
||||
name_color_last_update_ = SDL_GetTicks();
|
||||
}
|
||||
|
||||
// Precalcular el color actual del ciclo
|
||||
animated_color_ = name_color_cycle_.at(name_color_index_ % name_color_cycle_.size());
|
||||
}
|
||||
|
||||
// Actualiza la lógica del marcador
|
||||
void Scoreboard::update() {
|
||||
fillBackgroundTexture();
|
||||
updateTimeCounter();
|
||||
++loop_counter_;
|
||||
updateNameColorIndex();
|
||||
}
|
||||
|
||||
// Pinta el marcador
|
||||
@@ -129,7 +142,7 @@ void Scoreboard::setColor(Color color) {
|
||||
// Aplica los colores
|
||||
power_meter_sprite_->getTexture()->setColor(text_color2_);
|
||||
fillBackgroundTexture();
|
||||
iniNameColors();
|
||||
name_color_cycle_ = Colors::generateMirroredCycle(color_.INVERSE(), ColorCycleStyle::VIBRANT);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
@@ -145,7 +158,7 @@ void Scoreboard::setPos(SDL_FRect rect) {
|
||||
// Rellena los diferentes paneles del marcador
|
||||
void Scoreboard::fillPanelTextures() {
|
||||
// Guarda a donde apunta actualmente el renderizador
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
auto* temp = SDL_GetRenderTarget(renderer_);
|
||||
|
||||
// Genera el contenido de cada panel_
|
||||
for (size_t i = 0; i < static_cast<int>(Id::SIZE); ++i) {
|
||||
@@ -267,6 +280,7 @@ void Scoreboard::renderContinueMode(size_t panel_index) {
|
||||
}
|
||||
|
||||
void Scoreboard::renderEnterNameMode(size_t panel_index) {
|
||||
/*
|
||||
// SCORE
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
@@ -275,29 +289,19 @@ void Scoreboard::renderEnterNameMode(size_t panel_index) {
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
renderNameInputField(panel_index);
|
||||
}
|
||||
*/
|
||||
|
||||
void Scoreboard::renderNameInputField(size_t panel_index) {
|
||||
SDL_FRect rect = {
|
||||
.x = enter_name_pos_.x,
|
||||
.y = enter_name_pos_.y,
|
||||
.w = static_cast<float>(enter_name_text_->getCharacterSize() - 2),
|
||||
.h = static_cast<float>(enter_name_text_->getCharacterSize())};
|
||||
// SCORE
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// Recorre todos los slots de letras del nombre
|
||||
for (size_t j = 0; j < NAME_SIZE; ++j) {
|
||||
// Dibuja la linea. Si coincide con el selector solo se dibuja 2 de cada 4 veces
|
||||
if (j != selector_pos_.at(panel_index) || time_counter_ % 4 >= 2) {
|
||||
SDL_SetRenderDrawColor(renderer_, text_color1_.r, text_color1_.g, text_color1_.b, 255);
|
||||
SDL_RenderLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
||||
}
|
||||
// ENTER NAME
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
// Dibuja la letra
|
||||
if (j < record_name_.at(panel_index).size()) {
|
||||
enter_name_text_->writeColored(rect.x, rect.y, record_name_.at(panel_index).substr(j, 1), text_color2_);
|
||||
}
|
||||
rect.x += enter_name_text_->getCharacterSize();
|
||||
}
|
||||
// NAME
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, enter_name_.at(panel_index), 1, text_color2_);
|
||||
|
||||
// CARRUSEL
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, carousel_.at(panel_index), 1, animated_color_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderShowNameMode(size_t panel_index) {
|
||||
@@ -309,7 +313,7 @@ void Scoreboard::renderShowNameMode(size_t panel_index) {
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
// NOMBRE INTRODUCIDO
|
||||
enter_name_text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, record_name_.at(panel_index), 1, Colors::getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, enter_name_.at(panel_index), 1, animated_color_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderGameCompletedMode(size_t panel_index) {
|
||||
@@ -329,7 +333,7 @@ void Scoreboard::fillBackgroundTexture() {
|
||||
fillPanelTextures();
|
||||
|
||||
// Cambia el destino del renderizador
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_Texture* temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, background_);
|
||||
|
||||
// Dibuja el fondo del marcador
|
||||
@@ -379,7 +383,7 @@ void Scoreboard::recalculateAnchors() {
|
||||
slot4_4_ = {.x = COL, .y = ROW4};
|
||||
|
||||
// Primer cuadrado para poner el nombre de record
|
||||
const int ENTER_NAME_LENGTH = enter_name_text_->length(std::string(NAME_SIZE, 'A'));
|
||||
const int ENTER_NAME_LENGTH = text_->length(std::string(EnterName::MAX_NAME_SIZE, 'A'));
|
||||
enter_name_pos_.x = COL - (ENTER_NAME_LENGTH / 2);
|
||||
enter_name_pos_.y = ROW4;
|
||||
|
||||
@@ -405,7 +409,7 @@ void Scoreboard::createBackgroundTexture() {
|
||||
// Crea las texturas de los paneles
|
||||
void Scoreboard::createPanelTextures() {
|
||||
// Elimina las texturas en caso de existir
|
||||
for (auto *texture : panel_texture_) {
|
||||
for (auto* texture : panel_texture_) {
|
||||
if (texture != nullptr) {
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
@@ -413,8 +417,8 @@ void Scoreboard::createPanelTextures() {
|
||||
panel_texture_.clear();
|
||||
|
||||
// Crea las texturas para cada panel_
|
||||
for (auto &i : panel_) {
|
||||
SDL_Texture *tex = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, i.pos.w, i.pos.h);
|
||||
for (auto& i : panel_) {
|
||||
SDL_Texture* tex = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, i.pos.w, i.pos.h);
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
panel_texture_.push_back(tex);
|
||||
}
|
||||
@@ -426,15 +430,4 @@ void Scoreboard::renderSeparator() {
|
||||
auto color = param.scoreboard.separator_autocolor ? color_.DARKEN() : param.scoreboard.separator_color;
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 255);
|
||||
SDL_RenderLine(renderer_, 0, 0, rect_.w, 0);
|
||||
}
|
||||
|
||||
// Inicializa el vector de colores para el nombre
|
||||
void Scoreboard::iniNameColors() {
|
||||
Color color = color_.INVERSE();
|
||||
|
||||
name_colors_.clear();
|
||||
name_colors_.emplace_back(color.LIGHTEN(50));
|
||||
name_colors_.emplace_back(color.LIGHTEN(25));
|
||||
name_colors_.emplace_back(color);
|
||||
name_colors_.emplace_back(color.DARKEN(25));
|
||||
}
|
||||
Reference in New Issue
Block a user