tweak(hud): fila del marcador centrada amb posicions fixes (sense justificar a les vores)

This commit is contained in:
2026-05-29 20:44:37 +02:00
parent 17e9206d26
commit 56065995fd
+33 -17
View File
@@ -166,10 +166,21 @@ namespace Systems::InitHud {
}
}
// Separació punts↔slots dins d'un bloc = un pas de dígit (ritme únic).
auto blockInnerGap(float scale, float spacing) -> float {
return digitPitch(scale, spacing);
}
// Ample (constant) del bloc d'un jugador: 6 dígits + separació + slots.
// No depèn de les vides, així res es recol·loca quan se'n perden.
auto playerBlockWidth(float scale, float spacing) -> float {
return Graphics::VectorText::getTextWidth("000000", scale, spacing) +
blockInnerGap(scale, spacing) + slotsBlockWidth(scale, spacing);
}
// Pinta el bloc d'un jugador "punts vides" amb el seu color (punts amb
// zeros atenuats, vides com a icones de nau en brillant). Si right_align,
// el bloc acaba a anchor_x (ancorat a la dreta); si no, comença a
// anchor_x (esquerra).
// zeros atenuats, vides com a slots de nau). Ancorat a x_left (vora
// esquerra del bloc), mateix ordre per a P1 i P2 (no mirrored).
void drawPlayerBlock(Rendering::Renderer* renderer,
const Graphics::VectorText& text,
const std::shared_ptr<Graphics::Shape>& shape,
@@ -177,20 +188,16 @@ namespace Systems::InitHud {
int lives,
SDL_Color bright,
SDL_Color dim,
float anchor_x,
float x_left,
float center_y,
float scale,
float spacing,
bool right_align) {
float spacing) {
const float TOP_Y = center_y - (Graphics::VectorText::getTextHeight(scale) / 2.0F);
const float W_SCORE = Graphics::VectorText::getTextWidth(score, scale, spacing);
const float GAP = digitPitch(scale, spacing); // separació punts↔slots = un pas de dígit
const float W_LIVES = slotsBlockWidth(scale, spacing);
const float BLOCK_W = W_SCORE + GAP + W_LIVES;
float x = right_align ? (anchor_x - BLOCK_W) : anchor_x;
float x = x_left;
drawScore(text, score, bright, dim, x, TOP_Y, scale, spacing);
x += W_SCORE + GAP;
x += W_SCORE + blockInnerGap(scale, spacing);
drawSlots(renderer, shape, lives, bright, dim, x, center_y, scale, spacing);
}
@@ -219,15 +226,24 @@ namespace Systems::InitHud {
float center_y,
float scale,
float spacing) {
// Els blocs s'ancoren a les verticals del PLAYAREA (sota el marc).
const SDL_FRect& play = Defaults::Zones::PLAYAREA;
const float LEFT = play.x;
const float RIGHT = play.x + play.w;
// Fila centrada amb posicions FIXES: [bloc P1] · [NIVELL] · [bloc P2].
// Els blocs tenen ample constant (slots fixos), així NIVELL queda centrat
// i res es recol·loca en perdre vides. Separadors derivats del glif
// (dos espais), com el disseny original.
const float TOP_Y = center_y - (Graphics::VectorText::getTextHeight(scale) / 2.0F);
const float BLOCK_W = playerBlockWidth(scale, spacing);
const float W_LEVEL = Graphics::VectorText::getTextWidth(data.level_label, scale, spacing) +
Graphics::VectorText::getTextWidth(data.level_value, scale, spacing);
const float GAP = Graphics::VectorText::getTextWidth(" ", scale, spacing);
const float TOTAL = BLOCK_W + GAP + W_LEVEL + GAP + BLOCK_W;
drawPlayerBlock(renderer, text, data.shape_p1, data.score_p1, data.lives_p1, Defaults::Hud::Colors::P1_BRIGHT, Defaults::Hud::Colors::P1_DIM, LEFT, center_y, scale, spacing, false);
drawPlayerBlock(renderer, text, data.shape_p2, data.score_p2, data.lives_p2, Defaults::Hud::Colors::P2_BRIGHT, Defaults::Hud::Colors::P2_DIM, RIGHT, center_y, scale, spacing, true);
float x = (Defaults::Game::WIDTH / 2.0F) - (TOTAL / 2.0F);
drawPlayerBlock(renderer, text, data.shape_p1, data.score_p1, data.lives_p1, Defaults::Hud::Colors::P1_BRIGHT, Defaults::Hud::Colors::P1_DIM, x, center_y, scale, spacing);
x += BLOCK_W + GAP;
// NIVELL: drawLevel centra a WIDTH/2, que coincideix amb aquest tram.
drawLevel(text, data.level_label, data.level_value, TOP_Y, scale, spacing);
x += W_LEVEL + GAP;
drawPlayerBlock(renderer, text, data.shape_p2, data.score_p2, data.lives_p2, Defaults::Hud::Colors::P2_BRIGHT, Defaults::Hud::Colors::P2_DIM, x, center_y, scale, spacing);
}
void drawScoreboardAnimated(Rendering::Renderer* renderer,