feat(game): pausa graduada amb easing i separador al HUD
This commit is contained in:
1 parent
8aa4ec3daf
commit
5c70019eb5
9 files changed
+258
-61
No files matched your search
+27
-22
@@ -32,9 +32,13 @@ namespace {
|
||||
// ho fa igual amb `writeMonoDigits`).
|
||||
constexpr int MONO_DIGIT_W = 6;
|
||||
|
||||
// Separadors visuals entre etiquetes i valors.
|
||||
constexpr int LABEL_GAP = 2; // px entre "P1" i "000000"
|
||||
constexpr int FIELD_GAP = 6; // px entre "V 3" i "T 00"
|
||||
// Separador que s'enganxa al final de l'etiqueta abans del valor
|
||||
// ("P1 000000", "Vides 3"...). Canviant aquesta cadena aquí es
|
||||
// controla el look-and-feel de totes les línies del HUD.
|
||||
constexpr const char* SEPARATOR = " ";
|
||||
|
||||
// Separació extra entre camps dins d'una mateixa línia.
|
||||
constexpr int FIELD_GAP = 6; // px entre "Vides 3" i "Tres. 00"
|
||||
|
||||
// Format zero-padded a 6 dígits per a la puntuació.
|
||||
auto formatScore(int v) -> std::string {
|
||||
@@ -229,56 +233,57 @@ void Hud::renderIdleSide(int x, int y, int w, const Block& blk, int player_index
|
||||
const auto& p = players_[static_cast<std::size_t>(player_index)];
|
||||
const Uint8 SCORE_C = (blk.flash_ms_left > 0) ? UiConfig::get().hudFlash() : UiConfig::get().hudValue();
|
||||
|
||||
// --- Línia 1: "<label> 000000" centrada ---
|
||||
// --- Línia 1: "<label>-000000" centrada ---
|
||||
const std::string LBL1 = label + SEPARATOR;
|
||||
const std::string SCORE = formatScore(p.score);
|
||||
const int LBL_W = font_->length(label);
|
||||
const int LBL_W = font_->length(LBL1);
|
||||
const int SC_W = font_->lengthMonoDigits(SCORE, MONO_DIGIT_W);
|
||||
const int LINE1_W = LBL_W + LABEL_GAP + SC_W;
|
||||
const int LINE1_W = LBL_W + SC_W;
|
||||
int xx = x + ((w - LINE1_W) / 2);
|
||||
font_->writeColored(xx, y + LINE1_Y, label, UiConfig::get().hudLabel());
|
||||
xx += LBL_W + LABEL_GAP;
|
||||
font_->writeColored(xx, y + LINE1_Y, LBL1, UiConfig::get().hudLabel());
|
||||
xx += LBL_W;
|
||||
font_->writeMonoDigits(xx, y + LINE1_Y, SCORE, SCORE_C, MONO_DIGIT_W);
|
||||
|
||||
// --- Línia 2: "<vides> <n> <tresors> <n>" centrada ---
|
||||
const std::string V_LBL = Locale::get().text("hud.lives");
|
||||
const std::string T_LBL = Locale::get().text("hud.treasures");
|
||||
// --- Línia 2: "<vides>-<n> <tresors>-<n>" centrada ---
|
||||
const std::string V_LBL = Locale::get().text("hud.lives") + SEPARATOR;
|
||||
const std::string T_LBL = Locale::get().text("hud.treasures") + SEPARATOR;
|
||||
const std::string V_VAL = std::to_string(std::clamp(p.lives, 0, 9));
|
||||
const std::string T_VAL = formatTwoDigits(p.treasures);
|
||||
const int V_LW = font_->length(V_LBL);
|
||||
const int V_VW = font_->lengthMonoDigits(V_VAL, MONO_DIGIT_W);
|
||||
const int T_LW = font_->length(T_LBL);
|
||||
const int T_VW = font_->lengthMonoDigits(T_VAL, MONO_DIGIT_W);
|
||||
const int LINE2_W = V_LW + LABEL_GAP + V_VW + FIELD_GAP + T_LW + LABEL_GAP + T_VW;
|
||||
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());
|
||||
xx += V_LW + LABEL_GAP;
|
||||
xx += V_LW;
|
||||
font_->writeMonoDigits(xx, y + LINE2_Y, V_VAL, UiConfig::get().hudValue(), MONO_DIGIT_W);
|
||||
xx += V_VW + FIELD_GAP;
|
||||
font_->writeColored(xx, y + LINE2_Y, T_LBL, UiConfig::get().hudLabel());
|
||||
xx += T_LW + LABEL_GAP;
|
||||
xx += T_LW;
|
||||
font_->writeMonoDigits(xx, y + LINE2_Y, T_VAL, UiConfig::get().hudValue(), MONO_DIGIT_W);
|
||||
}
|
||||
|
||||
void Hud::renderIdleCenter(int x, int y, int w) const {
|
||||
// --- Línia 1: "<piramide> <n>" centrada ---
|
||||
const std::string PIR_LBL = Locale::get().text("hud.pyramid");
|
||||
// --- 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_);
|
||||
const int PL_W = font_->length(PIR_LBL);
|
||||
const int PV_W = font_->lengthMonoDigits(PIR_VAL, MONO_DIGIT_W);
|
||||
const int LINE1_W = PL_W + LABEL_GAP + PV_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());
|
||||
xx += PL_W + LABEL_GAP;
|
||||
xx += PL_W;
|
||||
font_->writeMonoDigits(xx, y + LINE1_Y, PIR_VAL, UiConfig::get().hudValue(), MONO_DIGIT_W);
|
||||
|
||||
// --- Línia 2: "<sala> <r>" centrada ---
|
||||
const std::string SALA_LBL = Locale::get().text("hud.room");
|
||||
// --- Línia 2: "<sala>-<r>" centrada ---
|
||||
const std::string SALA_LBL = Locale::get().text("hud.room") + SEPARATOR;
|
||||
const std::string SALA_VAL = std::to_string(room_);
|
||||
const int SL_W = font_->length(SALA_LBL);
|
||||
const int SV_W = font_->lengthMonoDigits(SALA_VAL, MONO_DIGIT_W);
|
||||
const int LINE2_W = SL_W + LABEL_GAP + SV_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());
|
||||
xx += SL_W + LABEL_GAP;
|
||||
xx += SL_W;
|
||||
font_->writeMonoDigits(xx, y + LINE2_Y, SALA_VAL, UiConfig::get().hudValue(), MONO_DIGIT_W);
|
||||
}
|
||||
Reference in new issue
Block a user