afegit defaults.h amb els valors per defecte de Param

This commit is contained in:
2025-08-16 10:29:30 +02:00
parent 0c10898bdc
commit 81d486f2d3
6 changed files with 316 additions and 231 deletions

View File

@@ -49,16 +49,14 @@ void Notifier::update() {
if (!shouldProcessNotification(i)) {
break;
}
processNotification(i);
}
clearFinishedNotifications();
}
auto Notifier::shouldProcessNotification(int index) const -> bool {
// Si la notificación anterior está "saliendo", no hagas nada
return index <= 0 || notifications_[index - 1].state != NotificationStatus::RISING;
return index <= 0 || notifications_[index - 1].state != State::RISING;
}
void Notifier::processNotification(int index) {
@@ -74,7 +72,7 @@ void Notifier::playNotificationSoundIfNeeded(const Notification& notification) {
// Hace sonar la notificación en el primer frame
if (notification.counter == 1 &&
param.notification.sound &&
notification.state == NotificationStatus::RISING) {
notification.state == State::RISING) {
Audio::get()->playSound("notify.wav", Audio::Group::INTERFACE);
}
}
@@ -83,13 +81,13 @@ void Notifier::updateNotificationState(int index) {
auto& notification = notifications_[index];
switch (notification.state) {
case NotificationStatus::RISING:
case State::RISING:
handleRisingState(index);
break;
case NotificationStatus::STAY:
case State::STAY:
handleStayState(index);
break;
case NotificationStatus::VANISHING:
case State::VANISHING:
handleVanishingState(index);
break;
default:
@@ -103,7 +101,7 @@ void Notifier::handleRisingState(int index) {
const float STEP = (float)notification.counter / notification.travel_dist;
const int ALPHA = 255 * STEP;
moveNotificationVertically(notification, param.notification.pos_v == NotifyPosition::TOP ? 1 : -1);
moveNotificationVertically(notification, param.notification.pos_v == Position::TOP ? 1 : -1);
notification.texture->setAlpha(ALPHA);
if (notification.rect.y == notification.y) {
@@ -115,7 +113,7 @@ void Notifier::handleStayState(int index) {
auto& notification = notifications_[index];
if (notification.counter == wait_time_) {
notification.state = NotificationStatus::VANISHING;
notification.state = State::VANISHING;
notification.counter = 0;
}
}
@@ -126,11 +124,11 @@ void Notifier::handleVanishingState(int index) {
const float STEP = notification.counter / (float)notification.travel_dist;
const int ALPHA = 255 * (1 - STEP);
moveNotificationVertically(notification, param.notification.pos_v == NotifyPosition::TOP ? -1 : 1);
moveNotificationVertically(notification, param.notification.pos_v == Position::TOP ? -1 : 1);
notification.texture->setAlpha(ALPHA);
if (notification.rect.y == notification.y - notification.travel_dist) {
notification.state = NotificationStatus::FINISHED;
notification.state = State::FINISHED;
}
}
@@ -140,7 +138,7 @@ void Notifier::moveNotificationVertically(Notification& notification, int direct
void Notifier::transitionToStayState(int index) {
auto& notification = notifications_[index];
notification.state = NotificationStatus::STAY;
notification.state = State::STAY;
notification.texture->setAlpha(255);
notification.counter = 0;
}
@@ -148,7 +146,7 @@ void Notifier::transitionToStayState(int index) {
// Elimina las notificaciones finalizadas
void Notifier::clearFinishedNotifications() {
for (int i = (int)notifications_.size() - 1; i >= 0; --i) {
if (notifications_[i].state == NotificationStatus::FINISHED) {
if (notifications_[i].state == State::FINISHED) {
notifications_.erase(notifications_.begin() + i);
}
}
@@ -185,20 +183,20 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string&
const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0;
const float WIDTH = text_->length(longest) + (PADDING_IN_H * 2) + ICON_SPACE;
const float HEIGHT = (text_->getCharacterSize() * texts.size()) + (PADDING_IN_V * 2);
const auto SHAPE = NotificationShape::SQUARED;
const auto SHAPE = Shape::SQUARED;
// Posición horizontal
float desp_h = 0;
switch (param.notification.pos_h) {
case NotifyPosition::LEFT:
case Position::LEFT:
desp_h = PADDING_OUT;
break;
case NotifyPosition::MIDDLE:
case Position::MIDDLE:
desp_h = ((param.game.width / 2) - (WIDTH / 2));
break;
case NotifyPosition::RIGHT:
case Position::RIGHT:
desp_h = param.game.width - WIDTH - PADDING_OUT;
break;
@@ -208,13 +206,13 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string&
}
// Posición vertical
const int DESP_V = (param.notification.pos_v == NotifyPosition::TOP) ? PADDING_OUT : (param.game.height - HEIGHT - PADDING_OUT);
const int DESP_V = (param.notification.pos_v == Position::TOP) ? PADDING_OUT : (param.game.height - HEIGHT - PADDING_OUT);
// Offset
const auto TRAVEL_DIST = HEIGHT + PADDING_OUT;
auto offset = notifications_.empty()
? DESP_V
: notifications_.back().y + (param.notification.pos_v == NotifyPosition::TOP ? TRAVEL_DIST : -TRAVEL_DIST);
: notifications_.back().y + (param.notification.pos_v == Position::TOP ? TRAVEL_DIST : -TRAVEL_DIST);
// Crea la notificacion
Notification n;
@@ -225,7 +223,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string&
n.travel_dist = TRAVEL_DIST;
n.texts = texts;
n.shape = SHAPE;
const float POS_Y = offset + (param.notification.pos_v == NotifyPosition::TOP ? -TRAVEL_DIST : TRAVEL_DIST);
const float POS_Y = offset + (param.notification.pos_v == Position::TOP ? -TRAVEL_DIST : TRAVEL_DIST);
n.rect = {desp_h, POS_Y, WIDTH, HEIGHT};
// Crea la textura
@@ -239,7 +237,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string&
// Dibuja el fondo de la notificación
SDL_SetRenderDrawColor(renderer_, bg_color_.r, bg_color_.g, bg_color_.b, 255);
SDL_FRect rect;
if (SHAPE == NotificationShape::ROUNDED) {
if (SHAPE == Shape::ROUNDED) {
rect = {4, 0, WIDTH - (4 * 2), HEIGHT};
SDL_RenderFillRect(renderer_, &rect);
@@ -253,7 +251,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string&
SDL_RenderFillRect(renderer_, &rect);
}
else if (SHAPE == NotificationShape::SQUARED) {
else if (SHAPE == Shape::SQUARED) {
SDL_RenderClear(renderer_);
}
@@ -293,7 +291,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string&
// Finaliza y elimnina todas las notificaciones activas
void Notifier::clearAllNotifications() {
for (auto& notification : notifications_) {
notification.state = NotificationStatus::FINISHED;
notification.state = State::FINISHED;
}
clearFinishedNotifications();