64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "game/ui/notification_presets.hpp"
|
|
|
|
class Text;
|
|
|
|
// Popup transitori a dalt i centrat. Entra lliscant des de dalt, es queda
|
|
// visible el temps configurat i surt lliscant cap amunt. Comparteix la font
|
|
// 8bithud i la paleta "ui" amb la resta d'overlays (carregades per RenderInfo
|
|
// a l'arrencada; si Notifier::init() es crida primer, les carrega ell).
|
|
//
|
|
// Ús típic:
|
|
// Notifier::get().notify("Text ràpid"); // preset DEFAULT
|
|
// Notifier::get().notify("Text ràpid", miPreset); // preset custom
|
|
// Notifier::get().notify("Urgent", 11, 3, 800); // colors i durada explícits
|
|
class Notifier {
|
|
public:
|
|
static auto get() -> Notifier&;
|
|
|
|
Notifier(const Notifier&) = delete;
|
|
Notifier(Notifier&&) = delete;
|
|
auto operator=(const Notifier&) -> Notifier& = delete;
|
|
auto operator=(Notifier&&) -> Notifier& = delete;
|
|
|
|
void init();
|
|
|
|
void update(int delta_ms);
|
|
void render();
|
|
|
|
// Tres overloads; els dos simples deleguen al tercer.
|
|
void notify(const std::string& text);
|
|
void notify(const std::string& text, const Notification::Preset& preset);
|
|
void notify(const std::string& text, Uint8 text_color, Uint8 bg_color, int time_ms);
|
|
|
|
static constexpr int PADDING_H = 6;
|
|
static constexpr int PADDING_V = 3;
|
|
static constexpr int TEXT_SIZE = 8;
|
|
static constexpr int HEIGHT = TEXT_SIZE + (2 * PADDING_V);
|
|
static constexpr float SLIDE_SPEED = 120.0F;
|
|
|
|
private:
|
|
enum class Status : std::uint8_t { HIDDEN,
|
|
RISING,
|
|
ACTIVE,
|
|
VANISHING };
|
|
|
|
Notifier() = default;
|
|
~Notifier();
|
|
|
|
std::unique_ptr<Text> text_;
|
|
Status status_{Status::HIDDEN};
|
|
float y_{static_cast<float>(-HEIGHT)};
|
|
std::string current_text_;
|
|
Uint8 current_text_color_{0};
|
|
Uint8 current_bg_color_{0};
|
|
int remaining_ms_{0};
|
|
};
|