From 55b37ba59414665978cd14165c62c91c789cc383 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 29 May 2026 21:00:21 +0200 Subject: [PATCH] =?UTF-8?q?tweak(hud):=20alinea=20verticalment=20els=20slo?= =?UTF-8?q?ts=20de=20vides=20amb=20la=20l=C3=ADnia=20del=20marcador=20(cen?= =?UTF-8?q?tre=20del=20bbox,=20no=20el=20declarat)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game/systems/init_hud_animator.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/source/game/systems/init_hud_animator.cpp b/source/game/systems/init_hud_animator.cpp index b724c5d..01a56f2 100644 --- a/source/game/systems/init_hud_animator.cpp +++ b/source/game/systems/init_hud_animator.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #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& shape) -> float { + float min_y = std::numeric_limits::max(); + float max_y = std::numeric_limits::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(i) * PITCH), .y = center_y}; + const Vec2 POS = {.x = x_left + (SIZE / 2.0F) + (static_cast(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); }