Files
jaildoctors_dilemma/source/game/ui/notifier.hpp

101 lines
3.8 KiB
C++

#pragma once
#include <SDL3/SDL.h>
#include <memory> // Para shared_ptr
#include <string> // Para string, basic_string
#include <vector> // Para vector
class SurfaceSprite; // lines 8-8
class Surface; // lines 10-10
class Text; // lines 9-9
class DeltaTimer; // lines 11-11
class Notifier {
public:
// Constantes
static constexpr Uint32 DURATION_DEFAULT = 2000;
static constexpr Uint32 DURATION_CHEEVO = 4000;
// Justificado para las notificaciones
enum class TextAlign {
LEFT,
CENTER,
};
// Gestión singleton
static void init(const std::string& icon_file, const std::string& text); // Inicialización
static void destroy(); // Destrucción
static auto get() -> Notifier*; // Acceso al singleton
// Métodos principales
void render(); // Renderizado
void update(float delta_time); // Actualización lógica
void show(
std::vector<std::string> texts,
TextAlign text_is = TextAlign::LEFT,
Uint32 display_duration = DURATION_DEFAULT,
int icon = -1,
bool can_be_removed = true,
const std::string& code = std::string()); // Mostrar notificación
// Consultas
auto isActive() -> bool; // Indica si hay notificaciones activas
auto getCodes() -> std::vector<std::string>; // Obtiene códigos de notificaciones
private:
// Tipos anidados
enum class Status {
RISING,
STAY,
VANISHING,
FINISHED,
};
enum class Shape {
ROUNDED,
SQUARED,
};
struct Notification {
std::shared_ptr<Surface> surface{nullptr};
std::shared_ptr<SurfaceSprite> sprite{nullptr};
std::vector<std::string> texts{};
Status state{Status::RISING};
Shape shape{Shape::SQUARED};
SDL_FRect rect{0.0F, 0.0F, 0.0F, 0.0F};
int y{0};
int travel_dist{0};
std::string code{};
bool can_be_removed{true};
int height{0};
Uint32 start_time{0};
Uint32 elapsed_time{0};
Uint32 display_duration{0};
};
// Constantes
static constexpr float ICON_SIZE = 16.0F;
static constexpr float PADDING_OUT = 0.0F;
static constexpr float SLIDE_SPEED = 120.0F; // Pixels per second for slide animations
// [SINGLETON] Objeto notifier
static Notifier* notifier;
// Métodos privados
void clearFinishedNotifications(); // Elimina las notificaciones finalizadas
void clearNotifications(); // Finaliza y elimina todas las notificaciones activas
// Constructor y destructor privados [SINGLETON]
Notifier(const std::string& icon_file, const std::string& text);
~Notifier() = default;
// Variables miembro
std::shared_ptr<Surface> icon_surface_; // Textura para los iconos
std::shared_ptr<Text> text_; // Objeto para dibujar texto
std::unique_ptr<DeltaTimer> delta_timer_; // Timer for frame-independent animations
Uint8 bg_color_{0}; // Color de fondo de las notificaciones
std::vector<Notification> notifications_; // Lista de notificaciones activas
bool stack_{false}; // Indica si las notificaciones se apilan
bool has_icons_{false}; // Indica si el notificador tiene textura para iconos
};