MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / onSoundPlay

Function onSoundPlay

TheForceEngine/TFE_A11y/accessibility.cpp:413–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 }

Callers 4

sound_playPriorityFunction · 0.85
soundCalculateCueFunction · 0.85
startSfxFunction · 0.85
startSpeechFunction · 0.85

Calls 10

getA11ySettingsFunction · 0.85
logWriteFunction · 0.85
toLowerFunction · 0.85
loadScreenSizeFunction · 0.85
calcWindowSizeFunction · 0.85
enqueueCaptionFunction · 0.85
countMethod · 0.80
atMethod · 0.80
c_strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected