Hello, I want to make a text writing effect as a dialog but it doesn’t work out to be able to align the text well, I leave you an image of how I’m doing it.
The Code for render segments:
for(int i = 0;i<Seg.Text.Num();i++)
{
AHUD_Customize* HUDC = Cast<AHUD_Customize>(HUD);
if(HUDC)
InPosition.X += HUDC->SizeX*((float(i)/30));
RenderCharacter(HUD,Canvas, Seg.Text[i], Seg, InPosition, Scale, BlendColor, DefaultColor, TextProgress);
}
The code to render the characters of tex:
if(TextProgress < Char.Index) return;
UHUDElement_Base::DrawText(HUD, FText::FromString(Char.value),InPosition.X, InPosition.Y, Scale,Scale,GEngine->GetMediumFont(), ETextAlign::TextAlign_Left, 0, DefaultColor);
Structs Code for render the text:
USTRUCT(BlueprintType)
struct FBTIcon
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
FName name;
//Should material or texture
UPROPERTY(EditAnywhere)
UObject* Icon;
UPROPERTY(EditAnywhere)
float Size = 1;
FBTIcon(const FName& Name, UObject* Icon, float Size)
: name(Name),
Icon(Icon),
Size(Size)
{
}
FBTIcon(){}
};
USTRUCT(BlueprintType)
struct FBTButton
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
FName name;
UPROPERTY(EditAnywhere)
EHatControllerBind bind;
FBTButton(const FName& Name, EHatControllerBind Bind)
: name(Name),
bind(Bind)
{
}
FBTButton(){}
};
/* BTCharacter: A single in a segment. */
USTRUCT(BlueprintType)
struct FBTCharacter
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
FString value;
//Should material or texture
UPROPERTY(EditAnywhere)
UObject* TextureValue;
UPROPERTY(EditAnywhere)
float TextureSize = 1;
UPROPERTY(EditAnywhere)
float PixelWidth;
UPROPERTY(EditAnywhere)
float PixelHeight;
UPROPERTY(EditAnywhere)
FVector2D PixelPosition;
// Index in the BTScript, MINUS wait time
UPROPERTY(EditAnywhere)
int Index;
/// Index in the BTScript, PLUS wait time
UPROPERTY(EditAnywhere)
int VirtualIndex;
FBTCharacter(const FString& Value, UObject* TextureValue, float TextureSize, float PixelWidth, float PixelHeight,
const FVector2D& PixelPosition, int Index, int VirtualIndex)
: value(Value),
TextureValue(TextureValue),
TextureSize(TextureSize),
PixelWidth(PixelWidth),
PixelHeight(PixelHeight),
PixelPosition(PixelPosition),
Index(Index),
VirtualIndex(VirtualIndex)
{
}
FBTCharacter()
{
}
};
USTRUCT(BlueprintType)
struct FBTSegment
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
TArray<FBTCharacter> Text;
UPROPERTY(EditAnywhere)
FColor Color;
UPROPERTY(EditAnywhere)
int Line;
UPROPERTY(EditAnywhere)
float PixelWidth;
UPROPERTY(EditAnywhere)
float PixelHeight;
UPROPERTY(EditAnywhere)
FVector2D PixelPosition;
UPROPERTY(EditAnywhere)
int EffectShake;
UPROPERTY(EditAnywhere)
bool EffectWave;
UPROPERTY(EditAnywhere)
bool EffectScream;
UPROPERTY(EditAnywhere)
bool EffectGlitch;
UPROPERTY(EditAnywhere)
float Scale;
UPROPERTY(EditAnywhere)
bool DefaultColor;
UPROPERTY(EditAnywhere)
int WaitLength;
UPROPERTY(EditAnywhere)
int VirtualIndex; // Index in the script, PLUS wait time
UPROPERTY(EditAnywhere)
float TotalLineWidth; // Width for the whole line we're on.
UPROPERTY(EditAnywhere)
UFont* OverrideFont; // if not none, override font when rendering this segment. This is used for localized fonts
FBTSegment(const TArray<FBTCharacter>& Text, const FColor& Color, int Line, float PixelWidth, float PixelHeight,
const FVector2D& PixelPosition, int EffectShake, bool bEffectWave, bool bEffectScream, bool bEffectGlitch,
float Scale, bool bDefaultColor, int WaitLength, int VirtualIndex, float TotalLineWidth, UFont* OverrideFont)
: Text(Text),
Color(Color),
Line(Line),
PixelWidth(PixelWidth),
PixelHeight(PixelHeight),
PixelPosition(PixelPosition),
EffectShake(EffectShake),
EffectWave(bEffectWave),
EffectScream(bEffectScream),
EffectGlitch(bEffectGlitch),
Scale(Scale),
DefaultColor(bDefaultColor),
WaitLength(WaitLength),
VirtualIndex(VirtualIndex),
TotalLineWidth(TotalLineWidth),
OverrideFont(OverrideFont)
{
}
FBTSegment()
{
}
};
USTRUCT(BlueprintType)
struct FBTScript
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
TArray<FBTSegment> Segments;
UPROPERTY(EditAnywhere)
int lines = 0;
UPROPERTY(EditAnywhere)
int characters = 0;
UPROPERTY(EditAnywhere)
int VirtualCharacters = 0;
UPROPERTY(EditAnywhere)
bool Analyzed = false;
UPROPERTY(EditAnywhere)
float PixelWidth;
UPROPERTY(EditAnywhere)
float PixelHeight;
// Analyzer needs this later
UPROPERTY(EditAnywhere)
FString RawText;
// For ConversationType_Internet
UPROPERTY(EditAnywhere)
int NumReviewStars = 0;
FBTScript(const TArray<FBTSegment>& Segments, int Lines, int Characters, int VirtualCharacters, bool bAnalyzed,
float PixelWidth, float PixelHeight, const FString& RawText, int NumReviewStars)
: Segments(Segments),
lines(Lines),
characters(Characters),
VirtualCharacters(VirtualCharacters),
Analyzed(bAnalyzed),
PixelWidth(PixelWidth),
PixelHeight(PixelHeight),
RawText(RawText),
NumReviewStars(NumReviewStars)
{
}
FBTScript()
{}
};