mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 09:35:25 +00:00
Fix typewriter text size calculation being wrong just after first construction
This commit is contained in:
parent
35f8bdf35e
commit
0c92bcbaa8
@ -110,17 +110,39 @@ void UTypewriterTextWidget::PlayLine(const FText& InLine, float Speed)
|
||||
bHasFinishedPlaying = false;
|
||||
|
||||
LineText->SetText(FText());
|
||||
CalculateWrappedString();
|
||||
|
||||
FTimerDelegate Delegate;
|
||||
Delegate.BindUObject(this, &ThisClass::PlayNextLetter);
|
||||
|
||||
TimerManager.SetTimer(LetterTimer, Delegate, LetterPlayTime/CurrentPlaySpeed, true);
|
||||
|
||||
SetVisibility(ESlateVisibility::SelfHitTestInvisible);
|
||||
if (bFirstPlayLine)
|
||||
{
|
||||
// Delay the very first PlayLine after construction, CalculateWrappedString is not reliable until a couple
|
||||
// of UI geometry updates. At first the geometry is 0, then it's just wrong, and then finally it settles.
|
||||
FTimerHandle TempHandle;
|
||||
FTimerDelegate DelayDelegate;
|
||||
DelayDelegate.BindUObject(this, &ThisClass::StartPlayLine);
|
||||
TimerManager.SetTimer(TempHandle, DelayDelegate, 0.2f, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartPlayLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UTypewriterTextWidget::StartPlayLine()
|
||||
{
|
||||
CalculateWrappedString();
|
||||
|
||||
FTimerDelegate Delegate;
|
||||
Delegate.BindUObject(this, &ThisClass::PlayNextLetter);
|
||||
|
||||
FTimerManager& TimerManager = GetWorld()->GetTimerManager();
|
||||
TimerManager.SetTimer(LetterTimer, Delegate, LetterPlayTime/CurrentPlaySpeed, true);
|
||||
|
||||
SetVisibility(ESlateVisibility::SelfHitTestInvisible);
|
||||
|
||||
bFirstPlayLine = false;
|
||||
|
||||
}
|
||||
|
||||
void UTypewriterTextWidget::SkipToLineEnd()
|
||||
{
|
||||
FTimerManager& TimerManager = GetWorld()->GetTimerManager();
|
||||
@ -137,6 +159,13 @@ void UTypewriterTextWidget::SkipToLineEnd()
|
||||
OnLineFinishedPlaying();
|
||||
}
|
||||
|
||||
void UTypewriterTextWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
bFirstPlayLine = true;
|
||||
}
|
||||
|
||||
void UTypewriterTextWidget::PlayNextLetter()
|
||||
{
|
||||
// Incorporate pauses as a multiple of play timer (may not be exact but close enough)
|
||||
|
@ -109,6 +109,8 @@ public:
|
||||
const FString& GetCurrentRunName() const { return CurrentRunName; }
|
||||
|
||||
protected:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
/// Called when on or more letters are added, if subclasses want to override
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Typewriter")
|
||||
void OnPlayLetter();
|
||||
@ -128,6 +130,7 @@ private:
|
||||
|
||||
void CalculateWrappedString();
|
||||
FString CalculateSegments(FString* OutCurrentRunName);
|
||||
void StartPlayLine();
|
||||
|
||||
UPROPERTY()
|
||||
FText CurrentLine;
|
||||
@ -159,4 +162,5 @@ private:
|
||||
FTimerHandle LetterTimer;
|
||||
float CurrentPlaySpeed = 1;
|
||||
float PauseTime = 0;
|
||||
bool bFirstPlayLine = true;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user