style: deixant guapetes les capçaleres de les classes

This commit is contained in:
2025-11-10 13:53:29 +01:00
parent 5dd463ad5a
commit b70b728b75
23 changed files with 492 additions and 595 deletions

View File

@@ -42,7 +42,6 @@ Notifier::Notifier(const std::string& icon_file, const std::string& text)
text_(Resource::get()->getText(text)),
delta_timer_(std::make_unique<DeltaTimer>()),
bg_color_(Options::notifications.color),
stack_(false),
has_icons_(!icon_file.empty()) {}
// Dibuja las notificaciones por pantalla
@@ -116,7 +115,7 @@ void Notifier::clearFinishedNotifications() {
notifications_.erase(result.begin(), result.end());
}
void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Uint32 display_duration, int icon, bool can_be_removed, const std::string& code) {
void Notifier::show(std::vector<std::string> texts, TextAlign text_is, Uint32 display_duration, int icon, bool can_be_removed, const std::string& code) {
// Si no hay texto, acaba
if (texts.empty()) {
return;
@@ -144,7 +143,7 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
const auto PADDING_IN_H = TEXT_SIZE;
const auto PADDING_IN_V = TEXT_SIZE / 2;
const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0;
text_is = ICON_SPACE > 0 ? NotificationText::LEFT : text_is;
text_is = ICON_SPACE > 0 ? TextAlign::LEFT : text_is;
const float WIDTH = Options::game.width - (PADDING_OUT * 2);
const float HEIGHT = (TEXT_SIZE * texts.size()) + (PADDING_IN_V * 2);
const auto SHAPE = Shape::SQUARED;
@@ -217,10 +216,10 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
int iterator = 0;
for (const auto& text : texts) {
switch (text_is) {
case NotificationText::LEFT:
case TextAlign::LEFT:
text_->writeColored(PADDING_IN_H + ICON_SPACE, PADDING_IN_V + (iterator * (TEXT_SIZE + 1)), text, COLOR);
break;
case NotificationText::CENTER:
case TextAlign::CENTER:
text_->writeDX(TEXT_CENTER | TEXT_COLOR, WIDTH / 2, PADDING_IN_V + (iterator * (TEXT_SIZE + 1)), text, 1, COLOR);
break;
default:

View File

@@ -10,26 +10,40 @@ class Surface; // lines 10-10
class Text; // lines 9-9
class DeltaTimer; // lines 11-11
// 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:
public:
// 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
static constexpr Uint32 DURATION_DEFAULT = 2000;
static constexpr Uint32 DURATION_CHEEVO = 4000;
// [SINGLETON] Objeto notifier
static Notifier* notifier;
// 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,
@@ -43,71 +57,44 @@ class Notifier {
};
struct Notification {
std::shared_ptr<Surface> surface{nullptr}; // Superficie asociada a la notificación
std::shared_ptr<SurfaceSprite> sprite{nullptr}; // Sprite asociado para gráficos o animaciones
std::vector<std::string> texts; // Lista de textos incluidos en la notificación
Status state{Status::RISING}; // Estado actual de la notificación (RISING, SHOWING, etc.)
Shape shape{Shape::SQUARED}; // Forma de la notificación (ej. SQUARED o ROUNDED)
SDL_FRect rect{0, 0, 0, 0}; // Dimensiones y posición de la notificación en pantalla
int y{0}; // Posición actual en el eje Y
int travel_dist{0}; // Distancia a recorrer (por ejemplo, en animaciones)
std::string code; // Código identificador único para esta notificación
bool can_be_removed{true}; // Indica si la notificación puede ser eliminada
int height{0}; // Altura de la notificación
Uint32 start_time{0}; // Momento en que se creó la notificación
Uint32 elapsed_time{0}; // Tiempo transcurrido desde la creación
Uint32 display_duration{0}; // Duración total para mostrar la notificación
// Constructor
explicit Notification() = default;
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};
};
std::shared_ptr<Surface> icon_surface_; // Textura para los iconos de las notificaciones
std::shared_ptr<Text> text_; // Objeto para dibujar texto
std::unique_ptr<DeltaTimer> delta_timer_; // Timer for frame-independent animations
// 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
// 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
// [SINGLETON] Objeto notifier
static Notifier* notifier;
// Elimina las notificaciones finalizadas
void clearFinishedNotifications();
// Métodos privados
void clearFinishedNotifications(); // Elimina las notificaciones finalizadas
void clearNotifications(); // Finaliza y elimina todas las notificaciones activas
// 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
// Constructor y destructor privados [SINGLETON]
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 auto get() -> Notifier*;
// Dibuja las notificaciones por pantalla
void render();
// Actualiza el estado de las notificaiones
void update(float delta_time);
// 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
auto isActive() -> bool;
// Obtiene los códigos de las notificaciones
auto getCodes() -> std::vector<std::string>;
// 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
};