This commit is contained in:
2025-10-27 11:53:12 +01:00
parent 231dcd4b3b
commit 5d8811026d
69 changed files with 899 additions and 888 deletions

View File

@@ -17,21 +17,21 @@
#include "utils/utils.hpp" // Para PaletteColor
// [SINGLETON]
Notifier* Notifier::notifier_ = nullptr;
Notifier* Notifier::notifier = nullptr;
// [SINGLETON] Crearemos el objeto con esta función estática
void Notifier::init(const std::string& icon_file, const std::string& text) {
Notifier::notifier_ = new Notifier(icon_file, text);
Notifier::notifier = new Notifier(icon_file, text);
}
// [SINGLETON] Destruiremos el objeto con esta función estática
void Notifier::destroy() {
delete Notifier::notifier_;
delete Notifier::notifier;
}
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
Notifier* Notifier::get() {
return Notifier::notifier_;
return Notifier::notifier;
}
// Constructor
@@ -138,9 +138,9 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
const int text_size = 6;
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;
const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0;
text_is = ICON_SPACE > 0 ? NotificationText::LEFT : text_is;
const float WIDTH = Options::game.width - (PADDING_OUT_ * 2);
const float WIDTH = Options::game.width - (PADDING_OUT * 2);
const float HEIGHT = (text_size * texts.size()) + (PADDING_IN_V * 2);
const auto SHAPE = NotificationShape::SQUARED;
@@ -148,7 +148,7 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
float desp_h = 0;
switch (Options::notifications.getHorizontalPosition()) {
case Options::NotificationPosition::LEFT:
desp_h = PADDING_OUT_;
desp_h = PADDING_OUT;
break;
case Options::NotificationPosition::CENTER:
@@ -156,7 +156,7 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
break;
case Options::NotificationPosition::RIGHT:
desp_h = Options::game.width - WIDTH - PADDING_OUT_;
desp_h = Options::game.width - WIDTH - PADDING_OUT;
break;
default:
@@ -165,10 +165,10 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
}
// Posición vertical
const int DESP_V = (Options::notifications.getVerticalPosition() == Options::NotificationPosition::TOP) ? PADDING_OUT_ : Options::game.height - HEIGHT - PADDING_OUT_;
const int DESP_V = (Options::notifications.getVerticalPosition() == Options::NotificationPosition::TOP) ? PADDING_OUT : Options::game.height - HEIGHT - PADDING_OUT;
// Offset
const auto TRAVEL_DIST = HEIGHT + PADDING_OUT_;
const auto TRAVEL_DIST = HEIGHT + PADDING_OUT;
const int TRAVEL_MOD = (Options::notifications.getVerticalPosition() == Options::NotificationPosition::TOP) ? 1 : -1;
const int OFFSET = !notifications_.empty() ? notifications_.back().y + TRAVEL_MOD * notifications_.back().travel_dist : DESP_V;
@@ -217,9 +217,9 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
// Dibuja el icono de la notificación
if (has_icons_ && icon >= 0 && texts.size() >= 2) {
auto sp = std::make_unique<SurfaceSprite>(icon_surface_, (SDL_FRect){0, 0, ICON_SIZE_, ICON_SIZE_});
sp->setPosition({PADDING_IN_H, PADDING_IN_V, ICON_SIZE_, ICON_SIZE_});
sp->setClip((SDL_FRect){ICON_SIZE_ * (icon % 10), ICON_SIZE_ * (icon / 10), ICON_SIZE_, ICON_SIZE_});
auto sp = std::make_unique<SurfaceSprite>(icon_surface_, (SDL_FRect){0, 0, ICON_SIZE, ICON_SIZE});
sp->setPosition({PADDING_IN_H, PADDING_IN_V, ICON_SIZE, ICON_SIZE});
sp->setClip((SDL_FRect){ICON_SIZE * (icon % 10), ICON_SIZE * (icon / 10), ICON_SIZE, ICON_SIZE});
sp->render();
}

View File

@@ -22,11 +22,11 @@ enum class NotificationText {
class Notifier {
private:
// Constantes
static constexpr float ICON_SIZE_ = 16.0F;
static constexpr float PADDING_OUT_ = 0.0F;
static constexpr float ICON_SIZE = 16.0F;
static constexpr float PADDING_OUT = 0.0F;
// [SINGLETON] Objeto notifier
static Notifier* notifier_;
static Notifier* notifier;
enum class NotificationStatus {
RISING,
@@ -59,14 +59,12 @@ class Notifier {
// Constructor
explicit Notification()
: surface(nullptr), // Inicializar superficie como nula
sprite(nullptr), // Inicializar sprite como nulo
texts(), // Inicializar lista de textos vacía
sprite(nullptr), // 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
travel_dist(0), // 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