feat(notifier): suport multilinia amb wrap automàtic per espais
This commit is contained in:
1 parent
591b4b58e5
commit
be9309d342
2 files changed
+91
-17
No files matched your search
@@ -5,9 +5,11 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "core/rendering/hud_constants.hpp"
|
||||
#include "core/rendering/surface.hpp"
|
||||
#include "utils/defines.hpp"
|
||||
|
||||
class Text;
|
||||
|
||||
@@ -19,6 +21,10 @@ class Text;
|
||||
// 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&;
|
||||
@@ -39,9 +45,13 @@ class Notifier {
|
||||
|
||||
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 LINE_GAP = 1; // Separació vertical entre línies multilinia.
|
||||
static constexpr int MARGIN_TOP = 2; // Separació amb la vora superior del canvas.
|
||||
static constexpr float SLIDE_SPEED = 120.0F;
|
||||
// Amplada màxima (sense comptar padding) que pot ocupar el text abans que
|
||||
// `wrapToWidth` el parteixi en línies. Deixem marge respecte a la vora del
|
||||
// canvas perquè la caixa no toqui els laterals.
|
||||
static constexpr int MAX_TEXT_WIDTH = GameCanvas::WIDTH - 20 - (2 * PADDING_H);
|
||||
|
||||
private:
|
||||
enum class Status : std::uint8_t { HIDDEN,
|
||||
@@ -55,8 +65,10 @@ class 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_;
|
||||
float y_{0.0F};
|
||||
std::vector<std::string> 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};
|
||||
|
||||
Reference in new issue
Block a user