Promoted MaxNumberOfLines to a property

This commit is contained in:
lumpn 2023-04-20 13:56:01 +08:00
parent c20d1113c1
commit 40398ef851
2 changed files with 8 additions and 7 deletions

View File

@ -120,11 +120,9 @@ void UTypewriterTextWidget::PlayNextLinePart(float Speed)
CalculateWrappedString(RemainingLinePart);
// TODO Jonas: Promote MaxLines to variable. Might want MaxLines = 1 for text before choices.
int MaxLines = 3;
if (NumberOfLines > MaxLines)
if (NumberOfLines > MaxNumberOfLines)
{
int MaxLength = CalculateMaxLength(MaxLines);
int MaxLength = CalculateMaxLength();
int TerminatorIndex = FindLastTerminator(RemainingLinePart, MaxLength);
int Length = TerminatorIndex + 1;
const FString& FirstLinePart = RemainingLinePart.Left(Length);
@ -236,14 +234,13 @@ int UTypewriterTextWidget::FindLastTerminator(const FString& CurrentLineString,
return (Count - 1);
}
int UTypewriterTextWidget::CalculateMaxLength(int MaxNumberOfLines)
int UTypewriterTextWidget::CalculateMaxLength()
{
int MaxLength = 0;
int CurrentNumberOfLines = 1;
for (int i = 0; i < Segments.Num(); i++)
{
const FTypewriterTextSegment& Segment = Segments[i];
// TODO Jonas: Mark line break segments as such in CalculateWrappedString instead.
if (Segment.Text.Equals(FString(TEXT("\n"))))
{
CurrentNumberOfLines++;

View File

@ -84,6 +84,10 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter")
float PauseTimeAtSentenceTerminators = 0.5f;
/// How many lines of text at most to print at once.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Typewriter")
int MaxNumberOfLines = 3;
/// Set Text immediately
UFUNCTION(BlueprintCallable)
void SetText(const FText& InText);
@ -134,7 +138,7 @@ private:
static bool IsClauseTerminator(TCHAR Letter);
static int FindLastTerminator(const FString& CurrentLineString, int Count);
int CalculateMaxLength(int MaxNumberOfLines);
int CalculateMaxLength();
void CalculateWrappedString(const FString& CurrentLineString);
FString CalculateSegments(FString* OutCurrentRunName);