A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgNode_Selector.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
3#include "DlgConstants.h"
4#include "DlgContext.h"
5#include "Logging/DlgLogger.h"
6
7
8bool UDlgNode_Selector::HandleNodeEnter(UDlgContext& Context, TSet<const UDlgNode*> NodesEnteredWithThisStep)
9{
10 FireNodeEnterEvents(Context);
11
12 if (NodesEnteredWithThisStep.Contains(this))
13 {
15 TEXT("SelectorNode::HandleNodeEnter - Failed to enter selector node, it was entered multiple times in a single step."
16 "Theoretically with some condition magic it could make sense, but chances are that it is an endless loop,"
17 "thus entering the same selector twice with a single step is not supported. Dialogue is terminated.\nContext:\n\t%s"),
18 *Context.GetContextString()
19 );
20
21 return false;
22 }
23 NodesEnteredWithThisStep.Add(this);
24
25 switch (SelectorType)
26 {
28 {
29 // Find first child with satisfies conditions
30 for (const FDlgEdge& Edge : Children)
31 if (Edge.Evaluate(Context, {this}))
32 return Context.EnterNode(Edge.TargetIndex, NodesEnteredWithThisStep);
33
34 break;
35 }
36
38 {
39 // Build the list of all valid children
40 TArray<int32> Candidates;
41 for (int32 EdgeIndex = 0; EdgeIndex < Children.Num(); ++EdgeIndex)
42 if (Children[EdgeIndex].Evaluate(Context, { this }))
43 Candidates.Add(EdgeIndex);
44
45 // No candidates :(
46 if (Candidates.Num() == 0)
47 break;
48
49 // Select Random
50 const int32 SelectedIndex = FMath::RandHelper(Candidates.Num());
51 const int32 TargetNodeIndex = Children[Candidates[SelectedIndex]].TargetIndex;
52 return Context.EnterNode(TargetNodeIndex, NodesEnteredWithThisStep);
53 }
54
55 default:
56 checkNoEntry();
57 }
58
60 TEXT("HandleNodeEnter - selector node entered, no satisfied child.\nContext:\n\t%s"),
61 *Context.GetContextString()
62 );
63 return false;
64}
static FDlgLogger & Get()
Definition DlgLogger.h:24
void Errorf(const FmtType &Fmt, Types... Args)
Definition INYLogger.h:305
UCLASS(BlueprintType)
Definition DlgContext.h:96
bool EnterNode(int32 NodeIndex, TSet< const UDlgNode * > NodesEnteredWithThisStep)
FString GetContextString() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Context")
bool HandleNodeEnter(UDlgContext &Context, TSet< const UDlgNode * > NodesEnteredWithThisStep) override
EDlgNodeSelectorType SelectorType
UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
TArray< FDlgEdge > Children
UPROPERTY(VisibleAnywhere, EditFixedSize, AdvancedDisplay, Category = "Dialogue|Node")
Definition DlgNode.h:402
void FireNodeEnterEvents(UDlgContext &Context)
Definition DlgNode.cpp:142
USTRUCT(BlueprintType)
Definition DlgEdge.h:25