Added hold block and minor fixes

This commit is contained in:
2025-12-20 11:10:23 +01:00
parent 38dbc17ace
commit a520de6c1f
20 changed files with 467 additions and 50 deletions

View File

@ -518,6 +518,7 @@ void GameRenderer::renderPlayingState(
SDL_Texture* statisticsPanelTex,
SDL_Texture* scorePanelTex,
SDL_Texture* nextPanelTex,
SDL_Texture* holdPanelTex,
float logicalW,
float logicalH,
float logicalScale,
@ -1403,30 +1404,49 @@ void GameRenderer::renderPlayingState(
pixelFont->draw(renderer, logicalW - 260, 10, gravityHud, 0.9f, {200, 200, 220, 255});
}
// Hold piece (right side, above score dashboard)
if (game->held().type < PIECE_COUNT) {
// Hold panel background & label (always visible). Small preview renders only if a piece is held.
{
float holdLabelX = statsTextX;
float holdY = statsY + statsH - 80.0f;
float holdBlockH = (finalBlockSize * 0.6f) * 6.0f;
const float holdGap = 18.0f;
float panelW = 120.0f;
float panelH = holdBlockH + 12.0f;
float panelX = holdLabelX + 40.0f;
float panelY = holdY - 6.0f;
if (scorePanelMetricsValid) {
const float holdGap = 18.0f;
const float holdBlockH = (finalBlockSize * 0.6f) * 4.0f;
holdY = scorePanelTop - holdBlockH - holdGap;
holdLabelX = statsTextX;
// Ensure HOLD block doesn't drift too far left if the score panel gets narrow.
holdLabelX = std::max(holdLabelX, scorePanelLeftX + 14.0f);
// If the score panel is extremely narrow, keep within its bounds.
holdLabelX = std::min(holdLabelX, scorePanelLeftX + std::max(0.0f, scorePanelWidth - 90.0f));
// align panel to score panel width and position it above it
panelW = scorePanelWidth;
panelX = scorePanelLeftX;
panelY = scorePanelTop - panelH - holdGap;
// choose label X (left edge + padding)
holdLabelX = panelX + 10.0f;
// label Y inside panel
holdY = panelY + 8.0f;
}
pixelFont->draw(renderer, holdLabelX, holdY, "HOLD", 1.0f, {255, 220, 0, 255});
drawSmallPiece(
renderer,
blocksTex,
static_cast<PieceType>(game->held().type),
holdLabelX + 50.0f,
holdY + 2.0f,
finalBlockSize * 0.6f
);
if (holdPanelTex) {
SDL_FRect panelDst{panelX, panelY, panelW, panelH};
SDL_SetTextureBlendMode(holdPanelTex, SDL_BLENDMODE_BLEND);
SDL_SetTextureScaleMode(holdPanelTex, SDL_SCALEMODE_LINEAR);
SDL_RenderTexture(renderer, holdPanelTex, nullptr, &panelDst);
} else {
// fallback: draw a dark panel rect so UI is visible even without texture
SDL_SetRenderDrawColor(renderer, 12, 18, 32, 220);
SDL_FRect panelDst{panelX, panelY, panelW, panelH};
SDL_RenderFillRect(renderer, &panelDst);
}
// Display "HOLD" label on right side
pixelFont->draw(renderer, holdLabelX + 56.0f, holdY + 4.0f, "HOLD", 1.0f, {255, 220, 0, 255});
if (game->held().type < PIECE_COUNT) {
// Draw small held preview inside the panel (centered)
float previewX = panelX + (panelW - (finalBlockSize * 0.6f * 4.0f)) * 0.5f;
float previewY = panelY + (panelH - holdBlockH) * 2.5f;
drawSmallPiece(renderer, blocksTex, static_cast<PieceType>(game->held().type), previewX, previewY, finalBlockSize * 0.6f);
}
}
// Pause overlay logic moved to renderPauseOverlay

View File

@ -24,6 +24,7 @@ public:
SDL_Texture* statisticsPanelTex,
SDL_Texture* scorePanelTex,
SDL_Texture* nextPanelTex,
SDL_Texture* holdPanelTex,
float logicalW,
float logicalH,
float logicalScale,