fixed highscore

This commit is contained in:
2025-12-06 14:54:56 +01:00
parent b531bbc798
commit 26b4454eea

View File

@ -563,58 +563,110 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi
float eased = combinedTransition * combinedTransition * (3.0f - 2.0f * combinedTransition); // cubic smoothstep float eased = combinedTransition * combinedTransition * (3.0f - 2.0f * combinedTransition); // cubic smoothstep
float panelDelta = eased * moveAmount; float panelDelta = eased * moveAmount;
float topPlayersY = LOGICAL_H * 0.24f + contentOffsetY - panelDelta; // Draw a larger centered logo above the highscores area, then a small "TOP PLAYER" label
// Move logo a bit lower for better spacing
float topPlayersY = LOGICAL_H * 0.20f + contentOffsetY - panelDelta;
float scoresStartY = topPlayersY;
if (useFont) { if (useFont) {
const std::string title = "TOP PLAYERS"; // Preferred logo texture (full) if present, otherwise the small logo
int tW = 0, tH = 0; SDL_Texture* logoTex = ctx.logoTex ? ctx.logoTex : ctx.logoSmallTex;
useFont->measure(title, 1.8f, tW, tH); float logoDrawH = 72.0f; // larger logo height
float titleX = (LOGICAL_W - (float)tW) * 0.5f + contentOffsetX; if (logoTex) {
useFont->draw(renderer, titleX, topPlayersY, title, 1.8f, SDL_Color{255, 220, 0, 255}); float texW = 0.0f, texH = 0.0f;
SDL_GetTextureSize(logoTex, &texW, &texH);
if (texW > 0.0f && texH > 0.0f) {
float scale = logoDrawH / texH;
float drawW = texW * scale;
SDL_FRect dst{ (LOGICAL_W - drawW) * 0.5f + contentOffsetX, topPlayersY, drawW, logoDrawH };
SDL_SetTextureAlphaMod(logoTex, 230);
SDL_RenderTexture(renderer, logoTex, nullptr, &dst);
// move down for title under logo
scoresStartY = dst.y + dst.h + 8.0f;
}
} }
float scoresStartY = topPlayersY + 70.0f; // Small TOP PLAYER label under the logo
const std::string smallTitle = "TOP PLAYER";
float titleScale = 0.9f;
int tW = 0, tH = 0;
useFont->measure(smallTitle, titleScale, tW, tH);
float titleX = (LOGICAL_W - (float)tW) * 0.5f + contentOffsetX;
useFont->draw(renderer, titleX, scoresStartY, smallTitle, titleScale, SDL_Color{200,220,230,200});
scoresStartY += (float)tH + 12.0f;
}
static const std::vector<ScoreEntry> EMPTY_SCORES; static const std::vector<ScoreEntry> EMPTY_SCORES;
const auto& hs = ctx.scores ? ctx.scores->all() : EMPTY_SCORES; const auto& hs = ctx.scores ? ctx.scores->all() : EMPTY_SCORES;
size_t maxDisplay = std::min(hs.size(), size_t(12)); size_t maxDisplay = std::min(hs.size(), size_t(10)); // display only top 10
// Draw highscores as an inline HUD-like panel (no opaque box), matching Options/Level/Exit style
if (useFont) { if (useFont) {
float cx = LOGICAL_W * 0.5f + contentOffsetX; const float panelW = std::min(780.0f, LOGICAL_W * 0.85f);
float colX[] = { cx - 280, cx - 180, cx - 20, cx + 90, cx + 200, cx + 300 }; const float panelH = 36.0f + maxDisplay * 36.0f; // header + rows
useFont->draw(renderer, colX[0], scoresStartY - 28, "RANK", 1.1f, SDL_Color{200,200,220,255}); float panelBaseX = (LOGICAL_W - panelW) * 0.5f + contentOffsetX;
useFont->draw(renderer, colX[1], scoresStartY - 28, "PLAYER", 1.1f, SDL_Color{200,200,220,255}); float panelBaseY = scoresStartY - 20.0f - panelDelta; // nudge up and apply HUD slide
useFont->draw(renderer, colX[2], scoresStartY - 28, "SCORE", 1.1f, SDL_Color{200,200,220,255});
useFont->draw(renderer, colX[3], scoresStartY - 28, "LINES", 1.1f, SDL_Color{200,200,220,255}); // Column positions inside panel
useFont->draw(renderer, colX[4], scoresStartY - 28, "LEVEL", 1.1f, SDL_Color{200,200,220,255}); float colLeft = panelBaseX + 12.0f;
useFont->draw(renderer, colX[5], scoresStartY - 28, "TIME", 1.1f, SDL_Color{200,200,220,255}); float colWidth = panelW - 24.0f;
// Center the column group inside the panel and place columns relative to center
float centerX = panelBaseX + panelW * 0.5f;
// Tighter column spacing: compress multipliers around center
float rankX = centerX - colWidth * 0.34f;
// Move PLAYER column a bit further left while leaving others unchanged
float nameX = centerX - colWidth * 0.25f;
float scoreX = centerX + colWidth * 0.00f;
float linesX = centerX + colWidth * 0.14f;
float levelX = centerX + colWidth * 0.26f;
float timeX = centerX + colWidth * 0.38f;
// Column header labels
float headerY = panelBaseY + 26.0f;
// Slightly smaller header for compactness
float headerScale = 0.75f;
// Use same color as Options heading
SDL_Color headerColor = SDL_Color{120,220,255,220};
useFont->draw(renderer, rankX, headerY, "#", headerScale, headerColor);
useFont->draw(renderer, nameX, headerY, "PLAYER", headerScale, headerColor);
useFont->draw(renderer, scoreX, headerY, "SCORE", headerScale, headerColor);
useFont->draw(renderer, linesX, headerY, "LINES", headerScale, headerColor);
useFont->draw(renderer, levelX, headerY, "LVL", headerScale, headerColor);
useFont->draw(renderer, timeX, headerY, "TIME", headerScale, headerColor);
const float rowHeight = 28.0f;
float rowY = panelBaseY + 48.0f;
float rowScale = 0.80f;
for (size_t i = 0; i < maxDisplay; ++i) { for (size_t i = 0; i < maxDisplay; ++i) {
float baseY = scoresStartY + i * 25.0f - panelDelta; float y = rowY + i * rowHeight;
float wave = std::sin((float)GlobalState::instance().logoAnimCounter * 0.006f + i * 0.25f) * 6.0f;
float y = baseY + wave;
char rankStr[8]; // (removed thin blue separator between rows per request)
std::snprintf(rankStr, sizeof(rankStr), "%zu.", i + 1);
useFont->draw(renderer, colX[0], y, rankStr, 1.0f, SDL_Color{220, 220, 230, 255});
useFont->draw(renderer, colX[1], y, hs[i].name, 1.0f, SDL_Color{220, 220, 230, 255}); // Subtle highlight wave for the list similar to before
float wave = std::sin((float)GlobalState::instance().logoAnimCounter * 0.006f + i * 0.25f) * 4.0f;
char scoreStr[16]; // Slightly reduced font for rows to fit more cleanly
std::snprintf(scoreStr, sizeof(scoreStr), "%d", hs[i].score); if (i < 5) {
useFont->draw(renderer, colX[2], y, scoreStr, 1.0f, SDL_Color{220, 220, 230, 255}); rowScale -= 0.05f;
}
SDL_Color rowColor = SDL_Color{120,220,255,220};
char linesStr[8]; char rankStr[8]; std::snprintf(rankStr, sizeof(rankStr), "%zu.", i + 1);
std::snprintf(linesStr, sizeof(linesStr), "%d", hs[i].lines); useFont->draw(renderer, rankX, y + wave, rankStr, rowScale, rowColor);
useFont->draw(renderer, colX[3], y, linesStr, 1.0f, SDL_Color{220, 220, 230, 255});
char levelStr[8]; useFont->draw(renderer, nameX, y + wave, hs[i].name, rowScale, rowColor);
std::snprintf(levelStr, sizeof(levelStr), "%d", hs[i].level);
useFont->draw(renderer, colX[4], y, levelStr, 1.0f, SDL_Color{220, 220, 230, 255});
char timeStr[16]; char scoreStr[16]; std::snprintf(scoreStr, sizeof(scoreStr), "%d", hs[i].score);
int mins = int(hs[i].timeSec) / 60; useFont->draw(renderer, scoreX, y + wave, scoreStr, rowScale, rowColor);
int secs = int(hs[i].timeSec) % 60;
char linesStr[8]; std::snprintf(linesStr, sizeof(linesStr), "%d", hs[i].lines);
useFont->draw(renderer, linesX, y + wave, linesStr, rowScale, rowColor);
char levelStr[8]; std::snprintf(levelStr, sizeof(levelStr), "%d", hs[i].level);
useFont->draw(renderer, levelX, y + wave, levelStr, rowScale, rowColor);
char timeStr[16]; int mins = int(hs[i].timeSec) / 60; int secs = int(hs[i].timeSec) % 60;
std::snprintf(timeStr, sizeof(timeStr), "%d:%02d", mins, secs); std::snprintf(timeStr, sizeof(timeStr), "%d:%02d", mins, secs);
useFont->draw(renderer, colX[5], y, timeStr, 1.0f, SDL_Color{220, 220, 230, 255}); useFont->draw(renderer, timeX, y + wave, timeStr, rowScale, rowColor);
} }
} }