fixed statistics panel

This commit is contained in:
2025-12-07 10:29:20 +01:00
parent 262ae49496
commit 59dc3a1638
2 changed files with 78 additions and 37 deletions

View File

@ -237,10 +237,22 @@ void GameRenderer::renderPlayingState(
drawRectWithOffset(gridX - 1 - contentOffsetX, gridY - 1 - contentOffsetY, GRID_W + 2, GRID_H + 2, {60, 80, 160, 255});
drawRectWithOffset(gridX - contentOffsetX, gridY - contentOffsetY, GRID_W, GRID_H, {20, 25, 35, 255});
// Draw panel backgrounds
SDL_SetRenderDrawColor(renderer, 10, 15, 25, 160);
SDL_FRect lbg{statsX - 16, gridY - 10, statsW + 32, GRID_H + 20};
SDL_RenderFillRect(renderer, &lbg);
// Draw stats panel backdrop using the same art as the score panel
const float blocksPanelPadLeft = 34.0f;
const float blocksPanelPadRight = 10.0f;
const float blocksPanelPadY = 26.0f;
SDL_FRect blocksPanelBg{
statsX - blocksPanelPadLeft,
gridY - blocksPanelPadY,
statsW + blocksPanelPadLeft + blocksPanelPadRight,
GRID_H + blocksPanelPadY * 2.0f
};
if (scorePanelTex) {
SDL_RenderTexture(renderer, scorePanelTex, nullptr, &blocksPanelBg);
} else {
SDL_SetRenderDrawColor(renderer, 12, 18, 32, 205);
SDL_RenderFillRect(renderer, &blocksPanelBg);
}
// Draw grid lines
SDL_SetRenderDrawColor(renderer, 40, 45, 60, 255);
@ -302,10 +314,6 @@ void GameRenderer::renderPlayingState(
s_inGridStarfield.draw(renderer, gridX, gridY, 0.22f, true);
SDL_SetRenderDrawBlendMode(renderer, oldBlend);
// Draw block statistics panel border
drawRectWithOffset(statsX - 3 - contentOffsetX, statsY - 3 - contentOffsetY, statsW + 6, statsH + 6, {100, 120, 200, 255});
drawRectWithOffset(statsX - contentOffsetX, statsY - contentOffsetY, statsW, statsH, {30, 35, 50, 255});
// Draw next piece preview panel border
drawRectWithOffset(nextX - 3 - contentOffsetX, nextY - 3 - contentOffsetY, nextW + 6, nextH + 6, {100, 120, 200, 255});
drawRectWithOffset(nextX - contentOffsetX, nextY - contentOffsetY, nextW, nextH, {30, 35, 50, 255});
@ -565,24 +573,23 @@ void GameRenderer::renderPlayingState(
}
// Draw block statistics (left panel)
pixelFont->draw(renderer, statsX + 10, statsY + 10, "BLOCKS", 1.0f, {255, 220, 0, 255});
const auto& blockCounts = game->getBlockCounts();
int totalBlocks = 0;
for (int i = 0; i < PIECE_COUNT; ++i) totalBlocks += blockCounts[i];
const float rowPadding = 18.0f;
const float rowPadding = 34.0f;
const float rowWidth = statsW - rowPadding * 2.0f;
const float rowSpacing = 12.0f;
float yCursor = statsY + 44.0f;
const float rowSpacing = 18.0f;
float yCursor = statsY + 34.0f;
for (int i = 0; i < PIECE_COUNT; ++i) {
float rowTop = yCursor;
float previewSize = finalBlockSize * 0.52f;
float previewX = statsX + rowPadding;
float previewY = rowTop - 14.0f;
float rowLeft = statsX + rowPadding;
float rowRight = rowLeft + rowWidth;
float previewSize = finalBlockSize * 0.5f;
float previewX = rowLeft;
float previewY = rowTop - 10.0f;
// Determine actual preview height to keep bars below the blocks
Game::Piece previewPiece{};
previewPiece.type = static_cast<PieceType>(i);
int maxCy = -1;
@ -600,36 +607,35 @@ void GameRenderer::renderPlayingState(
snprintf(countStr, sizeof(countStr), "%d", count);
int countW = 0, countH = 0;
pixelFont->measure(countStr, 1.0f, countW, countH);
float countX = previewX + rowWidth - static_cast<float>(countW);
float countY = previewY + 9.0f;
float countX = rowRight - static_cast<float>(countW);
float countY = previewY + 4.0f;
int perc = (totalBlocks > 0) ? int(std::round(100.0 * double(count) / double(totalBlocks))) : 0;
char percStr[16];
snprintf(percStr, sizeof(percStr), "%d%%", perc);
float barX = previewX;
float barY = previewY + pieceHeight + 12.0f;
float barH = 6.0f;
float barW = rowWidth;
float percY = barY + barH + 8.0f;
float barX = rowLeft + previewSize + 36.0f;
float barY = previewY + pieceHeight + 10.0f;
float barH = 7.0f;
float barW = std::max(0.0f, rowRight - barX);
float percY = barY + barH + 6.0f;
float rowBottom = percY + 16.0f;
float rowBottom = percY + 18.0f;
SDL_FRect rowBg{
previewX - 12.0f,
rowLeft - 18.0f,
rowTop - 14.0f,
rowWidth + 24.0f,
rowWidth + 36.0f,
rowBottom - (rowTop - 14.0f)
};
SDL_SetRenderDrawColor(renderer, 18, 26, 40, 200);
SDL_SetRenderDrawColor(renderer, 6, 12, 26, 205);
SDL_RenderFillRect(renderer, &rowBg);
SDL_SetRenderDrawColor(renderer, 70, 100, 150, 210);
SDL_SetRenderDrawColor(renderer, 30, 60, 110, 220);
SDL_RenderRect(renderer, &rowBg);
drawSmallPiece(renderer, blocksTex, static_cast<PieceType>(i), previewX, previewY, previewSize);
pixelFont->draw(renderer, countX, countY, countStr, 1.0f, {245, 245, 255, 255});
pixelFont->draw(renderer, previewX, percY, percStr, 0.8f, {215, 225, 240, 255});
SDL_SetRenderDrawColor(renderer, 110, 120, 140, 200);
SDL_SetRenderDrawColor(renderer, 32, 44, 70, 210);
SDL_FRect track{barX, barY, barW, barH};
SDL_RenderFillRect(renderer, &track);
SDL_Color pc = COLORS[i + 1];
@ -638,6 +644,11 @@ void GameRenderer::renderPlayingState(
fillW = std::clamp(fillW, 0.0f, barW);
SDL_FRect fill{barX, barY, fillW, barH};
SDL_RenderFillRect(renderer, &fill);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 45);
SDL_FRect fillHighlight{barX, barY, fillW, barH * 0.35f};
SDL_RenderFillRect(renderer, &fillHighlight);
pixelFont->draw(renderer, barX, percY, percStr, 0.78f, {185, 205, 230, 255});
yCursor = rowBottom + rowSpacing;
}