From 7bd7ba84e0deecba0f55085225b11d0cfe347d55 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 1 Oct 2025 19:11:58 +0200 Subject: [PATCH] scoreboard.cpp: treballant en transicio de ENTER_NAME a SHOW_NAME --- source/scoreboard.cpp | 61 ++++++++++++++++++++++++++++++++++++++----- source/scoreboard.h | 5 ++++ 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index dcab168..f3c387c 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -51,6 +51,9 @@ Scoreboard::Scoreboard() continue_counter_.at(i) = 0; carousel_prev_index_.at(i) = -1; // Inicializar a -1 para detectar primera inicialización enter_name_ref_.at(i) = nullptr; + previous_mode_.at(i) = Mode::SCORE; + text_slide_offset_.at(i) = 0.0f; + is_sliding_.at(i) = false; } panel_.at(static_cast(Id::LEFT)).mode = Mode::SCORE; @@ -199,12 +202,45 @@ void Scoreboard::updateCarouselAnimation(float deltaTime) { } } +// Actualiza la animación de deslizamiento de texto (transición ENTER_NAME -> SHOW_NAME) +void Scoreboard::updateTextSlideAnimation(float deltaTime) { + const float ROW_SIZE = rect_.h / 4.0f; // Altura de una fila + + for (size_t i = 0; i < static_cast(Id::SIZE); ++i) { + Mode current_mode = panel_.at(i).mode; + + // Detectar transición de ENTER_NAME a SHOW_NAME + if (previous_mode_.at(i) == Mode::ENTER_NAME && current_mode == Mode::SHOW_NAME) { + // Iniciar animación + is_sliding_.at(i) = true; + text_slide_offset_.at(i) = 0.0f; + } + + // Actualizar offset durante animación + if (is_sliding_.at(i)) { + // Incrementar offset basado en tiempo + float slide_speed = ROW_SIZE / TEXT_SLIDE_DURATION; // Píxeles por segundo + text_slide_offset_.at(i) += slide_speed * deltaTime; + + // Terminar animación cuando se complete + if (text_slide_offset_.at(i) >= ROW_SIZE) { + text_slide_offset_.at(i) = ROW_SIZE; + is_sliding_.at(i) = false; + } + } + + // Actualizar modo previo para la próxima iteración + previous_mode_.at(i) = current_mode; + } +} + // Actualiza la lógica del marcador void Scoreboard::update(float deltaTime) { fillBackgroundTexture(); updateTimeCounter(); updateNameColorIndex(); updateCarouselAnimation(deltaTime); + updateTextSlideAnimation(deltaTime); } // Pinta el marcador @@ -385,15 +421,26 @@ void Scoreboard::renderEnterNameMode(size_t panel_index) { } void Scoreboard::renderShowNameMode(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_); + // Calcular offset de animación de deslizamiento + const float ROW_SIZE = rect_.h / 4.0f; + float y_offset = 0.0f; - // NAME - text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_); + if (is_sliding_.at(panel_index)) { + // Durante animación: offset va de -ROW_SIZE (arriba) a 0 (posición final) + y_offset = -ROW_SIZE + text_slide_offset_.at(panel_index); + } - // NOMBRE INTRODUCIDO - text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, enter_name_.at(panel_index), 1, animated_color_); + // NOMBRE DEL JUGADOR (texto0 - entra desde arriba) + text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y + y_offset, name_.at(panel_index), 1, text_color1_); + + // SCORE (texto1 - se desplaza hacia abajo) + text_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y + y_offset, updateScoreText(score_.at(panel_index)), 1, text_color2_); + + // "ENTER NAME" (texto2 - se desplaza hacia abajo) + text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y + y_offset, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_); + + // NOMBRE INTRODUCIDO (texto3 - se desplaza hacia abajo) + text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y + y_offset, enter_name_.at(panel_index), 1, animated_color_); } void Scoreboard::renderGameCompletedMode(size_t panel_index) { diff --git a/source/scoreboard.h b/source/scoreboard.h index fca6d7f..6e53c3a 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -90,6 +90,9 @@ class Scoreboard { std::array(Id::SIZE)> carousel_position_ = {}; // Posición actual del carrusel (índice en character_list_) std::array(Id::SIZE)> carousel_target_ = {}; // Posición objetivo del carrusel std::array(Id::SIZE)> carousel_prev_index_ = {}; // Índice previo para detectar cambios + std::array(Id::SIZE)> previous_mode_ = {}; // Modo anterior para detectar transiciones + std::array(Id::SIZE)> text_slide_offset_ = {}; // Offset Y de animación de deslizamiento de texto + std::array(Id::SIZE)> is_sliding_ = {}; // Indica si el panel está animando deslizamiento std::array(Id::SIZE)> panel_ = {}; // Lista con todos los paneles del marcador Colors::Cycle name_color_cycle_; // Ciclo de colores para destacar el nombre una vez introducido Color animated_color_; // Color actual animado (ciclo automático cada 100ms) @@ -110,6 +113,7 @@ class Scoreboard { // --- Constantes --- static constexpr int CAROUSEL_VISIBLE_LETTERS = 9; + static constexpr float TEXT_SLIDE_DURATION = 0.5f; // Duración de la animación de deslizamiento en segundos // --- Variables de aspecto --- Color text_color1_, text_color2_; // Colores para los marcadores del texto; @@ -128,6 +132,7 @@ class Scoreboard { void updateTimeCounter(); // Actualiza el contador void updateNameColorIndex(); // Actualiza el índice del color animado del nombre void updateCarouselAnimation(float deltaTime); // Actualiza la animación del carrusel + void updateTextSlideAnimation(float deltaTime); // Actualiza la animación de deslizamiento de texto void renderSeparator(); // Dibuja la línea que separa la zona de juego del marcador void renderPanelContent(size_t panel_index); void renderScoreMode(size_t panel_index);