feat(notifier): geometria al ui.yaml; +1px alçada, text 1px més avall, marge superior 3
This commit is contained in:
1 parent
643e5442c3
commit
2e8df45b38
6 files changed
+92
-27
No files matched your search
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "core/rendering/screen.hpp"
|
||||
#include "core/rendering/text.hpp"
|
||||
#include "core/ui/ui_config.hpp"
|
||||
#include "utils/defines.hpp"
|
||||
|
||||
namespace {
|
||||
@@ -67,12 +68,13 @@ void Notifier::init(std::shared_ptr<Text> text, const Palette& ui_palette) {
|
||||
}
|
||||
|
||||
void Notifier::update(int delta_ms) {
|
||||
const auto& geo = UiConfig::get().notifier();
|
||||
const float DT = static_cast<float>(delta_ms) / 1000.0F;
|
||||
switch (status_) {
|
||||
case Status::RISING:
|
||||
y_ += SLIDE_SPEED * DT;
|
||||
if (y_ >= static_cast<float>(MARGIN_TOP + BORDER_PX)) {
|
||||
y_ = static_cast<float>(MARGIN_TOP + BORDER_PX);
|
||||
y_ += geo.slide_speed * DT;
|
||||
if (y_ >= static_cast<float>(geo.margin_top + geo.border_px)) {
|
||||
y_ = static_cast<float>(geo.margin_top + geo.border_px);
|
||||
status_ = Status::ACTIVE;
|
||||
}
|
||||
break;
|
||||
@@ -81,9 +83,9 @@ void Notifier::update(int delta_ms) {
|
||||
if (remaining_ms_ <= 0) { status_ = Status::VANISHING; }
|
||||
break;
|
||||
case Status::VANISHING:
|
||||
y_ -= SLIDE_SPEED * DT;
|
||||
if (y_ <= static_cast<float>(-current_box_h_ - BORDER_PX)) {
|
||||
y_ = static_cast<float>(-current_box_h_ - BORDER_PX - MARGIN_TOP);
|
||||
y_ -= geo.slide_speed * DT;
|
||||
if (y_ <= static_cast<float>(-current_box_h_ - geo.border_px)) {
|
||||
y_ = static_cast<float>(-current_box_h_ - geo.border_px - geo.margin_top);
|
||||
status_ = Status::HIDDEN;
|
||||
}
|
||||
break;
|
||||
@@ -95,6 +97,7 @@ void Notifier::update(int delta_ms) {
|
||||
void Notifier::render() {
|
||||
if (status_ == Status::HIDDEN || text_ == nullptr || current_lines_.empty()) { return; }
|
||||
|
||||
const auto& geo = UiConfig::get().notifier();
|
||||
const int BOX_X = (GameCanvas::WIDTH - current_box_w_) / 2;
|
||||
const int BOX_Y = static_cast<int>(y_);
|
||||
|
||||
@@ -106,13 +109,13 @@ void Notifier::render() {
|
||||
// costat i una mica fora de la caixa. Cada segment es queda dins del
|
||||
// rang del costat corresponent perquè les cantonades no es cobrisquen.
|
||||
const std::uint32_t BORDER_ARGB = ui_palette_[current_text_color_];
|
||||
Screen::get().fillRect(BOX_X, BOX_Y - BORDER_PX, current_box_w_, BORDER_PX, BORDER_ARGB);
|
||||
Screen::get().fillRect(BOX_X, BOX_Y + current_box_h_, current_box_w_, BORDER_PX, BORDER_ARGB);
|
||||
Screen::get().fillRect(BOX_X - BORDER_PX, BOX_Y, BORDER_PX, current_box_h_, BORDER_ARGB);
|
||||
Screen::get().fillRect(BOX_X + current_box_w_, BOX_Y, BORDER_PX, current_box_h_, BORDER_ARGB);
|
||||
Screen::get().fillRect(BOX_X, BOX_Y - geo.border_px, current_box_w_, geo.border_px, BORDER_ARGB);
|
||||
Screen::get().fillRect(BOX_X, BOX_Y + current_box_h_, current_box_w_, geo.border_px, BORDER_ARGB);
|
||||
Screen::get().fillRect(BOX_X - geo.border_px, BOX_Y, geo.border_px, current_box_h_, BORDER_ARGB);
|
||||
Screen::get().fillRect(BOX_X + current_box_w_, BOX_Y, geo.border_px, current_box_h_, BORDER_ARGB);
|
||||
|
||||
const int LINE_STEP = Rendering::Hud::FONT_SIZE_PX + LINE_GAP;
|
||||
int line_y = BOX_Y + PADDING_V;
|
||||
const int LINE_STEP = Rendering::Hud::FONT_SIZE_PX + geo.line_gap;
|
||||
int line_y = BOX_Y + geo.padding_top;
|
||||
for (const auto& line : current_lines_) {
|
||||
text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
||||
GameCanvas::CENTER_X,
|
||||
@@ -129,18 +132,20 @@ void Notifier::notify(const std::string& text, Uint8 text_color, Uint8 bg_color,
|
||||
// gestionar-ne una cua, canviar ací per una FIFO quan calga.
|
||||
if (text_ == nullptr) { return; }
|
||||
|
||||
const auto& geo = UiConfig::get().notifier();
|
||||
const int MAX_TEXT_WIDTH = GameCanvas::WIDTH - (2 * SIDE_MARGIN) - (2 * geo.padding_h);
|
||||
current_lines_ = wrapToWidth(text, MAX_TEXT_WIDTH, *text_, 1);
|
||||
|
||||
// Amplada = max de les línies + padding. Alçada = N*glif + (N-1)*gap + padding.
|
||||
// Amplada = max de les línies + padding. Alçada = N*glif + (N-1)*gap + padding asimètric.
|
||||
const int MAX_LINE_W = std::accumulate(current_lines_.begin(), current_lines_.end(), 0, [this](int acc, const std::string& s) { return std::max(acc, text_->length(s, 1)); });
|
||||
current_box_w_ = MAX_LINE_W + (2 * PADDING_H);
|
||||
current_box_w_ = MAX_LINE_W + (2 * geo.padding_h);
|
||||
|
||||
const int N = static_cast<int>(current_lines_.size());
|
||||
current_box_h_ = (N * Rendering::Hud::FONT_SIZE_PX) + ((N - 1) * LINE_GAP) + (2 * PADDING_V);
|
||||
current_box_h_ = (N * Rendering::Hud::FONT_SIZE_PX) + ((N - 1) * geo.line_gap) + geo.padding_top + geo.padding_bottom;
|
||||
|
||||
current_text_color_ = text_color;
|
||||
current_bg_color_ = bg_color;
|
||||
remaining_ms_ = time_ms;
|
||||
y_ = static_cast<float>(-current_box_h_ - BORDER_PX - MARGIN_TOP);
|
||||
y_ = static_cast<float>(-current_box_h_ - geo.border_px - geo.margin_top);
|
||||
status_ = Status::RISING;
|
||||
}
|
||||
Reference in new issue
Block a user