feat(hud): paleta per segments (P1 blanc, vides ambre, nivell verd, P2 rosa)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/defaults/hud.hpp"
|
||||
#include "core/math/easing.hpp"
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
|
||||
@@ -77,8 +78,40 @@ namespace Systems::InitHud {
|
||||
}
|
||||
}
|
||||
|
||||
void drawScoreboardSegmentsAt(const Graphics::VectorText& text,
|
||||
const ScoreboardSegments& segments,
|
||||
const Vec2& center,
|
||||
float scale,
|
||||
float spacing) {
|
||||
// Separadors entre segments (preservant el layout legacy: " ", " ", " ", " ").
|
||||
const float W_SEP1 = Graphics::VectorText::getTextWidth(" ", scale, spacing);
|
||||
const float W_SEP2 = Graphics::VectorText::getTextWidth(" ", scale, spacing);
|
||||
|
||||
const float W_SP1 = Graphics::VectorText::getTextWidth(segments.score_p1, scale, spacing);
|
||||
const float W_LP1 = Graphics::VectorText::getTextWidth(segments.lives_p1, scale, spacing);
|
||||
const float W_LV = Graphics::VectorText::getTextWidth(segments.level, scale, spacing);
|
||||
const float W_SP2 = Graphics::VectorText::getTextWidth(segments.score_p2, scale, spacing);
|
||||
const float W_LP2 = Graphics::VectorText::getTextWidth(segments.lives_p2, scale, spacing);
|
||||
|
||||
const float TOTAL = W_SP1 + W_SEP1 + W_LP1 + W_SEP2 + W_LV + W_SEP2 + W_SP2 + W_SEP1 + W_LP2;
|
||||
|
||||
const float HEIGHT = Graphics::VectorText::getTextHeight(scale);
|
||||
const float TOP_Y = center.y - (HEIGHT / 2.0F);
|
||||
float x = center.x - (TOTAL / 2.0F);
|
||||
|
||||
text.render(segments.score_p1, {.x = x, .y = TOP_Y}, scale, spacing, 1.0F, Defaults::Hud::Colors::SCORE_P1);
|
||||
x += W_SP1 + W_SEP1;
|
||||
text.render(segments.lives_p1, {.x = x, .y = TOP_Y}, scale, spacing, 1.0F, Defaults::Hud::Colors::LIVES);
|
||||
x += W_LP1 + W_SEP2;
|
||||
text.render(segments.level, {.x = x, .y = TOP_Y}, scale, spacing, 1.0F, Defaults::Hud::Colors::LEVEL);
|
||||
x += W_LV + W_SEP2;
|
||||
text.render(segments.score_p2, {.x = x, .y = TOP_Y}, scale, spacing, 1.0F, Defaults::Hud::Colors::SCORE_P2);
|
||||
x += W_SP2 + W_SEP1;
|
||||
text.render(segments.lives_p2, {.x = x, .y = TOP_Y}, scale, spacing, 1.0F, Defaults::Hud::Colors::LIVES);
|
||||
}
|
||||
|
||||
void drawScoreboardAnimated(const Graphics::VectorText& text,
|
||||
const std::string& scoreboard_text,
|
||||
const ScoreboardSegments& segments,
|
||||
float progress) {
|
||||
const float EASED = Easing::easeOutQuad(progress);
|
||||
|
||||
@@ -91,10 +124,7 @@ namespace Systems::InitHud {
|
||||
const auto Y_INI = static_cast<float>(Defaults::Game::HEIGHT);
|
||||
const float Y_ANIM = Y_INI + ((Y_FINAL - Y_INI) * EASED);
|
||||
|
||||
text.renderCentered(scoreboard_text,
|
||||
Vec2{.x = CENTRE_X, .y = Y_ANIM},
|
||||
SCALE,
|
||||
SPACING);
|
||||
drawScoreboardSegmentsAt(text, segments, {.x = CENTRE_X, .y = Y_ANIM}, SCALE, SPACING);
|
||||
}
|
||||
|
||||
} // namespace Systems::InitHud
|
||||
|
||||
@@ -21,6 +21,17 @@
|
||||
|
||||
namespace Systems::InitHud {
|
||||
|
||||
// Segments del marcador. Cada segment es renderitza amb el seu propi color
|
||||
// (vegeu Defaults::Hud::Colors). El layout final concatena en aquest ordre
|
||||
// amb separadors d'1, 2, 2, 1 espais respectivament (igual que el legacy).
|
||||
struct ScoreboardSegments {
|
||||
std::string score_p1;
|
||||
std::string lives_p1;
|
||||
std::string level; // ex: "NIVELL 01"
|
||||
std::string score_p2;
|
||||
std::string lives_p2;
|
||||
};
|
||||
|
||||
// Convierte un progreso global 0..1 al sub-progreso de un elemento que solo
|
||||
// se anima en la ventana [ratio_init, ratio_end].
|
||||
// < ratio_init → 0.0 (no empezó)
|
||||
@@ -40,10 +51,19 @@ namespace Systems::InitHud {
|
||||
// 66..100% → línea inferior crece desde los lados hacia el centro.
|
||||
void drawBordersAnimated(Rendering::Renderer* renderer, float progress);
|
||||
|
||||
// Dibuja el scoreboard centrado, subiendo desde fuera de la pantalla
|
||||
// hasta su posición final con easing.
|
||||
// Dibuixa els 5 segments del scoreboard centrats al voltant de `center`,
|
||||
// cadascun amb el seu color (Defaults::Hud::Colors). Separadors de 1/2/2/1
|
||||
// espais entre segments per preservar el layout legacy.
|
||||
void drawScoreboardSegmentsAt(const Graphics::VectorText& text,
|
||||
const ScoreboardSegments& segments,
|
||||
const Vec2& center,
|
||||
float scale,
|
||||
float spacing);
|
||||
|
||||
// Dibuixa el scoreboard centrat, pujant des de fora de la pantalla fins a
|
||||
// la seva posició final amb easing. Delega a drawScoreboardSegmentsAt.
|
||||
void drawScoreboardAnimated(const Graphics::VectorText& text,
|
||||
const std::string& scoreboard_text,
|
||||
const ScoreboardSegments& segments,
|
||||
float progress);
|
||||
|
||||
} // namespace Systems::InitHud
|
||||
|
||||
Reference in New Issue
Block a user