#pragma once #include // Para SDL_Rect #include // Para SDL_Renderer #include // Para shared_ptr #include // Para string, basic_string #include // Para vector #include "utils.h" // Para Color class Sprite; // lines 9-9 class Text; // lines 10-10 class Texture; // lines 11-11 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::vector texts; int counter; NotificationStatus state; 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), texts(), counter(0), state(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 // 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); // Destructor ~Notifier() = default; public: // [SINGLETON] Crearemos el objeto notifier con esta función estática static void init(const std::string &icon_file, std::shared_ptr text); // [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(); // Muestra una notificación de texto por pantalla void showText(std::vector texts, 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(); };