Update Dialogue Tree for Text Wrapping & Multiple Speakers

This commit is contained in:
Philip W 2024-01-12 21:31:14 +00:00
parent eb8f90016f
commit adc5787b43
4 changed files with 75 additions and 21 deletions

View File

@ -16,7 +16,29 @@ UDialogueTextNode::UDialogueTextNode()
FText UDialogueTextNode::GetNodeTitle() const
{
return Text.IsEmpty() ? LOCTEXT("EmptyParagraph", "(Empty paragraph)") : Text;
if (Text.IsEmpty()) return LOCTEXT("EmptyParagraph", "(Empty paragraph)");
FString WrappedText = Text.ToString();
WrappedText = WrappedText.TrimStartAndEnd();
if (Text.ToString().Len() > 20)
{
WrappedText = "";
int CharCount = 0;
for (int i = 0; i < Text.ToString().Len(); i++)
{
if (CharCount > 20 && Text.ToString()[i] == ' ')
{
WrappedText += "\n";
CharCount = 0;
}
else
{
WrappedText += Text.ToString()[i];
CharCount++;
}
}
}
UE_LOG(LogTemp, Warning, TEXT("Wrapped Text: %s"), *WrappedText);
return FText::FromString(WrappedText);
}
void UDialogueTextNode::SetNodeTitle(const FText& NewTitle)
@ -31,12 +53,16 @@ FLinearColor UDialogueTextNode::GetBackgroundColor() const
if (DialogueTree == nullptr)
return Super::GetBackgroundColor();
switch (DialoguePosition)
switch (DialogueCharacterSpeaking)
{
case EDialoguePosition::Left:
return DialogueTree->LeftDialogueBgColor;
case EDialoguePosition::Right:
return DialogueTree->RightDialogueBgColor;
case ECharacterSpeaking::Character1:
return DialogueTree->Character1.DialogueNodeBgColor;
case ECharacterSpeaking::Character2:
return DialogueTree->Character2.DialogueNodeBgColor;
case ECharacterSpeaking::Character3:
return DialogueTree->Character3.DialogueNodeBgColor;
case ECharacterSpeaking::Character4:
return DialogueTree->Character4.DialogueNodeBgColor;
default:
return FLinearColor::Black;
}

View File

@ -2,27 +2,31 @@
#include "CoreMinimal.h"
#include "GenericGraphNode.h"
#include "DialogueTree.h"
#include "DialogueTextNode.generated.h"
UENUM(BlueprintType)
enum class EDialoguePosition : uint8
enum class ECharacterSpeaking : uint8
{
Left,
Right
Character1,
Character2,
Character3,
Character4
};
UCLASS(Blueprintable)
class UDialogueTextNode : public UGenericGraphNode
{
GENERATED_BODY()
public:
UDialogueTextNode();
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue")
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue", meta = (MultiLine = true))
FText Text;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue")
EDialoguePosition DialoguePosition;
ECharacterSpeaking DialogueCharacterSpeaking = ECharacterSpeaking::Character1;
#if WITH_EDITOR
virtual FText GetNodeTitle() const override;

View File

@ -9,10 +9,18 @@ UDialogueTree::UDialogueTree()
NodeType = UGenericGraphNode::StaticClass();
EdgeType = UDialogueEdge::StaticClass();
LeftDialogueBgColor = FLinearColor::Black;
RightDialogueBgColor = FLinearColor(0.93f, 0.93f, 0.93f, 1.f);
bCanBeCyclical = true;
Character1.CharacterName = "Character 1";
Character2.CharacterName = "Character 2";
Character3.CharacterName = "None";
Character4.CharacterName = "None";
Character1.DialogueNodeBgColor = FLinearColor::Black;
Character2.DialogueNodeBgColor = FLinearColor(0.93f, 0.93f, 0.93f, 1.f);
Character3.DialogueNodeBgColor = FLinearColor::Yellow;
Character4.DialogueNodeBgColor = FLinearColor::Blue;
Name = "Dialogue Tree";
}

View File

@ -4,8 +4,21 @@
#include "GenericGraph.h"
#include "DialogueTree.generated.h"
USTRUCT(BlueprintType)
struct FDialogueCharacter
{
GENERATED_BODY()
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Dialogue")
FName CharacterName;
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Dialogue")
FLinearColor DialogueNodeBgColor;
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Dialogue")
UTexture2D* DialogueCharacterPortrait;
};
UCLASS(Blueprintable)
class ENDLESSVENDETTA_API UDialogueTree: public UGenericGraph
class ENDLESSVENDETTA_API UDialogueTree : public UGenericGraph
{
GENERATED_BODY()
@ -13,8 +26,11 @@ public:
UDialogueTree();
UPROPERTY(EditDefaultsOnly, Category = "Dialogue")
FLinearColor LeftDialogueBgColor;
FDialogueCharacter Character1;
UPROPERTY(EditDefaultsOnly, Category = "Dialogue")
FLinearColor RightDialogueBgColor;
FDialogueCharacter Character2;
UPROPERTY(EditDefaultsOnly, Category = "Dialogue")
FDialogueCharacter Character3;
UPROPERTY(EditDefaultsOnly, Category = "Dialogue")
FDialogueCharacter Character4;
};