Visualment, el carrusel ja salta al ultim caracter (instantani)
Si no hi ha lletres per a borrar, no fa roidet
This commit is contained in:
@@ -27,6 +27,7 @@ class EnterName {
|
|||||||
[[nodiscard]] auto getSelectedIndex() const -> int { return selected_index_; } // Obtiene el índice del carácter seleccionado
|
[[nodiscard]] auto getSelectedIndex() const -> int { return selected_index_; } // Obtiene el índice del carácter seleccionado
|
||||||
[[nodiscard]] auto getCharacterList() const -> const std::string& { return character_list_; } // Obtiene la lista completa de caracteres
|
[[nodiscard]] auto getCharacterList() const -> const std::string& { return character_list_; } // Obtiene la lista completa de caracteres
|
||||||
[[nodiscard]] auto nameIsFull() const -> bool { return name_.size() == MAX_NAME_SIZE; } // Informa de si el nombre ha alcanzado su limite
|
[[nodiscard]] auto nameIsFull() const -> bool { return name_.size() == MAX_NAME_SIZE; } // Informa de si el nombre ha alcanzado su limite
|
||||||
|
[[nodiscard]] auto nameIsEmpty() const -> bool { return name_.empty(); } // Informa de si el nombre está vacío
|
||||||
[[nodiscard]] auto endCharSelected() const -> bool { return selected_index_ == character_list_.size() - 1; } // Informa de si está seleccionado el caracter de terminar
|
[[nodiscard]] auto endCharSelected() const -> bool { return selected_index_ == character_list_.size() - 1; } // Informa de si está seleccionado el caracter de terminar
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ void Player::setInputPlaying(Input::Action action) {
|
|||||||
// Procesa inputs para cuando está introduciendo el nombre
|
// Procesa inputs para cuando está introduciendo el nombre
|
||||||
void Player::setInputEnteringName(Input::Action action) {
|
void Player::setInputEnteringName(Input::Action action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case Input::Action::FIRE_LEFT:
|
case Input::Action::FIRE_LEFT: // Añade una letra
|
||||||
if (isShowingName()) {
|
if (isShowingName()) {
|
||||||
passShowingName();
|
passShowingName();
|
||||||
} else {
|
} else {
|
||||||
@@ -139,12 +139,14 @@ void Player::setInputEnteringName(Input::Action action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Input::Action::FIRE_CENTER:
|
case Input::Action::FIRE_CENTER: // Borra una letra
|
||||||
if (isShowingName()) {
|
if (isShowingName()) {
|
||||||
passShowingName();
|
passShowingName();
|
||||||
} else {
|
} else {
|
||||||
enter_name_->removeLastCharacter();
|
if (!enter_name_->nameIsEmpty()) {
|
||||||
playSound("service_menu_back.wav");
|
enter_name_->removeLastCharacter();
|
||||||
|
playSound("service_menu_back.wav");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Input::Action::RIGHT:
|
case Input::Action::RIGHT:
|
||||||
|
|||||||
@@ -95,67 +95,63 @@ Scoreboard::~Scoreboard() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configura la animación del carrusel
|
|
||||||
// Configura la animación del carrusel
|
// Configura la animación del carrusel
|
||||||
void Scoreboard::setCarouselAnimation(Id id, int selected_index, EnterName* enter_name_ptr) {
|
void Scoreboard::setCarouselAnimation(Id id, int selected_index, EnterName* enter_name_ptr) {
|
||||||
auto idx = static_cast<size_t>(id);
|
auto idx = static_cast<size_t>(id);
|
||||||
|
|
||||||
// Guardar referencia a EnterName
|
// Guardar referencia al objeto EnterName
|
||||||
enter_name_ref_.at(idx) = enter_name_ptr;
|
enter_name_ref_.at(idx) = enter_name_ptr;
|
||||||
|
|
||||||
if ((enter_name_ptr == nullptr) || selected_index < 0) {
|
if ((enter_name_ptr == nullptr) || selected_index < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Primera inicialización: posicionar directamente sin animar
|
// ===== Primera inicialización =====
|
||||||
if (carousel_prev_index_.at(idx) == -1) {
|
if (carousel_prev_index_.at(idx) == -1) {
|
||||||
carousel_position_.at(idx) = static_cast<float>(selected_index);
|
carousel_position_.at(idx) = static_cast<float>(selected_index);
|
||||||
carousel_target_.at(idx) = static_cast<float>(selected_index);
|
carousel_target_.at(idx) = static_cast<float>(selected_index);
|
||||||
carousel_prev_index_.at(idx) = selected_index;
|
carousel_prev_index_.at(idx) = selected_index;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int prev_index = carousel_prev_index_.at(idx);
|
int prev_index = carousel_prev_index_.at(idx);
|
||||||
|
|
||||||
// Si el índice seleccionado no cambia, no hay nada que hacer
|
|
||||||
if (selected_index == prev_index) {
|
if (selected_index == prev_index) {
|
||||||
|
return; // No hay cambio
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== Bloqueo: si aún está animando, ignorar nueva orden =====
|
||||||
|
if (std::abs(carousel_position_.at(idx) - carousel_target_.at(idx)) > 0.01f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🚫 BLOQUEO: si todavía hay una animación en curso, ignoramos el nuevo movimiento
|
// ===== Calcular el salto =====
|
||||||
if (std::abs(carousel_position_.at(idx) - carousel_target_.at(idx)) > 0.01f) {
|
int delta = selected_index - prev_index;
|
||||||
return; // Aún animando: no aceptar nuevo target hasta terminar
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Animación completada → procesar el nuevo movimiento ----
|
|
||||||
int direction = selected_index - prev_index;
|
|
||||||
|
|
||||||
// Obtener tamaño de la lista para manejar wrap-around
|
|
||||||
const int LIST_SIZE = static_cast<int>(enter_name_ptr->getCharacterList().size());
|
const int LIST_SIZE = static_cast<int>(enter_name_ptr->getCharacterList().size());
|
||||||
|
|
||||||
// Manejar wrap-around circular
|
// Ajustar para wrap-around circular (camino más corto)
|
||||||
if (direction > LIST_SIZE / 2) {
|
if (delta > LIST_SIZE / 2) {
|
||||||
direction = -(LIST_SIZE - direction); // Wrap backward (ej: Z → A)
|
delta -= LIST_SIZE;
|
||||||
} else if (direction < -LIST_SIZE / 2) {
|
} else if (delta < -LIST_SIZE / 2) {
|
||||||
direction = LIST_SIZE + direction; // Wrap forward (ej: A → Z)
|
delta += LIST_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalizar dirección a -1 o +1
|
// ===== Diferenciar salto corto o largo =====
|
||||||
direction = (direction > 0) ? 1 : ((direction < 0) ? -1 : 0);
|
if (std::abs(delta) > 2) {
|
||||||
|
// Salto grande → ir directo sin animación
|
||||||
if (direction != 0) {
|
carousel_position_.at(idx) = static_cast<float>(selected_index);
|
||||||
// Asegurar que partimos de una posición alineada
|
carousel_target_.at(idx) = static_cast<float>(selected_index);
|
||||||
carousel_position_.at(idx) = std::round(carousel_position_.at(idx));
|
} else {
|
||||||
|
// Salto corto → animación suave normal
|
||||||
// Actualizar el nuevo target relativo
|
carousel_position_.at(idx) = std::round(carousel_position_.at(idx));
|
||||||
carousel_target_.at(idx) = carousel_position_.at(idx) + static_cast<float>(direction);
|
carousel_target_.at(idx) = carousel_position_.at(idx) + static_cast<float>(delta);
|
||||||
|
|
||||||
// Guardar el nuevo índice seleccionado
|
|
||||||
carousel_prev_index_.at(idx) = selected_index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualizar índice actual
|
||||||
|
carousel_prev_index_.at(idx) = selected_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Establece el modo del panel y gestiona transiciones
|
// Establece el modo del panel y gestiona transiciones
|
||||||
void Scoreboard::setMode(Id id, Mode mode) {
|
void Scoreboard::setMode(Id id, Mode mode) {
|
||||||
auto idx = static_cast<size_t>(id);
|
auto idx = static_cast<size_t>(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user