forked from jaildesigner-jailgames/jaildoctors_dilemma
128 lines
5.7 KiB
C++
128 lines
5.7 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL_rect.h> // Para SDL_Rect
|
|
#include <SDL3/SDL_stdinc.h> // Para Uint32, Uint8
|
|
|
|
#include <memory> // Para shared_ptr
|
|
#include <string> // Para string, basic_string
|
|
#include <vector> // Para vector
|
|
class SSprite; // lines 8-8
|
|
class Surface; // lines 10-10
|
|
class Text; // lines 9-9
|
|
|
|
// Constantes
|
|
constexpr Uint32 DEFAULT_NOTIFICATION_DURATION = 2000;
|
|
constexpr Uint32 CHEEVO_NOTIFICATION_DURATION = 4000;
|
|
|
|
// Justificado para las notificaciones
|
|
enum class NotificationText {
|
|
LEFT,
|
|
CENTER,
|
|
};
|
|
|
|
class Notifier {
|
|
private:
|
|
// Constantes
|
|
static constexpr int ICON_SIZE_ = 16;
|
|
static constexpr int PADDING_OUT_ = 0;
|
|
|
|
// [SINGLETON] Objeto notifier
|
|
static Notifier* notifier_;
|
|
|
|
enum class NotificationStatus {
|
|
RISING,
|
|
STAY,
|
|
VANISHING,
|
|
FINISHED,
|
|
};
|
|
|
|
enum class NotificationShape {
|
|
ROUNDED,
|
|
SQUARED,
|
|
};
|
|
|
|
struct Notification {
|
|
std::shared_ptr<Surface> surface; // Superficie asociada a la notificación
|
|
std::shared_ptr<SSprite> sprite; // Sprite asociado para gráficos o animaciones
|
|
std::vector<std::string> texts; // Lista de textos incluidos en la notificación
|
|
NotificationStatus state; // Estado actual de la notificación (RISING, SHOWING, etc.)
|
|
NotificationShape shape; // Forma de la notificación (ej. SQUARED o ROUNDED)
|
|
SDL_Rect rect; // Dimensiones y posición de la notificación en pantalla
|
|
int y; // Posición actual en el eje Y
|
|
int travel_dist; // Distancia a recorrer (por ejemplo, en animaciones)
|
|
std::string code; // Código identificador único para esta notificación
|
|
bool can_be_removed; // Indica si la notificación puede ser eliminada
|
|
int height; // Altura de la notificación
|
|
Uint32 start_time; // Momento en que se creó la notificación
|
|
Uint32 elapsed_time; // Tiempo transcurrido desde la creación
|
|
Uint32 display_duration; // Duración total para mostrar la notificación
|
|
|
|
// Constructor
|
|
explicit Notification()
|
|
: surface(nullptr), // Inicializar superficie como nula
|
|
sprite(nullptr), // Inicializar sprite como nulo
|
|
texts(), // Inicializar lista de textos vacía
|
|
state(NotificationStatus::RISING), // Estado inicial como "RISING"
|
|
shape(NotificationShape::SQUARED), // Forma inicial como "SQUARED"
|
|
rect{0, 0, 0, 0}, // Rectángulo inicial vacío
|
|
y(0), // Posición Y inicializada a 0
|
|
travel_dist(0), // Distancia inicializada a 0
|
|
code(""), // Código identificador vacío
|
|
can_be_removed(true), // Inicialmente se puede eliminar
|
|
height(0), // Altura inicializada a 0
|
|
start_time(0), // Tiempo de creación inicializado a 0
|
|
elapsed_time(0), // Tiempo transcurrido inicializado a 0
|
|
display_duration(0) // Duración inicializada a 0
|
|
{
|
|
}
|
|
};
|
|
|
|
std::shared_ptr<Surface> icon_surface_; // Textura para los iconos de las notificaciones
|
|
std::shared_ptr<Text> text_; // Objeto para dibujar texto
|
|
|
|
// Variables
|
|
Uint8 bg_color_; // Color de fondo de las notificaciones
|
|
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
|
|
|
|
// 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(const std::string& icon_file, const std::string& text);
|
|
|
|
// Destructor
|
|
~Notifier() = default;
|
|
|
|
public:
|
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
|
static void init(const std::string& icon_file, const std::string& text);
|
|
|
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
|
static void destroy();
|
|
|
|
// [SINGLETON] Con este método obtenemos el objeto 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 show(std::vector<std::string> texts, NotificationText text_is = NotificationText::LEFT, Uint32 display_duration = DEFAULT_NOTIFICATION_DURATION, int icon = -1, bool can_be_removed = true, 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();
|
|
};
|