Files
vibe3_physics/source/ui/notifier.h
Sergio Valor d93ac04ee3 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>
2025-10-10 07:55:55 +02:00

112 lines
3.3 KiB
C++

#pragma once
#include <SDL3/SDL.h>
#include <string>
#include <queue>
#include <memory>
// Forward declarations
class TextRenderer;
class ThemeManager;
/**
* @brief Sistema de notificaciones estilo iOS/Android
*
* Maneja notificaciones temporales con animaciones suaves:
* - Slide-in desde arriba
* - Fade-out al desaparecer
* - Cola FIFO de mensajes
* - Fondo semitransparente
* - Texto de tamaño fijo independiente de resolución
*/
class Notifier {
public:
enum class NotificationState {
SLIDING_IN, // Animación de entrada desde arriba
VISIBLE, // Visible estático
FADING_OUT, // Animación de salida (fade)
DONE // Completado, listo para eliminar
};
struct Notification {
std::string text;
Uint64 created_time;
Uint64 duration;
NotificationState state;
float alpha; // Opacidad 0.0-1.0
float y_offset; // Offset Y para animación slide (píxeles)
// NOTA: Los colores se obtienen dinámicamente desde ThemeManager en render()
};
Notifier();
~Notifier();
/**
* @brief Inicializa el notifier con un TextRenderer y ThemeManager
* @param renderer SDL renderer para dibujar
* @param text_renderer TextRenderer configurado con tamaño absoluto
* @param theme_manager ThemeManager para obtener colores dinámicos con LERP
* @param window_width Ancho de ventana física
* @param window_height Alto de ventana física
* @return true si inicialización exitosa
*/
bool init(SDL_Renderer* renderer, TextRenderer* text_renderer, ThemeManager* theme_manager, int window_width, int window_height);
/**
* @brief Actualiza las dimensiones de la ventana (llamar en resize)
* @param window_width Nuevo ancho de ventana física
* @param window_height Nuevo alto de ventana física
*/
void updateWindowSize(int window_width, int window_height);
/**
* @brief Muestra una nueva notificación
* @param text Texto a mostrar
* @param duration Duración en milisegundos (0 = usar default)
* @note Los colores se obtienen dinámicamente desde ThemeManager cada frame
*/
void show(const std::string& text, Uint64 duration = 0);
/**
* @brief Actualiza las animaciones de notificaciones
* @param current_time Tiempo actual en ms (SDL_GetTicks())
*/
void update(Uint64 current_time);
/**
* @brief Renderiza la notificación activa
*/
void render();
/**
* @brief Verifica si hay una notificación activa (visible)
* @return true si hay notificación mostrándose
*/
bool isActive() const;
/**
* @brief Limpia todas las notificaciones pendientes
*/
void clear();
private:
SDL_Renderer* renderer_;
TextRenderer* text_renderer_;
ThemeManager* theme_manager_; // Gestor de temas para obtener colores dinámicos con LERP
int window_width_;
int window_height_;
std::queue<Notification> notification_queue_;
std::unique_ptr<Notification> current_notification_;
/**
* @brief Procesa la cola y activa la siguiente notificación si es posible
*/
void processQueue();
/**
* @brief Dibuja el fondo semitransparente de la notificación
*/
void renderBackground(int x, int y, int width, int height, float alpha, SDL_Color bg_color);
};