Update Dialogue to Validate Choice Structure

This commit is contained in:
Philip W 2024-01-26 11:37:21 +00:00
parent 773c69a99b
commit dd9156e1fc
3 changed files with 33 additions and 7 deletions

Binary file not shown.

View File

@ -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<UDialogueEdge>(Edges[ChildrenNodes[i]])->EdgeColour = FLinearColor::Red;
Cast<UDialogueEdge>(Edges[ChildrenNodes[i]])->SetNodeTitle(FText::FromString("INVALID"));
}
else if (Choices[i].Len() > 15)
{
FString Substring = Choices[i].Left(15);
Substring.Append("...");
Cast<UDialogueEdge>(Edges[ChildrenNodes[i]])->SetNodeTitle(FText::FromString(Substring));
}
else
{
Cast<UDialogueEdge>(Edges[ChildrenNodes[i]])->SetNodeTitle(FText::FromString(Choices[i]));
Cast<UDialogueEdge>(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()));
}

View File

@ -6,11 +6,14 @@
UCLASS(Blueprintable)
class UDialogueEdge: public UGenericGraphEdge
class UDialogueEdge : public UGenericGraphEdge
{
GENERATED_BODY()
// public:
// UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue")
// FText Selection;
UDialogueEdge();
};
inline UDialogueEdge::UDialogueEdge()
{
bShouldDrawTitle = true;
}