122 lines
3.4 KiB
C++
122 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
|
#include <memory> // for shared_ptr, unique_ptr
|
|
#include <string> // for string, basic_string
|
|
#include <vector> // for vector
|
|
#include "utils.h" // for 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 NotificationPosition
|
|
{
|
|
UPPER_LEFT,
|
|
UPPER_CENTER,
|
|
UPPER_RIGHT,
|
|
MIDDLE_LEFT,
|
|
MIDDLE_RIGHT,
|
|
BOTTOM_LEFT,
|
|
BOTTOM_CENTER,
|
|
BOTTOM_RIGHT,
|
|
};
|
|
|
|
enum class NotificationShape
|
|
{
|
|
ROUNDED,
|
|
SQUARED,
|
|
};
|
|
|
|
struct Notification
|
|
{
|
|
std::shared_ptr<Texture> texture;
|
|
std::shared_ptr<Sprite> sprite;
|
|
std::string text1;
|
|
std::string text2;
|
|
int counter;
|
|
NotificationStatus status;
|
|
NotificationPosition position;
|
|
NotificationShape shape;
|
|
SDL_Rect rect;
|
|
int y;
|
|
int travel_dist;
|
|
std::string code; // Permite asignar un código a la notificación
|
|
};
|
|
|
|
// Objetos y punteros
|
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
|
|
|
std::shared_ptr<Texture> icon_texture_; // Textura para los iconos de las notificaciones
|
|
std::shared_ptr<Text> 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<Notification> 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> 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> 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<std::string> getCodes();
|
|
};
|