From 47adb4e976d48c290c332ea7f44e688c68ddba24 Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Fri, 12 May 2023 16:29:23 +0100 Subject: [PATCH] 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" --- .../Private/StevesUI/TypewriterTextWidget.cpp | 13 ++++++++++--- .../Public/StevesUI/TypewriterTextWidget.h | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/StevesUEHelpers/Private/StevesUI/TypewriterTextWidget.cpp b/Source/StevesUEHelpers/Private/StevesUI/TypewriterTextWidget.cpp index b3835fd..f397af3 100644 --- a/Source/StevesUEHelpers/Private/StevesUI/TypewriterTextWidget.cpp +++ b/Source/StevesUEHelpers/Private/StevesUI/TypewriterTextWidget.cpp @@ -425,9 +425,16 @@ FString UTypewriterTextWidget::CalculateSegments(FString* OutCurrentRunName) IsSentenceTerminator(Result[Result.Len() - 1]) && 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 - if (LettersLeft == Segment.Text.Len() || !IsSentenceTerminator(Segment.Text[LettersLeft])) - PauseTime = PauseTimeAtSentenceTerminators; + // Look ahead to make sure we only pause on LAST sentence terminator in a chain of them, + // and also optionally not if there isn't whitespace after (e.g. to not pause on ".txt") + if (LettersLeft < Segment.Text.Len()) + { + if (IsSentenceTerminator(Segment.Text[LettersLeft]) || + (!bPauseOnlyIfWhitespaceFollowsSentenceTerminator || FText::IsWhitespace(Segment.Text[LettersLeft]))) + { + PauseTime = PauseTimeAtSentenceTerminators; + } + } } if (!Segment.RunInfo.Name.IsEmpty()) diff --git a/Source/StevesUEHelpers/Public/StevesUI/TypewriterTextWidget.h b/Source/StevesUEHelpers/Public/StevesUI/TypewriterTextWidget.h index 5caa2e4..7b35bb0 100644 --- a/Source/StevesUEHelpers/Public/StevesUI/TypewriterTextWidget.h +++ b/Source/StevesUEHelpers/Public/StevesUI/TypewriterTextWidget.h @@ -91,6 +91,11 @@ public: /// Characters which terminate a clause, which is a preferred place to split an overly long line UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter") 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 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter")