#pragma once #include #include #include #include #include #include "core/rendering/hud_constants.hpp" #include "core/rendering/surface.hpp" #include "utils/defines.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). // // API crua: Notifier::get().notify(text, text_color, bg_color, time_ms). // Per a treballar amb presets pre-definits, vegeu Notification::notify() a // core/rendering/notification_presets.hpp. // // Multilinia: si el text passa de l'amplada màxima (`MAX_TEXT_WIDTH`), es // parteix per espais i la caixa creix en alçada automàticament. Els textos // curts (cas habitual) ocupen una sola línia i no canvien d'aspecte. 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; // Injecta la font compartida i la paleta UI que usa la caixa de fons. // Així Notifier no depèn de cap string de recurs ni del cache global. void init(std::shared_ptr text, const Palette& ui_palette); void update(int delta_ms); void render(); void notify(const std::string& text, Uint8 text_color, Uint8 bg_color, int time_ms); // Marge lateral entre la caixa i les vores esquerra/dreta del canvas. // Limita l'amplada disponible al text en multilinia (combinat amb el // padding horitzontal llegit d'UiConfig). No està exposat al YAML // perquè en pantalles 240 px no té sentit retallar més. static constexpr int SIDE_MARGIN = 10; private: enum class Status : std::uint8_t { HIDDEN, RISING, ACTIVE, VANISHING }; Notifier() = default; ~Notifier(); std::shared_ptr text_; Palette ui_palette_{}; Status status_{Status::HIDDEN}; float y_{0.0F}; std::vector current_lines_; int current_box_w_{0}; int current_box_h_{0}; Uint8 current_text_color_{0}; Uint8 current_bg_color_{0}; int remaining_ms_{0}; // Animació d'entrada/eixida per temps. `slide_elapsed_ms_` avança // amb el delta dins de RISING/VANISHING; els extrems s'avaluen a // `notify()` perquè depenen de la mida de la caixa. int slide_elapsed_ms_{0}; float slide_y_off_{0.0F}; float slide_y_on_{0.0F}; };