fixed highscores
This commit is contained in:
@ -2054,21 +2054,15 @@ void TetrisApp::Impl::runLoop()
|
||||
pixelFont.draw(renderer, boxX + (boxW - sW) * 0.5f + contentOffsetX, boxY + 100 + contentOffsetY, scoreStr, 1.2f, {255, 255, 255, 255});
|
||||
|
||||
if (isNewHighScore) {
|
||||
const char* enterName = "ENTER NAME:";
|
||||
const bool isCoopEntry = (game && game->getMode() == GameMode::Cooperate && coopGame);
|
||||
const char* enterName = isCoopEntry ? "ENTER NAMES:" : "ENTER NAME:";
|
||||
int enW=0, enH=0; pixelFont.measure(enterName, 1.0f, enW, enH);
|
||||
pixelFont.draw(renderer, boxX + (boxW - enW) * 0.5f + contentOffsetX, boxY + 160 + contentOffsetY, enterName, 1.0f, {200, 200, 220, 255});
|
||||
|
||||
float inputW = 300.0f;
|
||||
float inputH = 40.0f;
|
||||
float inputX = boxX + (boxW - inputW) * 0.5f;
|
||||
float inputY = boxY + 200.0f;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_FRect inputRect{inputX + contentOffsetX, inputY + contentOffsetY, inputW, inputH};
|
||||
SDL_RenderFillRect(renderer, &inputRect);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 220, 0, 255);
|
||||
SDL_RenderRect(renderer, &inputRect);
|
||||
const float inputW = isCoopEntry ? 260.0f : 300.0f;
|
||||
const float inputH = 40.0f;
|
||||
const float inputX = boxX + (boxW - inputW) * 0.5f;
|
||||
const float inputY = boxY + 200.0f;
|
||||
|
||||
const float nameScale = 1.2f;
|
||||
const bool showCursor = ((SDL_GetTicks() / 500) % 2) == 0;
|
||||
@ -2077,34 +2071,67 @@ void TetrisApp::Impl::runLoop()
|
||||
pixelFont.measure("A", nameScale, metricsW, metricsH);
|
||||
if (metricsH == 0) metricsH = 24;
|
||||
|
||||
int nameW = 0, nameH = 0;
|
||||
if (!playerName.empty()) {
|
||||
pixelFont.measure(playerName, nameScale, nameW, nameH);
|
||||
// Single name entry (non-coop) --- keep original behavior
|
||||
if (!isCoopEntry) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_FRect inputRect{inputX + contentOffsetX, inputY + contentOffsetY, inputW, inputH};
|
||||
SDL_RenderFillRect(renderer, &inputRect);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 220, 0, 255);
|
||||
SDL_RenderRect(renderer, &inputRect);
|
||||
|
||||
int nameW = 0, nameH = 0;
|
||||
if (!playerName.empty()) pixelFont.measure(playerName, nameScale, nameW, nameH);
|
||||
else nameH = metricsH;
|
||||
|
||||
float textX = inputX + (inputW - static_cast<float>(nameW)) * 0.5f + contentOffsetX;
|
||||
float textY = inputY + (inputH - static_cast<float>(metricsH)) * 0.5f + contentOffsetY;
|
||||
|
||||
if (!playerName.empty()) pixelFont.draw(renderer, textX, textY, playerName, nameScale, {255,255,255,255});
|
||||
|
||||
if (showCursor) {
|
||||
int cursorW = 0, cursorH = 0; pixelFont.measure("_", nameScale, cursorW, cursorH);
|
||||
float cursorX = playerName.empty() ? inputX + (inputW - static_cast<float>(cursorW)) * 0.5f + contentOffsetX : textX + static_cast<float>(nameW);
|
||||
float cursorY = inputY + (inputH - static_cast<float>(cursorH)) * 0.5f + contentOffsetY;
|
||||
pixelFont.draw(renderer, cursorX, cursorY, "_", nameScale, {255,255,255,255});
|
||||
}
|
||||
|
||||
const char* hint = "PRESS ENTER TO SUBMIT";
|
||||
int hW=0, hH=0; pixelFont.measure(hint, 0.8f, hW, hH);
|
||||
pixelFont.draw(renderer, boxX + (boxW - hW) * 0.5f + contentOffsetX, boxY + 280 + contentOffsetY, hint, 0.8f, {150, 150, 150, 255});
|
||||
} else {
|
||||
nameH = metricsH;
|
||||
// Coop: prompt sequentially. First ask Player 1, then ask Player 2 after Enter.
|
||||
const bool askingP1 = (highScoreEntryIndex == 0);
|
||||
const char* label = askingP1 ? "PLAYER 1:" : "PLAYER 2:";
|
||||
int labW=0, labH=0; pixelFont.measure(label, 1.0f, labW, labH);
|
||||
pixelFont.draw(renderer, boxX + (boxW - labW) * 0.5f + contentOffsetX, boxY + 160 + contentOffsetY, label, 1.0f, {200,200,220,255});
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_FRect rect{inputX + contentOffsetX, inputY + contentOffsetY, inputW, inputH};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 220, 0, 255);
|
||||
SDL_RenderRect(renderer, &rect);
|
||||
|
||||
const std::string &activeName = askingP1 ? playerName : player2Name;
|
||||
int nameW = 0, nameH = 0;
|
||||
if (!activeName.empty()) pixelFont.measure(activeName, nameScale, nameW, nameH);
|
||||
else nameH = metricsH;
|
||||
|
||||
float textX = inputX + (inputW - static_cast<float>(nameW)) * 0.5f + contentOffsetX;
|
||||
float textY = inputY + (inputH - static_cast<float>(metricsH)) * 0.5f + contentOffsetY;
|
||||
if (!activeName.empty()) pixelFont.draw(renderer, textX, textY, activeName, nameScale, {255,255,255,255});
|
||||
|
||||
if (showCursor) {
|
||||
int cursorW=0, cursorH=0; pixelFont.measure("_", nameScale, cursorW, cursorH);
|
||||
float cursorX = activeName.empty() ? inputX + (inputW - static_cast<float>(cursorW)) * 0.5f + contentOffsetX : textX + static_cast<float>(nameW);
|
||||
float cursorY = inputY + (inputH - static_cast<float>(cursorH)) * 0.5f + contentOffsetY;
|
||||
pixelFont.draw(renderer, cursorX, cursorY, "_", nameScale, {255,255,255,255});
|
||||
}
|
||||
|
||||
const char* hint = askingP1 ? "PRESS ENTER FOR NEXT NAME" : "PRESS ENTER TO SUBMIT";
|
||||
int hW=0, hH=0; pixelFont.measure(hint, 0.8f, hW, hH);
|
||||
pixelFont.draw(renderer, boxX + (boxW - hW) * 0.5f + contentOffsetX, boxY + 300 + contentOffsetY, hint, 0.8f, {150, 150, 150, 255});
|
||||
}
|
||||
|
||||
float textX = inputX + (inputW - static_cast<float>(nameW)) * 0.5f + contentOffsetX;
|
||||
float textY = inputY + (inputH - static_cast<float>(metricsH)) * 0.5f + contentOffsetY;
|
||||
|
||||
if (!playerName.empty()) {
|
||||
pixelFont.draw(renderer, textX, textY, playerName, nameScale, {255, 255, 255, 255});
|
||||
}
|
||||
|
||||
if (showCursor) {
|
||||
int cursorW = 0, cursorH = 0;
|
||||
pixelFont.measure("_", nameScale, cursorW, cursorH);
|
||||
float cursorX = playerName.empty()
|
||||
? inputX + (inputW - static_cast<float>(cursorW)) * 0.5f + contentOffsetX
|
||||
: textX + static_cast<float>(nameW);
|
||||
float cursorY = inputY + (inputH - static_cast<float>(cursorH)) * 0.5f + contentOffsetY;
|
||||
pixelFont.draw(renderer, cursorX, cursorY, "_", nameScale, {255, 255, 255, 255});
|
||||
}
|
||||
|
||||
const char* hint = "PRESS ENTER TO SUBMIT";
|
||||
int hW=0, hH=0; pixelFont.measure(hint, 0.8f, hW, hH);
|
||||
pixelFont.draw(renderer, boxX + (boxW - hW) * 0.5f + contentOffsetX, boxY + 280 + contentOffsetY, hint, 0.8f, {150, 150, 150, 255});
|
||||
|
||||
} else {
|
||||
char linesStr[64];
|
||||
snprintf(linesStr, sizeof(linesStr), "LINES: %d", game->lines());
|
||||
|
||||
Reference in New Issue
Block a user