Dialog * Dialog::CreateForString(const string &dialogText, const string &filePath, int timeBeforeDialogInitial, int delayBeforeContinuing, bool isInterrogation, bool isPassive, bool isConfrontation, bool canNavigateBack, bool canNavigateForward, bool presentEvidenceAutomatically, bool canStopPresentingEvidence) { Dialog *pDialog = new Dialog(filePath, timeBeforeDialogInitial, delayBeforeContinuing, isInterrogation, isPassive, isConfrontation, canNavigateBack, canNavigateForward, presentEvidenceAutomatically, canStopPresentingEvidence); double allowedWidth = textAreaRect.GetWidth() - desiredPadding * 2; string fullString = ""; deque<string> wordList = split(dialogText, ' '); while (!wordList.empty()) { string curstring = ""; double curTextWidth = 0; bool lineDone = false; bool addSpace = false; if (fullString.length() > 0) { fullString += "\n"; } while (!lineDone) { string stringToTest = (addSpace ? " " : "") + wordList.front(); double curStringWidth = pDialogFont->GetWidth(pDialog->StripEvents(stringToTest)); // If we've got a single word that takes up more than the entire length of the screen, // then we need to split it up. if (curTextWidth == 0 && curStringWidth > allowedWidth) { string testString = ""; string lastTestString = ""; curStringWidth = 0; while (curStringWidth <= allowedWidth) { if (stringToTest[0] == '{') { testString += stringToTest[0]; stringToTest = stringToTest.substr(1); while (stringToTest[0] != '}') { testString += stringToTest[0]; stringToTest = stringToTest.substr(1); } testString += stringToTest[0]; stringToTest = stringToTest.substr(1); } lastTestString = testString; testString += stringToTest[0]; double testCurStringWidth = pDialogFont->GetWidth(pDialog->StripEvents(testString)); if (testCurStringWidth > allowedWidth) { break; } curStringWidth = testCurStringWidth; stringToTest = stringToTest.substr(1); } wordList.insert(wordList.begin() + 1, stringToTest); stringToTest = lastTestString; } if (curTextWidth + curStringWidth <= allowedWidth) { string stringToPrependOnNext; stringToTest = pDialog->ParseEvents(fullString.length() + curstring.length(), stringToTest, &stringToPrependOnNext); curstring += stringToTest; curTextWidth += curStringWidth; wordList.pop_front(); addSpace = true; if (wordList.empty()) { lineDone = true; } else { wordList[0] = stringToPrependOnNext + wordList.front(); } } else { lineDone = true; } } fullString += curstring; } pDialog->SetText(fullString); if (delayBeforeContinuing >= 0) { pDialog->AddPausePosition(fullString.length(), delayBeforeContinuing); } if (filePath.length() > 0) { ResourceLoader::GetInstance()->PreloadDialog(filePath, filePath); } return pDialog; }