From adc5787b430ad3898b4b9a329e16e9e545a8fbda Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Fri, 12 Jan 2024 21:31:14 +0000 Subject: [PATCH] Update Dialogue Tree for Text Wrapping & Multiple Speakers --- .../DialogueSystem/DialogueTextNode.cpp | 40 +++++++++++++++---- .../DialogueSystem/DialogueTextNode.h | 16 +++++--- .../DialogueSystem/DialogueTree.cpp | 14 +++++-- .../DialogueSystem/DialogueTree.h | 26 +++++++++--- 4 files changed, 75 insertions(+), 21 deletions(-) diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.cpp b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.cpp index 8b61bba0..6d3e3c88 100644 --- a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.cpp @@ -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; } @@ -44,4 +70,4 @@ FLinearColor UDialogueTextNode::GetBackgroundColor() const #endif -#undef LOCTEXT_NAMESPACE \ No newline at end of file +#undef LOCTEXT_NAMESPACE diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.h index 6ff78b28..af556e4b 100644 --- a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.h +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.h @@ -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; @@ -31,4 +35,4 @@ public: virtual FLinearColor GetBackgroundColor() const override; #endif -}; \ No newline at end of file +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.cpp b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.cpp index 92569451..fc669ebf 100644 --- a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.cpp @@ -9,11 +9,19 @@ 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"; } -#undef LOCTEXT_NAMESPACE \ No newline at end of file +#undef LOCTEXT_NAMESPACE diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.h index 8150ba61..ed992455 100644 --- a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.h +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.h @@ -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; -}; \ No newline at end of file + FDialogueCharacter Character2; + UPROPERTY(EditDefaultsOnly, Category = "Dialogue") + FDialogueCharacter Character3; + UPROPERTY(EditDefaultsOnly, Category = "Dialogue") + FDialogueCharacter Character4; +};