added challenge level text

This commit is contained in:
2025-12-20 20:47:04 +01:00
parent 6c48af0bec
commit eb9822dac7
5 changed files with 190 additions and 4 deletions

View File

@ -7,6 +7,8 @@
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <sstream>
#include <string>
#include <limits>
#include <random>
#include <vector>
@ -610,7 +612,9 @@ void GameRenderer::renderPlayingState(
bool challengeClearFxActive,
const std::vector<int>* challengeClearFxOrder,
double challengeClearFxElapsedMs,
double challengeClearFxDurationMs
double challengeClearFxDurationMs,
const std::string* challengeStoryText,
float challengeStoryAlpha
) {
if (!game || !pixelFont) return;
@ -1702,6 +1706,51 @@ void GameRenderer::renderPlayingState(
pixelFont->draw(renderer, statsTextX, baseY + line.offsetY, line.text, line.scale, line.color);
}
// Challenge story / briefing line near level indicator
if (challengeStoryText && !challengeStoryText->empty() && challengeStoryAlpha > 0.0f && game->getMode() == GameMode::Challenge) {
float alpha = std::clamp(challengeStoryAlpha, 0.0f, 1.0f);
SDL_Color storyColor{160, 220, 255, static_cast<Uint8>(std::lround(210.0f * alpha))};
SDL_Color shadowColor{0, 0, 0, static_cast<Uint8>(std::lround(120.0f * alpha))};
auto drawWrapped = [&](const std::string& text, float x, float y, float maxW, float scale, SDL_Color color) {
std::istringstream iss(text);
std::string word;
std::string line;
float cursorY = y;
int lastH = 0;
while (iss >> word) {
std::string candidate = line.empty() ? word : (line + " " + word);
int w = 0, h = 0;
pixelFont->measure(candidate, scale, w, h);
if (w > maxW && !line.empty()) {
pixelFont->draw(renderer, x + 1.0f, cursorY + 1.0f, line, scale, shadowColor);
pixelFont->draw(renderer, x, cursorY, line, scale, color);
cursorY += h + 4.0f;
line = word;
lastH = h;
} else {
line = candidate;
lastH = h;
}
}
if (!line.empty()) {
pixelFont->draw(renderer, x + 1.0f, cursorY + 1.0f, line, scale, shadowColor);
pixelFont->draw(renderer, x, cursorY, line, scale, color);
cursorY += lastH + 4.0f;
}
};
float storyX = statsTextX;
float storyY = baseY + 112.0f;
float maxW = 230.0f;
if (scorePanelMetricsValid && scorePanelWidth > 40.0f) {
storyX = scorePanelLeftX + 14.0f;
maxW = std::max(160.0f, scorePanelWidth - 28.0f);
}
drawWrapped(*challengeStoryText, storyX, storyY, maxW, 0.7f, storyColor);
}
if (debugEnabled) {
pixelFont->draw(renderer, logicalW - 260, 10, gravityHud, 0.9f, {200, 200, 220, 255});
}