Avoid pausing on terminators if there isn't whitespace after

This is mostly to handle cases of mentioning file extensions etc in dialogue, e.g. you don't want a pause in the middle of ".txt"
This commit is contained in:
Steve Streeting 2023-05-12 16:29:23 +01:00
parent 737f289460
commit 47adb4e976
2 changed files with 15 additions and 3 deletions

View File

@ -425,9 +425,16 @@ FString UTypewriterTextWidget::CalculateSegments(FString* OutCurrentRunName)
IsSentenceTerminator(Result[Result.Len() - 1]) && IsSentenceTerminator(Result[Result.Len() - 1]) &&
CurrentLetterIndex < MaxLetterIndex - 1) // Don't pause on the last letter, that's the end pause's job CurrentLetterIndex < MaxLetterIndex - 1) // Don't pause on the last letter, that's the end pause's job
{ {
// Look ahead to make sure we only pause on LAST sentence terminator in a chain of them // Look ahead to make sure we only pause on LAST sentence terminator in a chain of them,
if (LettersLeft == Segment.Text.Len() || !IsSentenceTerminator(Segment.Text[LettersLeft])) // and also optionally not if there isn't whitespace after (e.g. to not pause on ".txt")
PauseTime = PauseTimeAtSentenceTerminators; if (LettersLeft < Segment.Text.Len())
{
if (IsSentenceTerminator(Segment.Text[LettersLeft]) ||
(!bPauseOnlyIfWhitespaceFollowsSentenceTerminator || FText::IsWhitespace(Segment.Text[LettersLeft])))
{
PauseTime = PauseTimeAtSentenceTerminators;
}
}
} }
if (!Segment.RunInfo.Name.IsEmpty()) if (!Segment.RunInfo.Name.IsEmpty())

View File

@ -91,6 +91,11 @@ public:
/// Characters which terminate a clause, which is a preferred place to split an overly long line /// Characters which terminate a clause, which is a preferred place to split an overly long line
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter")
FString ClauseTerminators = ",;:"; FString ClauseTerminators = ",;:";
/// If true (default), only pauses at sentence terminators if there's whitespace following them.
/// This prevents pausing on strings like ".txt"
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter")
bool bPauseOnlyIfWhitespaceFollowsSentenceTerminator = true;
/// If set > 0, splits a single PlayLine into multiple segments of this number of lines maximum /// If set > 0, splits a single PlayLine into multiple segments of this number of lines maximum
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter")