Added hold block and minor fixes
This commit is contained in:
@ -125,6 +125,7 @@ void GameRenderer::renderPlayingState(
|
||||
SDL_Texture* statisticsPanelTex,
|
||||
SDL_Texture* scorePanelTex,
|
||||
SDL_Texture* nextPanelTex,
|
||||
SDL_Texture* holdPanelTex,
|
||||
float logicalW,
|
||||
float logicalH,
|
||||
float logicalScale,
|
||||
@ -466,10 +467,76 @@ void GameRenderer::renderPlayingState(
|
||||
snprintf(gms, sizeof(gms), "GRAV: %.0f ms (%.2f fps)", gms_val, gfps);
|
||||
pixelFont->draw(renderer, logicalW - 260, 10, gms, 0.9f, {200, 200, 220, 255});
|
||||
|
||||
// Hold piece (if implemented)
|
||||
if (game->held().type < PIECE_COUNT) {
|
||||
pixelFont->draw(renderer, statsX + 10, statsY + statsH - 80, "HOLD", 1.0f, {255, 220, 0, 255});
|
||||
drawSmallPiece(renderer, blocksTex, static_cast<PieceType>(game->held().type), statsX + 60, statsY + statsH - 80, finalBlockSize * 0.6f);
|
||||
// Hold panel (always visible): draw background & label; preview shown only when a piece is held.
|
||||
{
|
||||
float holdBlockH = (finalBlockSize * 0.6f) * 4.0f;
|
||||
// Base panel height; enforce minimum but allow larger to fit texture
|
||||
float panelH = std::max(holdBlockH + 12.0f, 420.0f);
|
||||
// Increase height by ~20% of the hold block to give more vertical room
|
||||
float extraH = holdBlockH * 0.50f;
|
||||
panelH += extraH;
|
||||
const float holdGap = 18.0f;
|
||||
|
||||
// Align X to the bottom score label (`scoreX`) plus an offset to the right
|
||||
float panelX = scoreX + 30.0f; // move ~30px right to align with score label
|
||||
float panelW = statsW + 32.0f;
|
||||
float panelY = gridY - panelH - holdGap;
|
||||
// Move panel a bit higher for spacing (about half the extra height)
|
||||
panelY -= extraH * 0.5f;
|
||||
float labelX = panelX + 40.0f; // shift HOLD label ~30px to the right
|
||||
float labelY = panelY + 8.0f;
|
||||
|
||||
if (holdPanelTex) {
|
||||
int texW = 0, texH = 0;
|
||||
SDL_QueryTexture(holdPanelTex, nullptr, nullptr, &texW, &texH);
|
||||
if (texW > 0 && texH > 0) {
|
||||
// If the texture is taller than the current panel, expand panelH
|
||||
float texAspect = float(texH) / float(texW);
|
||||
float desiredTexH = panelW * texAspect;
|
||||
if (desiredTexH + 12.0f > panelH) {
|
||||
panelH = desiredTexH + 12.0f;
|
||||
// Recompute vertical placement after growing panelH
|
||||
panelY = gridY - panelH - holdGap;
|
||||
labelY = panelY + 8.0f;
|
||||
}
|
||||
|
||||
// Fill panel width and compute destination height from texture aspect ratio
|
||||
float texAspect = float(texH) / float(texW);
|
||||
float dstW = panelW;
|
||||
float dstH = dstW * texAspect * 1.2f;
|
||||
// If texture height exceeds panel, expand panelH to fit texture comfortably
|
||||
if (dstH + 12.0f > panelH) {
|
||||
panelH = dstH + 12.0f;
|
||||
panelY = gridY - panelH - holdGap;
|
||||
labelY = panelY + 8.0f;
|
||||
}
|
||||
float dstX = panelX;
|
||||
float dstY = panelY + (panelH - dstH) * 0.5f;
|
||||
|
||||
SDL_FRect panelDst{dstX, dstY, dstW, dstH};
|
||||
SDL_SetTextureBlendMode(holdPanelTex, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureScaleMode(holdPanelTex, SDL_SCALEMODE_LINEAR);
|
||||
SDL_RenderTexture(renderer, holdPanelTex, nullptr, &panelDst);
|
||||
} else {
|
||||
// Fallback to filling panel area if texture metrics unavailable
|
||||
SDL_SetRenderDrawColor(renderer, 12, 18, 32, 220);
|
||||
SDL_FRect panelDst{panelX, panelY, panelW, panelH};
|
||||
SDL_RenderFillRect(renderer, &panelDst);
|
||||
}
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(renderer, 12, 18, 32, 220);
|
||||
SDL_FRect panelDst{panelX, panelY, panelW, panelH};
|
||||
SDL_RenderFillRect(renderer, &panelDst);
|
||||
}
|
||||
|
||||
pixelFont->draw(renderer, labelX, labelY, "HOLDx", 1.0f, {255, 220, 0, 255});
|
||||
|
||||
if (game->held().type < PIECE_COUNT) {
|
||||
float previewW = finalBlockSize * 0.6f * 4.0f;
|
||||
float previewX = panelX + (panelW - previewW) * 0.5f;
|
||||
float previewY = panelY + (panelH - holdBlockH) * 0.5f;
|
||||
drawSmallPiece(renderer, blocksTex, static_cast<PieceType>(game->held().type), previewX, previewY, finalBlockSize * 0.6f);
|
||||
}
|
||||
}
|
||||
|
||||
// Pause overlay (suppressed when requested, e.g., countdown)
|
||||
|
||||
Reference in New Issue
Block a user