new next block

This commit is contained in:
2025-12-07 19:02:03 +01:00
parent a74d7135e6
commit 9d989ab395
9 changed files with 68 additions and 29 deletions

View File

@ -152,7 +152,8 @@ void GameRenderer::startTransportEffectForGame(Game* game, SDL_Texture* blocksTe
float rel = startX - gridOriginX;
float nearestTile = std::round(rel / finalBlockSize);
startX = gridOriginX + nearestTile * finalBlockSize;
startY = std::round(startY);
// Raise preview slightly to remove a thin line artifact under the panel
startY = std::round(startY) - 5.0f;
// Target is the current piece's grid position
float targetX = gridX + piece.x * finalBlockSize;
@ -180,7 +181,7 @@ void GameRenderer::startTransportEffectForGame(Game* game, SDL_Texture* blocksTe
float rel2 = nextPreviewX - gridOriginX2;
float nearestTile2 = std::round(rel2 / finalBlockSize);
nextPreviewX = gridOriginX2 + nearestTile2 * finalBlockSize;
nextPreviewY = std::round(nextPreviewY);
nextPreviewY = std::round(nextPreviewY) - 5.0f;
// Initialize transport state to perform fades: preview fade-out -> grid fade-in -> next preview fade-in
s_transport.active = true;
@ -396,6 +397,7 @@ void GameRenderer::renderNextPanel(
SDL_Renderer* renderer,
FontAtlas* pixelFont,
SDL_Texture* blocksTex,
SDL_Texture* nextPanelTex,
const Game::Piece& nextPiece,
float panelX,
float panelY,
@ -412,27 +414,37 @@ void GameRenderer::renderNextPanel(
const SDL_Color bayOutline{25, 62, 86, 220};
const SDL_Color labelColor{255, 220, 0, 255};
SDL_FRect bayRect{panelX, panelY, panelW, panelH};
SDL_SetRenderDrawColor(renderer, bayColor.r, bayColor.g, bayColor.b, bayColor.a);
SDL_RenderFillRect(renderer, &bayRect);
// If an external NEXT panel texture is provided, draw it scaled into
// the panel rectangle and skip the custom background/frame drawing.
if (nextPanelTex) {
SDL_FRect dst{panelX, panelY, panelW, panelH};
SDL_RenderTexture(renderer, nextPanelTex, nullptr, &dst);
// Draw the panel label over the texture — user requested visible label
const float labelPad = tileSize * 0.25f;
pixelFont->draw(renderer, panelX + labelPad, panelY + labelPad * 0.5f, "NEXT", 0.9f, labelColor);
} else {
SDL_FRect bayRect{panelX, panelY, panelW, panelH};
SDL_SetRenderDrawColor(renderer, bayColor.r, bayColor.g, bayColor.b, bayColor.a);
SDL_RenderFillRect(renderer, &bayRect);
SDL_FRect thinOutline{panelX - 1.0f, panelY - 1.0f, panelW + 2.0f, panelH + 2.0f};
auto drawOutlineNoBottom = [&](const SDL_FRect& rect, SDL_Color color) {
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
const float left = rect.x;
const float top = rect.y;
const float right = rect.x + rect.w;
const float bottom = rect.y + rect.h;
SDL_RenderLine(renderer, left, top, right, top); // top edge
SDL_RenderLine(renderer, left, top, left, bottom); // left edge
SDL_RenderLine(renderer, right, top, right, bottom); // right edge
};
SDL_FRect thinOutline{panelX - 1.0f, panelY - 1.0f, panelW + 2.0f, panelH + 2.0f};
auto drawOutlineNoBottom = [&](const SDL_FRect& rect, SDL_Color color) {
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
const float left = rect.x;
const float top = rect.y;
const float right = rect.x + rect.w;
const float bottom = rect.y + rect.h;
SDL_RenderLine(renderer, left, top, right, top); // top edge
SDL_RenderLine(renderer, left, top, left, bottom); // left edge
SDL_RenderLine(renderer, right, top, right, bottom); // right edge
};
drawOutlineNoBottom(thinOutline, gridBorderColor);
drawOutlineNoBottom(bayRect, bayOutline);
//drawOutlineNoBottom(thinOutline, gridBorderColor);
//drawOutlineNoBottom(bayRect, bayOutline);
const float labelPad = tileSize * 0.25f;
pixelFont->draw(renderer, panelX + labelPad, panelY + labelPad * 0.5f, "NEXT", 0.9f, labelColor);
const float labelPad = tileSize * 0.25f;
pixelFont->draw(renderer, panelX + labelPad, panelY + labelPad * 0.5f, "NEXT", 0.9f, labelColor);
}
if (nextPiece.type >= PIECE_COUNT) {
return;
@ -478,8 +490,8 @@ void GameRenderer::renderNextPanel(
float rel = startX - gridOriginX;
float nearestTile = std::round(rel / tileSize);
startX = gridOriginX + nearestTile * tileSize;
// Round Y to pixel to avoid subpixel artifacts
startY = std::round(startY);
// Round Y to pixel to avoid subpixel artifacts and nudge upward slightly
startY = std::round(startY) - 5.0f;
// If a transfer fade is active, the preview cells will be drawn by the
// transport effect (with fade). Skip drawing the normal preview in that case.
@ -505,6 +517,7 @@ void GameRenderer::renderPlayingState(
SDL_Texture* blocksTex,
SDL_Texture* statisticsPanelTex,
SDL_Texture* scorePanelTex,
SDL_Texture* nextPanelTex,
float logicalW,
float logicalH,
float logicalScale,
@ -821,7 +834,7 @@ void GameRenderer::renderPlayingState(
SDL_SetRenderDrawBlendMode(renderer, oldBlend);
renderNextPanel(renderer, pixelFont, blocksTex, game->next(), NEXT_PANEL_X, NEXT_PANEL_Y, NEXT_PANEL_WIDTH, NEXT_PANEL_HEIGHT, finalBlockSize);
renderNextPanel(renderer, pixelFont, blocksTex, nextPanelTex, game->next(), NEXT_PANEL_X, NEXT_PANEL_Y, NEXT_PANEL_WIDTH, NEXT_PANEL_HEIGHT, finalBlockSize);
// Draw a small filled connector to visually merge NEXT panel and grid border
SDL_SetRenderDrawColor(renderer, 60, 80, 160, 255); // same as grid border