#pragma once #include // para SDL_Rect #include // para SDL_Renderer #include // para shared_ptr, unique_ptr #include // para string, basic_string #include // para vector #include "utils.h" // para Color class Sprite; class Text; class Texture; struct JA_Sound_t; // lines 12-12 class Notifier { private: // [SINGLETON] Objeto notifier privado para Don Melitón static Notifier *notifier_; enum class NotificationStatus { RISING, STAY, VANISHING, FINISHED, }; enum class NotificationShape { ROUNDED, SQUARED, }; struct Notification { std::shared_ptr texture; std::shared_ptr sprite; std::string text1; std::string text2; int counter; NotificationStatus status; NotificationShape shape; SDL_Rect rect; int y; int travel_dist; std::string code; // Permite asignar un código a la notificación // Constructor explicit Notification() : texture(nullptr), sprite(nullptr), text1(""), text2(""), counter(0), status(NotificationStatus::RISING), shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code("") {} }; // Objetos y punteros SDL_Renderer *renderer_; // El renderizador de la ventana std::shared_ptr icon_texture_; // Textura para los iconos de las notificaciones std::shared_ptr text_; // Objeto para dibujar texto // Variables Color bg_color_; // Color de fondo de las notificaciones int wait_time_; // Tiempo que se ve la notificación std::vector notifications_; // La lista de notificaciones activas bool stack_; // Indica si las notificaciones se apilan bool has_icons_; // Indica si el notificador tiene textura para iconos JA_Sound_t *sound_; // Sonido a reproducir cuando suena la notificación // Elimina las notificaciones finalizadas void clearFinishedNotifications(); // Finaliza y elimnina todas las notificaciones activas void clearNotifications(); // [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera // Constructor Notifier(std::string icon_file, std::shared_ptr text, const std::string &sound_file); // Destructor ~Notifier(); public: // [SINGLETON] Crearemos el objeto notifier con esta función estática static void init(const std::string &icon_file, std::shared_ptr text, const std::string &sound_file); // [SINGLETON] Destruiremos el objeto notifier con esta función estática static void destroy(); // [SINGLETON] Con este método obtenemos el objeto notifier y podemos trabajar con él static Notifier *get(); // Dibuja las notificaciones por pantalla void render(); // Actualiza el estado de las notificaiones void update(); /** * @brief Muestra una notificación de texto por pantalla. * * @param text1 Primer texto opcional para mostrar (valor predeterminado: cadena vacía). * @param text2 Segundo texto opcional para mostrar (valor predeterminado: cadena vacía). * @param icon Icono opcional para mostrar (valor predeterminado: -1). * @param code Permite asignar un código a la notificación (valor predeterminado: cadena vacía). */ void showText(std::string text1 = std::string(), std::string text2 = std::string(), int icon = -1, const std::string &code = std::string()); // Indica si hay notificaciones activas bool isActive(); // Obtiene los códigos de las notificaciones std::vector getCodes(); };