Les notificacions ara van per milisegons.

posibilitat d'establir el tems de una notificacio (util per a allargar les dels logros)
This commit is contained in:
2025-03-08 11:29:25 +01:00
parent fdb85ac393
commit 195d812d2a
4 changed files with 88 additions and 99 deletions

View File

@@ -9,6 +9,11 @@ class SSprite; // lines 9-9
class Text; // lines 10-10
class Surface; // lines 11-11
// Constantes
constexpr Uint32 DEFAULT_NOTIFICATION_DURATION = 2000;
constexpr Uint32 CHEEVO_NOTIFICATION_DURATION = 4000;
// Justificado para las notificaciones
enum class NotificationText
{
LEFT,
@@ -41,24 +46,39 @@ private:
struct Notification
{
std::shared_ptr<Surface> surface;
std::shared_ptr<SSprite> sprite;
std::vector<std::string> 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
bool can_be_removed;
int height;
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), sprite(nullptr), texts(), counter(0), state(NotificationStatus::RISING),
shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code(""),
can_be_removed(true), height(0) {}
: 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
@@ -66,7 +86,6 @@ private:
// Variables
Uint8 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
@@ -102,7 +121,7 @@ public:
void update();
// Muestra una notificación de texto por pantalla
void show(std::vector<std::string> texts, NotificationText text_is = NotificationText::LEFT, int icon = -1, bool can_be_removed = true, const std::string &code = std::string());
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();