forked from jaildesigner-jailgames/jaildoctors_dilemma
migrat Notifier a time based
This commit is contained in:
@@ -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() && ¬ification != ¬ifications_.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;
|
||||
|
||||
Reference in New Issue
Block a user