Files
aee-arcade/source/core/rendering/notifier.hpp
T
JailDesignerandClaude Opus 4.7 32d6067752 refactor(core/rendering): injectar font i paleta als overlays (COUP-04) + tancament auditoria
Notifier::init i RenderInfo::init cridaven Resource::Cache::get() i
construïen cadascun la seua pròpia instància de Text a partir de
"8bithud.gif" + "data/font/8bithud.fnt" (strings hardcoded). Notifier
també llegia la paleta "ui" a cada render().

Ara:
- Director construeix una sola std::shared_ptr<Text> compartida.
- RenderInfo::init(Frame, shared_ptr<Text>) i Notifier::init
  (shared_ptr<Text>, const Palette&) reben els recursos injectats.
- Notifier desa la Palette una volta i la consulta localment a
  render(), sense tocar el cache global.

Resultat: els overlays perden la dependència dels noms dels assets
i del cache; el cicle de vida queda controlat pel Director. El camp
intern text_ passa a shared_ptr<Text>.

El document d'auditoria es tanca:
- PATCH-02, COUP-05 → DEFERRED (feature beyond cleanup scope).
- INC-04 → WONTFIX (coexistència justificada de writeDX/write*).
- Estat global: neteja completada.

Build + smoke 5s xvfb OK (exit 124).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 10:05:58 +02:00

64 lines
2.0 KiB
C++

#pragma once
#include <SDL3/SDL.h>
#include <cstdint>
#include <memory>
#include <string>
#include "core/rendering/hud_constants.hpp"
#include "core/rendering/surface.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 del joc, vegeu Notification::notify() a
// game/ui/notification_presets.hpp.
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> 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);
static constexpr int PADDING_H = 6;
static constexpr int PADDING_V = 3;
static constexpr int HEIGHT = Rendering::Hud::FONT_SIZE_PX + (2 * PADDING_V);
static constexpr int MARGIN_TOP = 2; // Separació amb la vora superior del canvas.
static constexpr float SLIDE_SPEED = 120.0F;
private:
enum class Status : std::uint8_t { HIDDEN,
RISING,
ACTIVE,
VANISHING };
Notifier() = default;
~Notifier();
std::shared_ptr<Text> text_;
Palette ui_palette_{};
Status status_{Status::HIDDEN};
float y_{static_cast<float>(-HEIGHT - MARGIN_TOP)};
std::string current_text_;
Uint8 current_text_color_{0};
Uint8 current_bg_color_{0};
int remaining_ms_{0};
};