tweak(hud): zeros de farciment de la puntuació atenuats i etiqueta NIVELL en verd atenuat
This commit is contained in:
@@ -86,13 +86,39 @@ namespace Systems::InitHud {
|
||||
return (lives < 10) ? "0" + S : S;
|
||||
}
|
||||
|
||||
// Pinta el bloc d'un jugador "punts vides" amb el seu color. Si
|
||||
// right_align, el bloc acaba a anchor_x (ancorat a la dreta); si no,
|
||||
// comença a anchor_x (ancorat a l'esquerra).
|
||||
// Pinta la puntuació amb els zeros de farciment previs al primer dígit
|
||||
// significatiu en to atenuat i la resta en brillant (efecte display de 7
|
||||
// segments). Puntuació 0 (tot zeros) → tot atenuat.
|
||||
void drawScore(const Graphics::VectorText& text,
|
||||
const std::string& score,
|
||||
SDL_Color bright,
|
||||
SDL_Color dim,
|
||||
float x,
|
||||
float top_y,
|
||||
float scale,
|
||||
float spacing) {
|
||||
const size_t SIG = score.find_first_not_of('0');
|
||||
const std::string PREFIX = (SIG == std::string::npos) ? score : score.substr(0, SIG);
|
||||
const std::string REST = (SIG == std::string::npos) ? std::string{} : score.substr(SIG);
|
||||
if (!PREFIX.empty()) {
|
||||
text.render(PREFIX, {.x = x, .y = top_y}, scale, spacing, 1.0F, dim);
|
||||
// Avança l'amplada del prefix més el buit inter-caràcter que hi
|
||||
// hauria si fos un sol string (exacte per a qualsevol spacing).
|
||||
x += Graphics::VectorText::getTextWidth(PREFIX, scale, spacing) + (spacing * scale);
|
||||
}
|
||||
if (!REST.empty()) {
|
||||
text.render(REST, {.x = x, .y = top_y}, scale, spacing, 1.0F, bright);
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta el bloc d'un jugador "punts vides" amb el seu color (punts amb
|
||||
// zeros atenuats, vides en brillant). Si right_align, el bloc acaba a
|
||||
// anchor_x (ancorat a la dreta); si no, comença a anchor_x (esquerra).
|
||||
void drawPlayerBlock(const Graphics::VectorText& text,
|
||||
const std::string& score,
|
||||
int lives,
|
||||
SDL_Color color,
|
||||
SDL_Color bright,
|
||||
SDL_Color dim,
|
||||
float anchor_x,
|
||||
float top_y,
|
||||
float scale,
|
||||
@@ -104,12 +130,13 @@ namespace Systems::InitHud {
|
||||
const float BLOCK_W = W_SCORE + Defaults::Hud::Layout::BLOCK_INNER_GAP + W_LIVES;
|
||||
|
||||
float x = right_align ? (anchor_x - BLOCK_W) : anchor_x;
|
||||
text.render(score, {.x = x, .y = top_y}, scale, spacing, 1.0F, color);
|
||||
drawScore(text, score, bright, dim, x, top_y, scale, spacing);
|
||||
x += W_SCORE + Defaults::Hud::Layout::BLOCK_INNER_GAP;
|
||||
text.render(LIVES_STR, {.x = x, .y = top_y}, scale, spacing, 1.0F, color);
|
||||
text.render(LIVES_STR, {.x = x, .y = top_y}, scale, spacing, 1.0F, bright);
|
||||
}
|
||||
|
||||
// Pinta el nivell ("NIVELL" + número) centrat a la pantalla.
|
||||
// Pinta el nivell centrat: etiqueta "NIVELL" en verd atenuat i el número
|
||||
// en verd brillant.
|
||||
void drawLevel(const Graphics::VectorText& text,
|
||||
const std::string& label,
|
||||
const std::string& value,
|
||||
@@ -120,7 +147,7 @@ namespace Systems::InitHud {
|
||||
const float W_VALUE = Graphics::VectorText::getTextWidth(value, scale, spacing);
|
||||
const float CX = Defaults::Game::WIDTH / 2.0F;
|
||||
float x = CX - ((W_LABEL + W_VALUE) / 2.0F);
|
||||
text.render(label, {.x = x, .y = top_y}, scale, spacing, 1.0F, Defaults::Hud::Colors::LEVEL_BRIGHT);
|
||||
text.render(label, {.x = x, .y = top_y}, scale, spacing, 1.0F, Defaults::Hud::Colors::LEVEL_DIM);
|
||||
x += W_LABEL;
|
||||
text.render(value, {.x = x, .y = top_y}, scale, spacing, 1.0F, Defaults::Hud::Colors::LEVEL_BRIGHT);
|
||||
}
|
||||
@@ -138,8 +165,8 @@ namespace Systems::InitHud {
|
||||
const float RIGHT = play.x + play.w;
|
||||
const float TOP_Y = center_y - (Graphics::VectorText::getTextHeight(scale) / 2.0F);
|
||||
|
||||
drawPlayerBlock(text, data.score_p1, data.lives_p1, Defaults::Hud::Colors::P1_BRIGHT, LEFT, TOP_Y, scale, spacing, false);
|
||||
drawPlayerBlock(text, data.score_p2, data.lives_p2, Defaults::Hud::Colors::P2_BRIGHT, RIGHT, TOP_Y, scale, spacing, true);
|
||||
drawPlayerBlock(text, data.score_p1, data.lives_p1, Defaults::Hud::Colors::P1_BRIGHT, Defaults::Hud::Colors::P1_DIM, LEFT, TOP_Y, scale, spacing, false);
|
||||
drawPlayerBlock(text, data.score_p2, data.lives_p2, Defaults::Hud::Colors::P2_BRIGHT, Defaults::Hud::Colors::P2_DIM, RIGHT, TOP_Y, scale, spacing, true);
|
||||
drawLevel(text, data.level_label, data.level_value, TOP_Y, scale, spacing);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user