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:
@@ -39,7 +39,6 @@ Notifier::Notifier(const std::string &icon_file, const std::string &text)
|
||||
: icon_surface_(!icon_file.empty() ? Resource::get()->getSurface(icon_file) : nullptr),
|
||||
text_(Resource::get()->getText(text)),
|
||||
bg_color_(options.notifications.color),
|
||||
wait_time_(150),
|
||||
stack_(false),
|
||||
has_icons_(!icon_file.empty()) {}
|
||||
|
||||
@@ -66,75 +65,47 @@ void Notifier::update()
|
||||
}
|
||||
}
|
||||
|
||||
notifications_[i].counter++;
|
||||
|
||||
// Hace sonar la notificación en el primer frame
|
||||
if (notifications_[i].counter == 1)
|
||||
switch (notifications_[i].state)
|
||||
{
|
||||
if (options.notifications.sound)
|
||||
{
|
||||
if (notifications_[i].state == NotificationStatus::RISING)
|
||||
{
|
||||
// Reproduce el sonido de la notificación
|
||||
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los estados
|
||||
if (notifications_[i].state == NotificationStatus::RISING)
|
||||
case NotificationStatus::RISING:
|
||||
{
|
||||
// const float step = ((float)notifications_[i].counter / notifications_[i].travel_dist);
|
||||
// const int alpha = 255 * step;
|
||||
// constexpr int ALPHA = 255;
|
||||
|
||||
if (options.notifications.getVerticalPosition() == NotificationPosition::TOP)
|
||||
{
|
||||
notifications_[i].rect.y++;
|
||||
}
|
||||
else if (options.notifications.getVerticalPosition() == NotificationPosition::BOTTOM)
|
||||
{
|
||||
notifications_[i].rect.y--;
|
||||
}
|
||||
// notifications_[i].surface->setAlpha(ALPHA);
|
||||
const int DIRECTION = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? 1 : -1;
|
||||
notifications_[i].rect.y += DIRECTION;
|
||||
|
||||
if (notifications_[i].rect.y == notifications_[i].y)
|
||||
{
|
||||
notifications_[i].state = NotificationStatus::STAY;
|
||||
// notifications_[i].surface->setAlpha(255);
|
||||
notifications_[i].counter = 0;
|
||||
notifications_[i].start_time = SDL_GetTicks();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
else if (notifications_[i].state == NotificationStatus::STAY)
|
||||
case NotificationStatus::STAY:
|
||||
{
|
||||
if (notifications_[i].counter == wait_time_)
|
||||
notifications_[i].elapsed_time = SDL_GetTicks() - notifications_[i].start_time;
|
||||
if (notifications_[i].elapsed_time >= notifications_[i].display_duration)
|
||||
{
|
||||
notifications_[i].state = NotificationStatus::VANISHING;
|
||||
notifications_[i].counter = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (notifications_[i].state == NotificationStatus::VANISHING)
|
||||
|
||||
case NotificationStatus::VANISHING:
|
||||
{
|
||||
|
||||
// const float step = (notifications_[i].counter / (float)notifications_[i].travel_dist);
|
||||
// const int ALPHA = 255 * (1 - step);
|
||||
// constexpr int ALPHA = 255;
|
||||
|
||||
if (options.notifications.getVerticalPosition() == NotificationPosition::TOP)
|
||||
{
|
||||
notifications_[i].rect.y--;
|
||||
}
|
||||
else if (options.notifications.getVerticalPosition() == NotificationPosition::BOTTOM)
|
||||
{
|
||||
notifications_[i].rect.y++;
|
||||
}
|
||||
// notifications_[i].surface->setAlpha(ALPHA);
|
||||
const int DIRECTION = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? -1 : 1;
|
||||
notifications_[i].rect.y += DIRECTION;
|
||||
|
||||
if (notifications_[i].rect.y == notifications_[i].y - notifications_[i].travel_dist)
|
||||
{
|
||||
notifications_[i].state = NotificationStatus::FINISHED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case NotificationStatus::FINISHED:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
notifications_[i].sprite->setPosition(notifications_[i].rect);
|
||||
@@ -155,7 +126,7 @@ void Notifier::clearFinishedNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
void Notifier::show(std::vector<std::string> texts, NotificationText text_is, int icon, bool can_be_removed, const std::string &code)
|
||||
void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Uint32 display_duration, int icon, bool can_be_removed, const std::string &code)
|
||||
{
|
||||
// Si no hay texto, acaba
|
||||
if (texts.empty())
|
||||
@@ -179,11 +150,12 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
for (const auto &text : texts)
|
||||
{
|
||||
if (text.length() > longest.length())
|
||||
{
|
||||
longest = text;
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
//const int text_size = text_->getCharacterSize();
|
||||
const int text_size = 6;
|
||||
const auto PADDING_IN_H = text_size;
|
||||
const auto PADDING_IN_V = text_size / 2;
|
||||
@@ -194,33 +166,34 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
const auto SHAPE = NotificationShape::SQUARED;
|
||||
|
||||
// Posición horizontal
|
||||
auto desp_h = 0;
|
||||
if (options.notifications.getHorizontalPosition() == NotificationPosition::LEFT)
|
||||
int desp_h = 0;
|
||||
switch (options.notifications.getHorizontalPosition())
|
||||
{
|
||||
case NotificationPosition::LEFT:
|
||||
desp_h = PADDING_OUT_;
|
||||
}
|
||||
else if (options.notifications.getHorizontalPosition() == NotificationPosition::CENTER)
|
||||
{
|
||||
break;
|
||||
|
||||
case NotificationPosition::CENTER:
|
||||
desp_h = ((options.game.width / 2) - (WIDTH / 2));
|
||||
}
|
||||
else if (options.notifications.getHorizontalPosition() == NotificationPosition::RIGHT)
|
||||
{
|
||||
break;
|
||||
|
||||
case NotificationPosition::RIGHT:
|
||||
desp_h = options.game.width - WIDTH - PADDING_OUT_;
|
||||
break;
|
||||
|
||||
default:
|
||||
desp_h = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
const int DESP_V = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? PADDING_OUT_ : options.game.height - HEIGHT - PADDING_OUT_;
|
||||
|
||||
// Offset
|
||||
const auto TRAVEL_DIST = HEIGHT + PADDING_OUT_;
|
||||
auto offset = 0;
|
||||
if (options.notifications.getVerticalPosition() == NotificationPosition::TOP)
|
||||
{
|
||||
offset = !notifications_.empty() ? notifications_.back().y + notifications_.back().travel_dist : DESP_V;
|
||||
}
|
||||
else if (options.notifications.getVerticalPosition() == NotificationPosition::BOTTOM)
|
||||
{
|
||||
offset = !notifications_.empty() ? notifications_.back().y - notifications_.back().travel_dist : DESP_V;
|
||||
}
|
||||
const int TRAVEL_MOD = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? 1 : -1;
|
||||
const int OFFSET = !notifications_.empty() ? notifications_.back().y + TRAVEL_MOD * notifications_.back().travel_dist : DESP_V;
|
||||
|
||||
|
||||
// Crea la notificacion
|
||||
Notification n;
|
||||
@@ -228,12 +201,13 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
// Inicializa variables
|
||||
n.code = code;
|
||||
n.can_be_removed = can_be_removed;
|
||||
n.y = offset;
|
||||
n.y = OFFSET;
|
||||
n.travel_dist = TRAVEL_DIST;
|
||||
n.texts = texts;
|
||||
n.shape = SHAPE;
|
||||
int y_pos = offset + ((options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? -TRAVEL_DIST : TRAVEL_DIST);
|
||||
n.rect = {desp_h, y_pos, WIDTH, HEIGHT};
|
||||
n.display_duration = display_duration;
|
||||
const int Y_POS = OFFSET + ((options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? -TRAVEL_DIST : TRAVEL_DIST);
|
||||
n.rect = {desp_h, Y_POS, WIDTH, HEIGHT};
|
||||
|
||||
// Crea la textura
|
||||
n.surface = std::make_shared<Surface>(WIDTH, HEIGHT);
|
||||
@@ -303,6 +277,9 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
|
||||
// Añade la notificación a la lista
|
||||
notifications_.emplace_back(n);
|
||||
|
||||
// Reproduce el sonido de la notificación
|
||||
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
||||
}
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
|
||||
Reference in New Issue
Block a user