From dd9156e1fc1e462af17764645cd6654f4ac192e6 Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Fri, 26 Jan 2024 11:37:21 +0000 Subject: [PATCH] Update Dialogue to Validate Choice Structure --- .../Dialogue/Testing/TestDialogueTree.uasset | 4 ++-- .../DialogueSystem/DialogueChoiceNode.cpp | 23 +++++++++++++++++++ .../DialogueSystem/DialogueEdge.h | 13 +++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/EndlessVendetta/Content/Dialogue/Testing/TestDialogueTree.uasset b/EndlessVendetta/Content/Dialogue/Testing/TestDialogueTree.uasset index 7fb3c240..edec184b 100644 --- a/EndlessVendetta/Content/Dialogue/Testing/TestDialogueTree.uasset +++ b/EndlessVendetta/Content/Dialogue/Testing/TestDialogueTree.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bc2cc9b626876c809e9b28673d8aefcf1a83071621cd270863751b61c5b2ae53 -size 22144 +oid sha256:ae77647d592ad3c7affe1b638ba623e02456851dcf3071f11565fdcec2a3d58d +size 23072 diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.cpp b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.cpp index 6fa8ff9d..00c3b94f 100644 --- a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.cpp @@ -1,4 +1,6 @@ #include "DialogueChoiceNode.h" + +#include "DialogueEdge.h" #include "DialogueTree.h" #define LOCTEXT_NAMESPACE "UDialogueChoiceNode" @@ -16,6 +18,27 @@ UDialogueChoiceNode::UDialogueChoiceNode() FText UDialogueChoiceNode::GetNodeTitle() const { + bool bHasValidNumberOfChoices = false; + if (Choices.Num() == ChildrenNodes.Num()) bHasValidNumberOfChoices = true; + for (int i = 0; i < Edges.Num(); i++) + { + if (!bHasValidNumberOfChoices) + { + Cast(Edges[ChildrenNodes[i]])->EdgeColour = FLinearColor::Red; + Cast(Edges[ChildrenNodes[i]])->SetNodeTitle(FText::FromString("INVALID")); + } + else if (Choices[i].Len() > 15) + { + FString Substring = Choices[i].Left(15); + Substring.Append("..."); + Cast(Edges[ChildrenNodes[i]])->SetNodeTitle(FText::FromString(Substring)); + } + else + { + Cast(Edges[ChildrenNodes[i]])->SetNodeTitle(FText::FromString(Choices[i])); + Cast(Edges[ChildrenNodes[i]])->EdgeColour = FLinearColor::White; + } + } const FText ChoiceNodeTitle = NodeTitle.IsEmpty() ? LOCTEXT("Choice Node", "Choice Node") : NodeTitle; return FText::Format(LOCTEXT("Choice Node Title", "{0} [{1}]"), ChoiceNodeTitle, FText::AsNumber(Choices.Num())); } diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h index ef92beff..3613f00d 100644 --- a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h @@ -6,11 +6,14 @@ UCLASS(Blueprintable) -class UDialogueEdge: public UGenericGraphEdge +class UDialogueEdge : public UGenericGraphEdge { GENERATED_BODY() - // public: - // UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") - // FText Selection; -}; \ No newline at end of file + UDialogueEdge(); +}; + +inline UDialogueEdge::UDialogueEdge() +{ + bShouldDrawTitle = true; +}