mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +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;
|
bHasFinishedPlaying = false;
|
||||||
|
|
||||||
LineText->SetText(FText());
|
LineText->SetText(FText());
|
||||||
CalculateWrappedString();
|
|
||||||
|
|
||||||
FTimerDelegate Delegate;
|
|
||||||
Delegate.BindUObject(this, &ThisClass::PlayNextLetter);
|
|
||||||
|
|
||||||
TimerManager.SetTimer(LetterTimer, Delegate, LetterPlayTime/CurrentPlaySpeed, true);
|
if (bFirstPlayLine)
|
||||||
|
{
|
||||||
SetVisibility(ESlateVisibility::SelfHitTestInvisible);
|
// 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()
|
void UTypewriterTextWidget::SkipToLineEnd()
|
||||||
{
|
{
|
||||||
FTimerManager& TimerManager = GetWorld()->GetTimerManager();
|
FTimerManager& TimerManager = GetWorld()->GetTimerManager();
|
||||||
@ -137,6 +159,13 @@ void UTypewriterTextWidget::SkipToLineEnd()
|
|||||||
OnLineFinishedPlaying();
|
OnLineFinishedPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UTypewriterTextWidget::NativeConstruct()
|
||||||
|
{
|
||||||
|
Super::NativeConstruct();
|
||||||
|
|
||||||
|
bFirstPlayLine = true;
|
||||||
|
}
|
||||||
|
|
||||||
void UTypewriterTextWidget::PlayNextLetter()
|
void UTypewriterTextWidget::PlayNextLetter()
|
||||||
{
|
{
|
||||||
// Incorporate pauses as a multiple of play timer (may not be exact but close enough)
|
// 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; }
|
const FString& GetCurrentRunName() const { return CurrentRunName; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
/// Called when on or more letters are added, if subclasses want to override
|
/// Called when on or more letters are added, if subclasses want to override
|
||||||
UFUNCTION(BlueprintImplementableEvent, Category = "Typewriter")
|
UFUNCTION(BlueprintImplementableEvent, Category = "Typewriter")
|
||||||
void OnPlayLetter();
|
void OnPlayLetter();
|
||||||
@ -128,6 +130,7 @@ private:
|
|||||||
|
|
||||||
void CalculateWrappedString();
|
void CalculateWrappedString();
|
||||||
FString CalculateSegments(FString* OutCurrentRunName);
|
FString CalculateSegments(FString* OutCurrentRunName);
|
||||||
|
void StartPlayLine();
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
FText CurrentLine;
|
FText CurrentLine;
|
||||||
@ -159,4 +162,5 @@ private:
|
|||||||
FTimerHandle LetterTimer;
|
FTimerHandle LetterTimer;
|
||||||
float CurrentPlaySpeed = 1;
|
float CurrentPlaySpeed = 1;
|
||||||
float PauseTime = 0;
|
float PauseTime = 0;
|
||||||
|
bool bFirstPlayLine = true;
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user