Fix: Notificaciones con colores dinámicos y transiciones LERP
Problema resuelto: 1. Color del tema saliente: Notificaciones mostraban color del tema ANTIGUO 2. Sin transiciones LERP: Notificaciones no participaban en transiciones suaves Cambios implementados: - Arquitectura cambiada de estática a dinámica - Notifier ahora consulta ThemeManager cada frame en render() - Eliminados colores estáticos de struct Notification - Notifier::init() recibe puntero a ThemeManager - Notifier::show() ya no recibe parámetros de color - Simplificado showNotificationForAction() (-23 líneas) Fix crítico de inicialización: - ThemeManager ahora se inicializa ANTES de updatePhysicalWindowSize() - Previene nullptr en notifier_.init() que causaba que no se mostraran Resultado: - ✅ Notificaciones usan color del tema DESTINO (no origen) - ✅ Transiciones LERP suaves automáticas durante cambios de tema - ✅ Código más limpio y centralizado en ThemeManager - ✅ -50 líneas de código duplicado eliminadas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -205,13 +205,14 @@ bool Engine::initialize(int width, int height, int zoom, bool fullscreen) {
|
||||
|
||||
srand(static_cast<unsigned>(time(nullptr)));
|
||||
|
||||
// Calcular tamaño físico de ventana y tamaño de fuente absoluto
|
||||
updatePhysicalWindowSize();
|
||||
|
||||
// Inicializar ThemeManager
|
||||
// Inicializar ThemeManager PRIMERO (requerido por Notifier)
|
||||
theme_manager_ = std::make_unique<ThemeManager>();
|
||||
theme_manager_->initialize();
|
||||
|
||||
// Calcular tamaño físico de ventana y tamaño de fuente absoluto
|
||||
// NOTA: Debe llamarse DESPUÉS de inicializar ThemeManager porque notifier_.init() lo necesita
|
||||
updatePhysicalWindowSize();
|
||||
|
||||
initBalls(scenario_);
|
||||
}
|
||||
|
||||
@@ -1003,28 +1004,8 @@ void Engine::setText() {
|
||||
std::to_string(num_balls % 1000) + " Pelotas";
|
||||
}
|
||||
|
||||
// Obtener color del tema actual para la notificación
|
||||
int text_r, text_g, text_b;
|
||||
theme_manager_->getCurrentThemeTextColor(text_r, text_g, text_b);
|
||||
SDL_Color notification_color = {
|
||||
static_cast<Uint8>(text_r),
|
||||
static_cast<Uint8>(text_g),
|
||||
static_cast<Uint8>(text_b),
|
||||
255
|
||||
};
|
||||
|
||||
// Obtener color de fondo de la notificación desde el tema
|
||||
int bg_r, bg_g, bg_b;
|
||||
theme_manager_->getCurrentNotificationBackgroundColor(bg_r, bg_g, bg_b);
|
||||
SDL_Color notification_bg_color = {
|
||||
static_cast<Uint8>(bg_r),
|
||||
static_cast<Uint8>(bg_g),
|
||||
static_cast<Uint8>(bg_b),
|
||||
255
|
||||
};
|
||||
|
||||
// Mostrar notificación
|
||||
notifier_.show(notification_text, NOTIFICATION_DURATION, notification_color, notification_bg_color);
|
||||
// Mostrar notificación (colores se obtienen dinámicamente desde ThemeManager)
|
||||
notifier_.show(notification_text, NOTIFICATION_DURATION);
|
||||
|
||||
// Sistema antiguo (mantener temporalmente para compatibilidad)
|
||||
text_ = notification_text;
|
||||
@@ -1037,28 +1018,9 @@ void Engine::showNotificationForAction(const std::string& text) {
|
||||
// IMPORTANTE: Esta función solo se llama desde handlers de teclado (acciones manuales)
|
||||
// NUNCA se llama desde código automático (DEMO/LOGO), por lo tanto siempre mostramos notificación
|
||||
|
||||
// Obtener color del tema actual para el texto
|
||||
int text_r, text_g, text_b;
|
||||
theme_manager_->getCurrentThemeTextColor(text_r, text_g, text_b);
|
||||
SDL_Color notification_color = {
|
||||
static_cast<Uint8>(text_r),
|
||||
static_cast<Uint8>(text_g),
|
||||
static_cast<Uint8>(text_b),
|
||||
255
|
||||
};
|
||||
|
||||
// Obtener color de fondo de la notificación desde el tema
|
||||
int bg_r, bg_g, bg_b;
|
||||
theme_manager_->getCurrentNotificationBackgroundColor(bg_r, bg_g, bg_b);
|
||||
SDL_Color notification_bg_color = {
|
||||
static_cast<Uint8>(bg_r),
|
||||
static_cast<Uint8>(bg_g),
|
||||
static_cast<Uint8>(bg_b),
|
||||
255
|
||||
};
|
||||
|
||||
// Mostrar notificación
|
||||
notifier_.show(text, NOTIFICATION_DURATION, notification_color, notification_bg_color);
|
||||
// Los colores se obtienen dinámicamente cada frame desde ThemeManager en render()
|
||||
// Esto permite transiciones LERP suaves y siempre usar el color del tema actual
|
||||
notifier_.show(text, NOTIFICATION_DURATION);
|
||||
}
|
||||
|
||||
void Engine::pushBallsAwayFromGravity() {
|
||||
@@ -1466,10 +1428,10 @@ void Engine::updatePhysicalWindowSize() {
|
||||
|
||||
text_renderer_notifier_.init(renderer_, TEXT_FONT_PATH, notification_font_size, TEXT_ANTIALIASING);
|
||||
|
||||
// Inicializar/actualizar Notifier con nuevas dimensiones
|
||||
// Inicializar/actualizar Notifier con nuevas dimensiones y ThemeManager
|
||||
// NOTA: init() es seguro de llamar múltiples veces, solo actualiza punteros y dimensiones
|
||||
// Esto asegura que el notifier tenga las referencias correctas tras resize/fullscreen
|
||||
notifier_.init(renderer_, &text_renderer_notifier_, physical_window_width_, physical_window_height_);
|
||||
notifier_.init(renderer_, &text_renderer_notifier_, theme_manager_.get(), physical_window_width_, physical_window_height_);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user