clang-tidy readability-function-cognitive-complexity
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#include "define_buttons.h"
|
#include "define_buttons.h"
|
||||||
|
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
#include "input.h" // Para Input, InputAction
|
#include "input.h" // Para Input, InputAction
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "options.h" // Para OptionsController, Options, options
|
#include "options.h" // Para OptionsController, Options, options
|
||||||
@@ -86,9 +88,6 @@ auto DefineButtons::enable(int index) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si está habilitado
|
|
||||||
auto DefineButtons::isEnabled() const -> bool { return enabled_; }
|
|
||||||
|
|
||||||
// Incrementa el indice de los botones
|
// Incrementa el indice de los botones
|
||||||
void DefineButtons::incIndexButton() {
|
void DefineButtons::incIndexButton() {
|
||||||
if (index_button_ < buttons_.size() - 1) {
|
if (index_button_ < buttons_.size() - 1) {
|
||||||
@@ -100,7 +99,6 @@ void DefineButtons::incIndexButton() {
|
|||||||
|
|
||||||
// Guarda los cambios en las opciones
|
// Guarda los cambios en las opciones
|
||||||
void DefineButtons::saveBindingsToOptions() {
|
void DefineButtons::saveBindingsToOptions() {
|
||||||
// Modifica las opciones para colocar los valores asignados
|
|
||||||
auto &controller = Options::controllers.at(index_controller_);
|
auto &controller = Options::controllers.at(index_controller_);
|
||||||
controller.name = input_->getControllerName(index_controller_);
|
controller.name = input_->getControllerName(index_controller_);
|
||||||
for (size_t j = 0; j < controller.inputs.size(); ++j) {
|
for (size_t j = 0; j < controller.inputs.size(); ++j) {
|
||||||
@@ -110,12 +108,9 @@ void DefineButtons::saveBindingsToOptions() {
|
|||||||
|
|
||||||
// Comprueba que un botón no esté ya asignado
|
// Comprueba que un botón no esté ya asignado
|
||||||
auto DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) -> bool {
|
auto DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) -> bool {
|
||||||
for (const auto &b : buttons_) {
|
return std::ranges::all_of(buttons_, [button](const auto &b) {
|
||||||
if (b.button == button) {
|
return b.button != button;
|
||||||
return false;
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limpia la asignación de botones
|
// Limpia la asignación de botones
|
||||||
@@ -130,18 +125,10 @@ void DefineButtons::clearButtons() {
|
|||||||
|
|
||||||
// Comprueba si ha finalizado
|
// Comprueba si ha finalizado
|
||||||
void DefineButtons::checkEnd() {
|
void DefineButtons::checkEnd() {
|
||||||
// Comprueba si ha finalizado
|
|
||||||
if (finished_) {
|
if (finished_) {
|
||||||
// Asigna los botones definidos al input_
|
bindButtons(); // Asigna los botones definidos al input_
|
||||||
bindButtons();
|
saveBindingsToOptions(); // Guarda los cambios en las opciones
|
||||||
|
input_->resetInputStates(); // Reinicia los estados de las pulsaciones de los botones
|
||||||
// Guarda los cambios en las opciones
|
enabled_ = false; // Deshabilita
|
||||||
saveBindingsToOptions();
|
|
||||||
|
|
||||||
// Reinicia los estados de las pulsaciones de los botones
|
|
||||||
input_->resetInputStates();
|
|
||||||
|
|
||||||
// Deshabilita
|
|
||||||
enabled_ = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,9 +32,9 @@ class DefineButtons {
|
|||||||
void render(); // Dibuja el objeto en pantalla
|
void render(); // Dibuja el objeto en pantalla
|
||||||
void checkEvents(const SDL_Event &event); // Procesa los eventos
|
void checkEvents(const SDL_Event &event); // Procesa los eventos
|
||||||
auto enable(int index_controller) -> bool; // Habilita la redefinición de botones
|
auto enable(int index_controller) -> bool; // Habilita la redefinición de botones
|
||||||
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si está habilitado
|
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }; // Comprueba si está habilitado
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Objetos
|
// Objetos
|
||||||
Input *input_ = nullptr; // Gestión de entrada
|
Input *input_ = nullptr; // Gestión de entrada
|
||||||
std::shared_ptr<Text> text_; // Renderizado de texto
|
std::shared_ptr<Text> text_; // Renderizado de texto
|
||||||
|
|||||||
@@ -15,16 +15,16 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
Notifier *Notifier::instance = nullptr;
|
Notifier* Notifier::instance = nullptr;
|
||||||
|
|
||||||
// Inicializa la instancia única del singleton
|
// Inicializa la instancia única del singleton
|
||||||
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text) { Notifier::instance = new Notifier(icon_file, text); }
|
void Notifier::init(const std::string& icon_file, std::shared_ptr<Text> text) { Notifier::instance = new Notifier(icon_file, text); }
|
||||||
|
|
||||||
// Libera la instancia
|
// Libera la instancia
|
||||||
void Notifier::destroy() { delete Notifier::instance; }
|
void Notifier::destroy() { delete Notifier::instance; }
|
||||||
|
|
||||||
// Obtiene la instancia
|
// Obtiene la instancia
|
||||||
auto Notifier::get() -> Notifier * { return Notifier::instance; }
|
auto Notifier::get() -> Notifier* { return Notifier::instance; }
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text)
|
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text)
|
||||||
@@ -46,71 +46,108 @@ void Notifier::render() {
|
|||||||
// Actualiza el estado de las notificaiones
|
// Actualiza el estado de las notificaiones
|
||||||
void Notifier::update() {
|
void Notifier::update() {
|
||||||
for (int i = 0; i < (int)notifications_.size(); ++i) {
|
for (int i = 0; i < (int)notifications_.size(); ++i) {
|
||||||
// Si la notificación anterior está "saliendo", no hagas nada
|
if (!shouldProcessNotification(i)) {
|
||||||
if (i > 0) {
|
|
||||||
if (notifications_[i - 1].state == NotificationStatus::RISING) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
notifications_[i].counter++;
|
processNotification(i);
|
||||||
|
|
||||||
// Hace sonar la notificación en el primer frame
|
|
||||||
if (notifications_[i].counter == 1) {
|
|
||||||
if (param.notification.sound) {
|
|
||||||
if (notifications_[i].state == NotificationStatus::RISING) {
|
|
||||||
// Reproduce el sonido de la notificación
|
|
||||||
Audio::get()->playSound("notify.wav", Audio::Group::INTERFACE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los estados
|
|
||||||
if (notifications_[i].state == NotificationStatus::RISING) {
|
|
||||||
const float STEP = ((float)notifications_[i].counter / notifications_[i].travel_dist);
|
|
||||||
const int ALPHA = 255 * STEP;
|
|
||||||
|
|
||||||
if (param.notification.pos_v == NotifyPosition::TOP) {
|
|
||||||
notifications_[i].rect.y++;
|
|
||||||
} else {
|
|
||||||
notifications_[i].rect.y--;
|
|
||||||
}
|
|
||||||
notifications_[i].texture->setAlpha(ALPHA);
|
|
||||||
|
|
||||||
if (notifications_[i].rect.y == notifications_[i].y) {
|
|
||||||
notifications_[i].state = NotificationStatus::STAY;
|
|
||||||
notifications_[i].texture->setAlpha(255);
|
|
||||||
notifications_[i].counter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (notifications_[i].state == NotificationStatus::STAY) {
|
|
||||||
if (notifications_[i].counter == wait_time_) {
|
|
||||||
notifications_[i].state = NotificationStatus::VANISHING;
|
|
||||||
notifications_[i].counter = 0;
|
|
||||||
}
|
|
||||||
} else if (notifications_[i].state == NotificationStatus::VANISHING) {
|
|
||||||
const float STEP = (notifications_[i].counter / (float)notifications_[i].travel_dist);
|
|
||||||
const int ALPHA = 255 * (1 - STEP);
|
|
||||||
|
|
||||||
if (param.notification.pos_v == NotifyPosition::TOP) {
|
|
||||||
notifications_[i].rect.y--;
|
|
||||||
} else {
|
|
||||||
notifications_[i].rect.y++;
|
|
||||||
}
|
|
||||||
notifications_[i].texture->setAlpha(ALPHA);
|
|
||||||
|
|
||||||
if (notifications_[i].rect.y == notifications_[i].y - notifications_[i].travel_dist) {
|
|
||||||
notifications_[i].state = NotificationStatus::FINISHED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications_[i].sprite->setPosition(notifications_[i].rect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFinishedNotifications();
|
clearFinishedNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Notifier::shouldProcessNotification(int index) const {
|
||||||
|
// Si la notificación anterior está "saliendo", no hagas nada
|
||||||
|
if (index > 0 && notifications_[index - 1].state == NotificationStatus::RISING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notifier::processNotification(int index) {
|
||||||
|
auto& notification = notifications_[index];
|
||||||
|
notification.counter++;
|
||||||
|
|
||||||
|
playNotificationSoundIfNeeded(notification);
|
||||||
|
updateNotificationState(index);
|
||||||
|
notification.sprite->setPosition(notification.rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notifier::playNotificationSoundIfNeeded(const Notification& notification) {
|
||||||
|
// Hace sonar la notificación en el primer frame
|
||||||
|
if (notification.counter == 1 &&
|
||||||
|
param.notification.sound &&
|
||||||
|
notification.state == NotificationStatus::RISING) {
|
||||||
|
Audio::get()->playSound("notify.wav", Audio::Group::INTERFACE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notifier::updateNotificationState(int index) {
|
||||||
|
auto& notification = notifications_[index];
|
||||||
|
|
||||||
|
switch (notification.state) {
|
||||||
|
case NotificationStatus::RISING:
|
||||||
|
handleRisingState(index);
|
||||||
|
break;
|
||||||
|
case NotificationStatus::STAY:
|
||||||
|
handleStayState(index);
|
||||||
|
break;
|
||||||
|
case NotificationStatus::VANISHING:
|
||||||
|
handleVanishingState(index);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notifier::handleRisingState(int index) {
|
||||||
|
auto& notification = notifications_[index];
|
||||||
|
|
||||||
|
const float step = (float)notification.counter / notification.travel_dist;
|
||||||
|
const int alpha = 255 * step;
|
||||||
|
|
||||||
|
moveNotificationVertically(notification, param.notification.pos_v == NotifyPosition::TOP ? 1 : -1);
|
||||||
|
notification.texture->setAlpha(alpha);
|
||||||
|
|
||||||
|
if (notification.rect.y == notification.y) {
|
||||||
|
transitionToStayState(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notifier::handleStayState(int index) {
|
||||||
|
auto& notification = notifications_[index];
|
||||||
|
|
||||||
|
if (notification.counter == wait_time_) {
|
||||||
|
notification.state = NotificationStatus::VANISHING;
|
||||||
|
notification.counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notifier::handleVanishingState(int index) {
|
||||||
|
auto& notification = notifications_[index];
|
||||||
|
|
||||||
|
const float step = notification.counter / (float)notification.travel_dist;
|
||||||
|
const int alpha = 255 * (1 - step);
|
||||||
|
|
||||||
|
moveNotificationVertically(notification, param.notification.pos_v == NotifyPosition::TOP ? -1 : 1);
|
||||||
|
notification.texture->setAlpha(alpha);
|
||||||
|
|
||||||
|
if (notification.rect.y == notification.y - notification.travel_dist) {
|
||||||
|
notification.state = NotificationStatus::FINISHED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notifier::moveNotificationVertically(Notification& notification, int direction) {
|
||||||
|
notification.rect.y += direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notifier::transitionToStayState(int index) {
|
||||||
|
auto& notification = notifications_[index];
|
||||||
|
notification.state = NotificationStatus::STAY;
|
||||||
|
notification.texture->setAlpha(255);
|
||||||
|
notification.counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Elimina las notificaciones finalizadas
|
// Elimina las notificaciones finalizadas
|
||||||
void Notifier::clearFinishedNotifications() {
|
void Notifier::clearFinishedNotifications() {
|
||||||
for (int i = (int)notifications_.size() - 1; i >= 0; --i) {
|
for (int i = (int)notifications_.size() - 1; i >= 0; --i) {
|
||||||
@@ -120,7 +157,7 @@ void Notifier::clearFinishedNotifications() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notifier::show(std::vector<std::string> texts, int icon, const std::string &code) {
|
void Notifier::show(std::vector<std::string> texts, int icon, const std::string& code) {
|
||||||
// Si no hay texto, acaba
|
// Si no hay texto, acaba
|
||||||
if (texts.empty()) {
|
if (texts.empty()) {
|
||||||
return;
|
return;
|
||||||
@@ -132,12 +169,12 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Elimina las cadenas vacías
|
// Elimina las cadenas vacías
|
||||||
texts.erase(std::remove_if(texts.begin(), texts.end(), [](const std::string &s) { return s.empty(); }),
|
texts.erase(std::remove_if(texts.begin(), texts.end(), [](const std::string& s) { return s.empty(); }),
|
||||||
texts.end());
|
texts.end());
|
||||||
|
|
||||||
// Encuentra la cadena más larga
|
// Encuentra la cadena más larga
|
||||||
std::string longest;
|
std::string longest;
|
||||||
for (const auto &text : texts) {
|
for (const auto& text : texts) {
|
||||||
if (text.length() > longest.length()) {
|
if (text.length() > longest.length()) {
|
||||||
longest = text;
|
longest = text;
|
||||||
}
|
}
|
||||||
@@ -238,7 +275,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
|
|||||||
// Escribe el texto de la notificación
|
// Escribe el texto de la notificación
|
||||||
const Color COLOR{255, 255, 255};
|
const Color COLOR{255, 255, 255};
|
||||||
int iterator = 0;
|
int iterator = 0;
|
||||||
for (const auto &text : texts) {
|
for (const auto& text : texts) {
|
||||||
text_->writeColored(PADDING_IN_H + ICON_SPACE, PADDING_IN_V + iterator * (text_->getCharacterSize() + 1), text, COLOR);
|
text_->writeColored(PADDING_IN_H + ICON_SPACE, PADDING_IN_V + iterator * (text_->getCharacterSize() + 1), text, COLOR);
|
||||||
++iterator;
|
++iterator;
|
||||||
}
|
}
|
||||||
@@ -258,7 +295,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
|
|||||||
|
|
||||||
// Finaliza y elimnina todas las notificaciones activas
|
// Finaliza y elimnina todas las notificaciones activas
|
||||||
void Notifier::clearAllNotifications() {
|
void Notifier::clearAllNotifications() {
|
||||||
for (auto ¬ification : notifications_) {
|
for (auto& notification : notifications_) {
|
||||||
notification.state = NotificationStatus::FINISHED;
|
notification.state = NotificationStatus::FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +305,7 @@ void Notifier::clearAllNotifications() {
|
|||||||
// Obtiene los códigos de las notificaciones
|
// Obtiene los códigos de las notificaciones
|
||||||
auto Notifier::getCodes() -> std::vector<std::string> {
|
auto Notifier::getCodes() -> std::vector<std::string> {
|
||||||
std::vector<std::string> codes;
|
std::vector<std::string> codes;
|
||||||
for (const auto ¬ification : notifications_) {
|
for (const auto& notification : notifications_) {
|
||||||
codes.emplace_back(notification.code);
|
codes.emplace_back(notification.code);
|
||||||
}
|
}
|
||||||
return codes;
|
return codes;
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ class Notifier {
|
|||||||
auto getCodes() -> std::vector<std::string>; // Obtiene los códigos de las notificaciones activas
|
auto getCodes() -> std::vector<std::string>; // Obtiene los códigos de las notificaciones activas
|
||||||
auto checkCode(const std::string &code) -> bool { return stringInVector(getCodes(), code); } // Comprueba si hay alguna notificación con un código concreto
|
auto checkCode(const std::string &code) -> bool { return stringInVector(getCodes(), code); } // Comprueba si hay alguna notificación con un código concreto
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Singleton ---
|
|
||||||
static Notifier *instance;
|
|
||||||
|
|
||||||
// --- Tipos internos ---
|
// --- Tipos internos ---
|
||||||
enum class NotificationStatus {
|
enum class NotificationStatus {
|
||||||
RISING,
|
RISING,
|
||||||
@@ -78,10 +75,22 @@ private:
|
|||||||
bool has_icons_; // Indica si el notificador tiene textura para iconos
|
bool has_icons_; // Indica si el notificador tiene textura para iconos
|
||||||
|
|
||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void clearFinishedNotifications(); // Elimina las notificaciones finalizadas
|
void clearFinishedNotifications(); // Elimina las notificaciones cuyo estado es FINISHED
|
||||||
void clearAllNotifications(); // Finaliza y elimina todas las notificaciones activas
|
void clearAllNotifications(); // Elimina todas las notificaciones activas, sin importar el estado
|
||||||
|
bool shouldProcessNotification(int index) const; // Determina si una notificación debe ser procesada (según su estado y posición)
|
||||||
|
void processNotification(int index); // Procesa una notificación en la posición dada: actualiza su estado y comportamiento visual
|
||||||
|
void playNotificationSoundIfNeeded(const Notification ¬ification); // Reproduce sonido asociado si es necesario (dependiendo del estado o contenido)
|
||||||
|
void updateNotificationState(int index); // Actualiza el estado interno de una notificación (ej. de RISING a STAY)
|
||||||
|
void handleRisingState(int index); // Lógica de animación para el estado RISING (apareciendo)
|
||||||
|
void handleStayState(int index); // Lógica para mantener una notificación visible en el estado STAY
|
||||||
|
void handleVanishingState(int index); // Lógica de animación para el estado VANISHING (desapareciendo)
|
||||||
|
void moveNotificationVertically(Notification ¬ification, int direction); // Mueve verticalmente una notificación en una dirección dada (útil para animación en apilamiento)
|
||||||
|
void transitionToStayState(int index); // Cambia el estado de una notificación de RISING a STAY cuando ha alcanzado su posición final
|
||||||
|
|
||||||
// --- Constructor y destructor ---
|
// --- Constructor y destructor ---
|
||||||
Notifier(std::string icon_file, std::shared_ptr<Text> text); // Constructor privado
|
Notifier(std::string icon_file, std::shared_ptr<Text> text); // Constructor privado
|
||||||
~Notifier() = default; // Destructor privado
|
~Notifier() = default; // Destructor privado
|
||||||
|
|
||||||
|
// --- Singleton ---
|
||||||
|
static Notifier *instance;
|
||||||
};
|
};
|
||||||
@@ -153,19 +153,58 @@ void Scoreboard::fillPanelTextures() {
|
|||||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer_);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
switch (panel_[i].mode) {
|
renderPanelContent(i);
|
||||||
case ScoreboardMode::SCORE: {
|
}
|
||||||
|
|
||||||
|
// Deja el renderizador apuntando donde estaba
|
||||||
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scoreboard::renderPanelContent(size_t panelIndex) {
|
||||||
|
switch (panel_[panelIndex].mode) {
|
||||||
|
case ScoreboardMode::SCORE:
|
||||||
|
renderScoreMode(panelIndex);
|
||||||
|
break;
|
||||||
|
case ScoreboardMode::DEMO:
|
||||||
|
renderDemoMode();
|
||||||
|
break;
|
||||||
|
case ScoreboardMode::WAITING:
|
||||||
|
renderWaitingMode();
|
||||||
|
break;
|
||||||
|
case ScoreboardMode::GAME_OVER:
|
||||||
|
renderGameOverMode();
|
||||||
|
break;
|
||||||
|
case ScoreboardMode::STAGE_INFO:
|
||||||
|
renderStageInfoMode();
|
||||||
|
break;
|
||||||
|
case ScoreboardMode::CONTINUE:
|
||||||
|
renderContinueMode(panelIndex);
|
||||||
|
break;
|
||||||
|
case ScoreboardMode::ENTER_NAME:
|
||||||
|
renderEnterNameMode(panelIndex);
|
||||||
|
break;
|
||||||
|
case ScoreboardMode::SHOW_NAME:
|
||||||
|
renderShowNameMode(panelIndex);
|
||||||
|
break;
|
||||||
|
case ScoreboardMode::GAME_COMPLETED:
|
||||||
|
renderGameCompletedMode(panelIndex);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scoreboard::renderScoreMode(size_t panelIndex) {
|
||||||
// SCORE
|
// SCORE
|
||||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_1_.x, slot4_1_.y, name_[i], 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_1_.x, slot4_1_.y, name_[panelIndex], 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]), 1, text_color2_);
|
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||||
|
|
||||||
// MULT
|
// MULT
|
||||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 3"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 3"), 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_4_.x, slot4_4_.y, "x" + std::to_string(mult_[i]).substr(0, 3), 1, text_color2_);
|
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_4_.x, slot4_4_.y, "x" + std::to_string(mult_[panelIndex]).substr(0, 3), 1, text_color2_);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ScoreboardMode::DEMO: {
|
void Scoreboard::renderDemoMode() {
|
||||||
// DEMO MODE
|
// DEMO MODE
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 6"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 6"), 1, text_color1_);
|
||||||
|
|
||||||
@@ -174,10 +213,9 @@ void Scoreboard::fillPanelTextures() {
|
|||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 8"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 8"), 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 9"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 9"), 1, text_color1_);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ScoreboardMode::WAITING: {
|
void Scoreboard::renderWaitingMode() {
|
||||||
// GAME OVER
|
// GAME OVER
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||||
|
|
||||||
@@ -186,10 +224,9 @@ void Scoreboard::fillPanelTextures() {
|
|||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 8"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 8"), 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 9"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 9"), 1, text_color1_);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ScoreboardMode::GAME_OVER: {
|
void Scoreboard::renderGameOverMode() {
|
||||||
// GAME OVER
|
// GAME OVER
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||||
|
|
||||||
@@ -198,10 +235,9 @@ void Scoreboard::fillPanelTextures() {
|
|||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 12"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 12"), 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 13"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 13"), 1, text_color1_);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ScoreboardMode::STAGE_INFO: {
|
void Scoreboard::renderStageInfoMode() {
|
||||||
// STAGE
|
// STAGE
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, Lang::getText("[SCOREBOARD] 5") + std::to_string(stage_), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, Lang::getText("[SCOREBOARD] 5") + std::to_string(stage_), 1, text_color1_);
|
||||||
|
|
||||||
@@ -215,84 +251,77 @@ void Scoreboard::fillPanelTextures() {
|
|||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 4"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 4"), 1, text_color1_);
|
||||||
const std::string NAME = hi_score_name_.empty() ? "" : hi_score_name_ + " - ";
|
const std::string NAME = hi_score_name_.empty() ? "" : hi_score_name_ + " - ";
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, NAME + updateScoreText(hi_score_), 1, text_color2_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, NAME + updateScoreText(hi_score_), 1, text_color2_);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ScoreboardMode::CONTINUE: {
|
void Scoreboard::renderContinueMode(size_t panelIndex) {
|
||||||
// SCORE
|
// SCORE
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[i], 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panelIndex], 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]), 1, text_color2_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||||
|
|
||||||
// CONTINUE
|
// CONTINUE
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 10"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 10"), 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_[i]), 1, text_color2_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_[panelIndex]), 1, text_color2_);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ScoreboardMode::ENTER_NAME: {
|
void Scoreboard::renderEnterNameMode(size_t panelIndex) {
|
||||||
// SCORE
|
// SCORE
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[i], 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panelIndex], 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]), 1, text_color2_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||||
|
|
||||||
// ENTER NAME
|
// ENTER NAME
|
||||||
{
|
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||||
|
|
||||||
|
renderNameInputField(panelIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scoreboard::renderNameInputField(size_t panelIndex) {
|
||||||
SDL_FRect rect = {enter_name_pos_.x, enter_name_pos_.y, 5.0F, 7.0F};
|
SDL_FRect rect = {enter_name_pos_.x, enter_name_pos_.y, 5.0F, 7.0F};
|
||||||
|
|
||||||
// Recorre todos los slots de letras del nombre
|
// Recorre todos los slots de letras del nombre
|
||||||
for (size_t j = 0; j < NAME_SIZE; ++j) {
|
for (size_t j = 0; j < NAME_SIZE; ++j) {
|
||||||
// Selecciona el color
|
// Selecciona el color
|
||||||
const Color COLOR = j < selector_pos_[i] ? text_color2_ : text_color1_;
|
const Color COLOR = j < selector_pos_[panelIndex] ? text_color2_ : text_color1_;
|
||||||
|
|
||||||
if (j != selector_pos_[i] || time_counter_ % 3 == 0) {
|
if (j != selector_pos_[panelIndex] || time_counter_ % 3 == 0) {
|
||||||
// Dibuja la linea
|
// Dibuja la linea
|
||||||
if (j >= selector_pos_[i]) {
|
if (j >= selector_pos_[panelIndex]) {
|
||||||
SDL_SetRenderDrawColor(renderer_, COLOR.r, COLOR.g, COLOR.b, 255);
|
SDL_SetRenderDrawColor(renderer_, COLOR.r, COLOR.g, COLOR.b, 255);
|
||||||
SDL_RenderLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
SDL_RenderLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja la letra
|
// Dibuja la letra
|
||||||
if (j < record_name_[i].size()) {
|
if (j < record_name_[panelIndex].size()) {
|
||||||
text_scoreboard_->writeColored(rect.x, rect.y, record_name_[i].substr(j, 1), COLOR);
|
text_scoreboard_->writeColored(rect.x, rect.y, record_name_[panelIndex].substr(j, 1), COLOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rect.x += 7;
|
rect.x += 7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
void Scoreboard::renderShowNameMode(size_t panelIndex) {
|
||||||
case ScoreboardMode::SHOW_NAME: {
|
|
||||||
// SCORE
|
// SCORE
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[i], 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panelIndex], 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]), 1, text_color2_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||||
|
|
||||||
// NAME
|
// NAME
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||||
|
|
||||||
/* TEXTO CENTRADO */
|
/* TEXTO CENTRADO */
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_[i], 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_[panelIndex], 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||||
|
|
||||||
/* TEXTO A LA IZQUIERDA */
|
/* TEXTO A LA IZQUIERDA */
|
||||||
// text_scoreboard_->writeColored(enter_name_pos_.x, enter_name_pos_.y, record_name_[i], getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
// text_scoreboard_->writeColored(enter_name_pos_.x, enter_name_pos_.y, record_name_[panelIndex], getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
case ScoreboardMode::GAME_COMPLETED: {
|
void Scoreboard::renderGameCompletedMode(size_t panelIndex) {
|
||||||
// GAME OVER
|
// GAME OVER
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||||
|
|
||||||
// SCORE
|
// SCORE
|
||||||
if (time_counter_ % 10 < 8) {
|
if (time_counter_ % 10 < 8) {
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 14"), 1, text_color1_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 14"), 1, text_color1_);
|
||||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_[i]), 1, text_color2_);
|
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deja el renderizador apuntando donde estaba
|
|
||||||
SDL_SetRenderTarget(renderer_, temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rellena la textura de fondo
|
// Rellena la textura de fondo
|
||||||
|
|||||||
@@ -113,6 +113,17 @@ class Scoreboard {
|
|||||||
void updateTimeCounter(); // Actualiza el contador
|
void updateTimeCounter(); // Actualiza el contador
|
||||||
void renderSeparator(); // Dibuja la línea que separa la zona de juego del marcador
|
void renderSeparator(); // Dibuja la línea que separa la zona de juego del marcador
|
||||||
void iniNameColors(); // Inicializa el vector de colores para el nombre
|
void iniNameColors(); // Inicializa el vector de colores para el nombre
|
||||||
|
void renderPanelContent(size_t panelIndex);
|
||||||
|
void renderScoreMode(size_t panelIndex);
|
||||||
|
void renderDemoMode();
|
||||||
|
void renderWaitingMode();
|
||||||
|
void renderGameOverMode();
|
||||||
|
void renderStageInfoMode();
|
||||||
|
void renderContinueMode(size_t panelIndex);
|
||||||
|
void renderEnterNameMode(size_t panelIndex);
|
||||||
|
void renderNameInputField(size_t panelIndex);
|
||||||
|
void renderShowNameMode(size_t panelIndex);
|
||||||
|
void renderGameCompletedMode(size_t panelIndex);
|
||||||
|
|
||||||
// --- Constructor y destructor privados (singleton) ---
|
// --- Constructor y destructor privados (singleton) ---
|
||||||
Scoreboard();
|
Scoreboard();
|
||||||
|
|||||||
Reference in New Issue
Block a user