migrat Notifier a time based

This commit is contained in:
2025-10-28 10:10:47 +01:00
parent de8c714132
commit 9e8c5e13df
7 changed files with 36 additions and 20 deletions

View File

@@ -15,6 +15,7 @@
#include "core/resources/resource.hpp" // Para Resource
#include "external/jail_audio.h" // Para JA_PlaySound
#include "game/options.hpp" // Para Options, options, NotificationPosition
#include "utils/delta_timer.hpp" // Para DeltaTimer
#include "utils/utils.hpp" // Para PaletteColor
// [SINGLETON]
@@ -39,6 +40,7 @@ auto Notifier::get() -> Notifier* {
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)),
delta_timer_(std::make_unique<DeltaTimer>()),
bg_color_(Options::notifications.color),
stack_(false),
has_icons_(!icon_file.empty()) {}
@@ -51,7 +53,7 @@ void Notifier::render() {
}
// Actualiza el estado de las notificaiones
void Notifier::update() {
void Notifier::update(float delta_time) {
for (auto& notification : notifications_) {
// Si la notificación anterior está "saliendo", no hagas nada
if (!notifications_.empty() && &notification != &notifications_.front()) {
@@ -63,10 +65,11 @@ void Notifier::update() {
switch (notification.state) {
case Status::RISING: {
const int DIRECTION = 1;
notification.rect.y += DIRECTION;
const float DISPLACEMENT = SLIDE_SPEED * delta_time;
notification.rect.y += DISPLACEMENT;
if (notification.rect.y == notification.y) {
if (notification.rect.y >= notification.y) {
notification.rect.y = notification.y;
notification.state = Status::STAY;
notification.start_time = SDL_GetTicks();
}
@@ -81,10 +84,12 @@ void Notifier::update() {
}
case Status::VANISHING: {
const int DIRECTION = -1;
notification.rect.y += DIRECTION;
const float DISPLACEMENT = SLIDE_SPEED * delta_time;
notification.rect.y -= DISPLACEMENT;
if (notification.rect.y == notification.y - notification.travel_dist) {
const float TARGET_Y = notification.y - notification.travel_dist;
if (notification.rect.y <= TARGET_Y) {
notification.rect.y = TARGET_Y;
notification.state = Status::FINISHED;
}
break;