tweak(hud): alinea verticalment els slots de vides amb la línia del marcador (centre del bbox, no el declarat)

This commit is contained in:
2026-05-29 21:00:21 +02:00
parent 20825c8138
commit 55b37ba594
+20 -1
View File
@@ -5,6 +5,7 @@
#include <SDL3/SDL.h>
#include <algorithm>
#include <limits>
#include <string>
#include "core/defaults.hpp"
@@ -92,6 +93,22 @@ namespace Systems::InitHud {
Graphics::VectorText::getTextWidth("0", scale, spacing);
}
// Desplaçament vertical (unitats locals) entre el center declarat de la
// shape i el centre real del seu bbox. La nau té center (0,0) però el seu
// bbox no hi està centrat; cal per alinear el centre VISUAL de la nau amb
// la línia del marcador (els dígits sí tenen el center al mig del glif).
auto shapeVerticalOffset(const std::shared_ptr<Graphics::Shape>& shape) -> float {
float min_y = std::numeric_limits<float>::max();
float max_y = std::numeric_limits<float>::lowest();
for (const auto& prim : shape->getPrimitives()) {
for (const auto& point : prim.points) {
min_y = std::min(min_y, point.y);
max_y = std::max(max_y, point.y);
}
}
return ((min_y + max_y) / 2.0F) - shape->getCenter().y;
}
// Mida d'un slot = alçada real del glif del dígit (no la cel·la, que té
// marge vertical: usar la cel·la feia les naus el doble de grans), amb un
// xicotet factor d'ajust perquè la silueta de la nau case amb les xifres.
@@ -129,10 +146,12 @@ namespace Systems::InitHud {
// slot (mida predictible independent del .shp).
const float RADIUS = shape->getBoundingRadius();
const float ICON_SCALE = (RADIUS > 0.001F) ? (SIZE / (2.0F * RADIUS)) : 1.0F;
// Alinea el centre visual de la nau amb la línia del marcador.
const float OFFSET_Y = shapeVerticalOffset(shape) * ICON_SCALE;
const int FILLED = std::clamp(lives - 1, 0, NUM_SLOTS);
for (int i = 0; i < NUM_SLOTS; i++) {
const SDL_Color COLOR = (i < FILLED) ? bright : dim;
const Vec2 POS = {.x = x_left + (SIZE / 2.0F) + (static_cast<float>(i) * PITCH), .y = center_y};
const Vec2 POS = {.x = x_left + (SIZE / 2.0F) + (static_cast<float>(i) * PITCH), .y = center_y - OFFSET_Y};
// glow=false: el marcador es manté net, com els dígits del text.
Rendering::renderShape(renderer, shape, POS, 0.0F, ICON_SCALE, 1.0F, 1.0F, COLOR, 0.0F, 1.0F, false);
}