feat(hud): famílies de color per bloc + ombra del text
This commit is contained in:
1 parent
932d195eb0
commit
629baaaec3
6 files changed
+131
-33
No files matched your search
+47
-13
@@ -40,6 +40,25 @@ namespace {
|
||||
// Separació extra entre camps dins d'una mateixa línia.
|
||||
constexpr int FIELD_GAP = 6; // px entre "Vides 3" i "Tres. 00"
|
||||
|
||||
// Desplaçament de l'ombra del text en píxels (sota-dreta). Petit
|
||||
// perquè la font del HUD és 8 px d'alçada — qualsevol valor més
|
||||
// gran tapa el següent caràcter.
|
||||
constexpr int SHADOW_DX = 1;
|
||||
constexpr int SHADOW_DY = 1;
|
||||
|
||||
// Helpers per pintar text amb ombra. Primer la sombra desplaçada,
|
||||
// després el text principal al damunt — l'ordre garanteix que la
|
||||
// sombra mai cobreix el text. El kerning queda al default del
|
||||
// Text (1 px), igual que la resta del HUD.
|
||||
void drawShadowed(Text& font, int x, int y, const std::string& s, Uint8 color, Uint8 shadow) {
|
||||
font.writeColored(x + SHADOW_DX, y + SHADOW_DY, s, shadow);
|
||||
font.writeColored(x, y, s, color);
|
||||
}
|
||||
void drawMonoShadowed(Text& font, int x, int y, const std::string& s, Uint8 color, Uint8 shadow, int cell_w) {
|
||||
font.writeMonoDigits(x + SHADOW_DX, y + SHADOW_DY, s, shadow, cell_w);
|
||||
font.writeMonoDigits(x, y, s, color, cell_w);
|
||||
}
|
||||
|
||||
// Format zero-padded a 6 dígits per a la puntuació.
|
||||
auto formatScore(int v) -> std::string {
|
||||
const int CLAMPED = std::clamp(v, 0, 999999);
|
||||
@@ -261,6 +280,16 @@ void Hud::renderBlock(BlockId id) const {
|
||||
void Hud::renderIdleSide(int x, int y, int w, const Block& blk, int player_index, const std::string& label) const {
|
||||
const auto& p = players_[static_cast<std::size_t>(player_index)];
|
||||
|
||||
// Família de color del bloc: P1 (vermell-crema-vermell-fosc) per al
|
||||
// jugador 0, P2 (cian-blau-blau-marí) per al jugador 1. Mantenir el
|
||||
// mateix matís a label/value/shadow dóna jerarquia visual coherent
|
||||
// entre línies sense empastar (la sombra és un to fosc del mateix
|
||||
// matís → efecte embossing).
|
||||
const auto& ui = UiConfig::get();
|
||||
const Uint8 LBL_C = (player_index == 0) ? ui.hudP1Label() : ui.hudP2Label();
|
||||
const Uint8 VAL_C = (player_index == 0) ? ui.hudP1Value() : ui.hudP2Value();
|
||||
const Uint8 SHD_C = (player_index == 0) ? ui.hudP1Shadow() : ui.hudP2Shadow();
|
||||
|
||||
// Slot inactiu amb prompt actiu: substituïm el render de zeros pel
|
||||
// missatge "PULSA START / PARA JUGAR" o "ESPERA / PARA JUGAR" segons
|
||||
// el mode fixat per la GameScene cada frame. El render de zeros
|
||||
@@ -275,12 +304,12 @@ void Hud::renderIdleSide(int x, int y, int w, const Block& blk, int player_index
|
||||
const int L2_W = font_->length(L2);
|
||||
const int X1 = x + ((w - L1_W) / 2);
|
||||
const int X2 = x + ((w - L2_W) / 2);
|
||||
font_->writeColored(X1, y + LINE1_Y, L1, UiConfig::get().hudLabel());
|
||||
font_->writeColored(X2, y + LINE2_Y, L2, UiConfig::get().hudValue());
|
||||
drawShadowed(*font_, X1, y + LINE1_Y, L1, LBL_C, SHD_C);
|
||||
drawShadowed(*font_, X2, y + LINE2_Y, L2, VAL_C, SHD_C);
|
||||
return;
|
||||
}
|
||||
|
||||
const Uint8 SCORE_C = (blk.flash_ms_left > 0) ? UiConfig::get().hudFlash() : UiConfig::get().hudValue();
|
||||
const Uint8 SCORE_C = (blk.flash_ms_left > 0) ? ui.hudFlash() : VAL_C;
|
||||
|
||||
// --- Línia 1: "<label>-000000" centrada ---
|
||||
const std::string LBL1 = label + SEPARATOR;
|
||||
@@ -289,9 +318,9 @@ void Hud::renderIdleSide(int x, int y, int w, const Block& blk, int player_index
|
||||
const int SC_W = font_->lengthMonoDigits(SCORE, MONO_DIGIT_W);
|
||||
const int LINE1_W = LBL_W + SC_W;
|
||||
int xx = x + ((w - LINE1_W) / 2);
|
||||
font_->writeColored(xx, y + LINE1_Y, LBL1, UiConfig::get().hudLabel());
|
||||
drawShadowed(*font_, xx, y + LINE1_Y, LBL1, LBL_C, SHD_C);
|
||||
xx += LBL_W;
|
||||
font_->writeMonoDigits(xx, y + LINE1_Y, SCORE, SCORE_C, MONO_DIGIT_W);
|
||||
drawMonoShadowed(*font_, xx, y + LINE1_Y, SCORE, SCORE_C, SHD_C, MONO_DIGIT_W);
|
||||
|
||||
// --- Línia 2: "<vides>-<n> <tresors>-<n>" centrada ---
|
||||
const std::string V_LBL = Locale::get().text("hud.lives") + SEPARATOR;
|
||||
@@ -304,16 +333,21 @@ void Hud::renderIdleSide(int x, int y, int w, const Block& blk, int player_index
|
||||
const int T_VW = font_->lengthMonoDigits(T_VAL, MONO_DIGIT_W);
|
||||
const int LINE2_W = V_LW + V_VW + FIELD_GAP + T_LW + T_VW;
|
||||
xx = x + ((w - LINE2_W) / 2);
|
||||
font_->writeColored(xx, y + LINE2_Y, V_LBL, UiConfig::get().hudLabel());
|
||||
drawShadowed(*font_, xx, y + LINE2_Y, V_LBL, LBL_C, SHD_C);
|
||||
xx += V_LW;
|
||||
font_->writeMonoDigits(xx, y + LINE2_Y, V_VAL, UiConfig::get().hudValue(), MONO_DIGIT_W);
|
||||
drawMonoShadowed(*font_, xx, y + LINE2_Y, V_VAL, VAL_C, SHD_C, MONO_DIGIT_W);
|
||||
xx += V_VW + FIELD_GAP;
|
||||
font_->writeColored(xx, y + LINE2_Y, T_LBL, UiConfig::get().hudLabel());
|
||||
drawShadowed(*font_, xx, y + LINE2_Y, T_LBL, LBL_C, SHD_C);
|
||||
xx += T_LW;
|
||||
font_->writeMonoDigits(xx, y + LINE2_Y, T_VAL, UiConfig::get().hudValue(), MONO_DIGIT_W);
|
||||
drawMonoShadowed(*font_, xx, y + LINE2_Y, T_VAL, VAL_C, SHD_C, MONO_DIGIT_W);
|
||||
}
|
||||
|
||||
void Hud::renderIdleCenter(int x, int y, int w) const {
|
||||
const auto& ui = UiConfig::get();
|
||||
const Uint8 LBL_C = ui.hudCenterLabel();
|
||||
const Uint8 VAL_C = ui.hudCenterValue();
|
||||
const Uint8 SHD_C = ui.hudCenterShadow();
|
||||
|
||||
// --- Línia 1: "<piramide>-<n>" centrada ---
|
||||
const std::string PIR_LBL = Locale::get().text("hud.pyramid") + SEPARATOR;
|
||||
const std::string PIR_VAL = std::to_string(pyramid_);
|
||||
@@ -321,9 +355,9 @@ void Hud::renderIdleCenter(int x, int y, int w) const {
|
||||
const int PV_W = font_->lengthMonoDigits(PIR_VAL, MONO_DIGIT_W);
|
||||
const int LINE1_W = PL_W + PV_W;
|
||||
int xx = x + ((w - LINE1_W) / 2);
|
||||
font_->writeColored(xx, y + LINE1_Y, PIR_LBL, UiConfig::get().hudLabel());
|
||||
drawShadowed(*font_, xx, y + LINE1_Y, PIR_LBL, LBL_C, SHD_C);
|
||||
xx += PL_W;
|
||||
font_->writeMonoDigits(xx, y + LINE1_Y, PIR_VAL, UiConfig::get().hudValue(), MONO_DIGIT_W);
|
||||
drawMonoShadowed(*font_, xx, y + LINE1_Y, PIR_VAL, VAL_C, SHD_C, MONO_DIGIT_W);
|
||||
|
||||
// --- Línia 2: "<sala>-<r>" centrada ---
|
||||
const std::string SALA_LBL = Locale::get().text("hud.room") + SEPARATOR;
|
||||
@@ -332,7 +366,7 @@ void Hud::renderIdleCenter(int x, int y, int w) const {
|
||||
const int SV_W = font_->lengthMonoDigits(SALA_VAL, MONO_DIGIT_W);
|
||||
const int LINE2_W = SL_W + SV_W;
|
||||
xx = x + ((w - LINE2_W) / 2);
|
||||
font_->writeColored(xx, y + LINE2_Y, SALA_LBL, UiConfig::get().hudLabel());
|
||||
drawShadowed(*font_, xx, y + LINE2_Y, SALA_LBL, LBL_C, SHD_C);
|
||||
xx += SL_W;
|
||||
font_->writeMonoDigits(xx, y + LINE2_Y, SALA_VAL, UiConfig::get().hudValue(), MONO_DIGIT_W);
|
||||
drawMonoShadowed(*font_, xx, y + LINE2_Y, SALA_VAL, VAL_C, SHD_C, MONO_DIGIT_W);
|
||||
}
|
||||
Reference in new issue
Block a user