| 411 | } |
| 412 | |
| 413 | void onSoundPlay(char* name, CaptionEnv env) |
| 414 | { |
| 415 | const TFE_Settings_A11y* settings = TFE_Settings::getA11ySettings(); |
| 416 | // Don't add caption if captions are disabled for the current env |
| 417 | if (env == CC_CUTSCENE && !settings->showCutsceneCaptions && !settings->showCutsceneSubtitles) { return; } |
| 418 | if (env == CC_GAMEPLAY && !settings->showGameplayCaptions && !settings->showGameplaySubtitles) { return; } |
| 419 | |
| 420 | if (s_logSFXNames) { TFE_System::logWrite(LOG_ERROR, "a11y", name); } |
| 421 | |
| 422 | string nameLower = toLower(name); |
| 423 | |
| 424 | if (s_captionMap.count(nameLower)) |
| 425 | { |
| 426 | Caption caption = s_captionMap[nameLower]; // Copy |
| 427 | caption.env = env; |
| 428 | // Don't add caption if the last caption has the same text |
| 429 | if (s_activeCaptions.size() > 0 && s_activeCaptions.back().text == caption.text) { return; } |
| 430 | |
| 431 | if (env == CC_CUTSCENE) |
| 432 | { |
| 433 | // Don't add caption if this type of caption is disabled |
| 434 | if (caption.type == CC_EFFECT && !settings->showCutsceneCaptions) { return; } |
| 435 | else if (caption.type == CC_VOICE && !settings->showCutsceneSubtitles) { return; } |
| 436 | |
| 437 | s32 maxLines = CUTSCENE_MAX_LINES[settings->cutsceneFontSize]; |
| 438 | |
| 439 | // Split caption into chunks if it's very long and would take up too much screen |
| 440 | // real estate at the selected font size (e.g. narration before Talay). |
| 441 | loadScreenSize(); |
| 442 | f32 fontScale; |
| 443 | auto windowSize = calcWindowSize(&fontScale, env); |
| 444 | assert(fontScale > 0); |
| 445 | |
| 446 | size_t idx = 0; // Index of current character in string. |
| 447 | string line = ""; // Current line of the current chunk. |
| 448 | string chunk; |
| 449 | s32 chunkLineCount = 0; |
| 450 | while (idx < caption.text.length()) |
| 451 | { |
| 452 | // Extend the line one character at a time until we exceed the width of the panel |
| 453 | // or run out of text. |
| 454 | line += caption.text.at(idx); |
| 455 | idx++; |
| 456 | ImGui::PushFont(s_currentCaptionFont); |
| 457 | auto textSize = ImGui::CalcTextSize(line.c_str(), 0, false, -1.0f); |
| 458 | ImGui::PopFont(); |
| 459 | // If we exceed the width of the panel... |
| 460 | if (textSize.x * fontScale > windowSize.x * 0.95f) |
| 461 | { |
| 462 | size_t spaceIndex = line.rfind(' '); |
| 463 | // ...and the line has a space in it, add the line to the chunk. |
| 464 | if (spaceIndex > 0) |
| 465 | { |
| 466 | chunk += line.substr(0, spaceIndex) + "\n"; |
| 467 | idx -= (line.length() - spaceIndex - 1); |
| 468 | line = string(""); |
| 469 | chunkLineCount++; |
| 470 | } |
no test coverage detected