A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueDetailsPanelUtils.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
3#include "DlgHelper.h"
4
5
7{
8 TArray<UObject*> OuterObjects;
9 PropertyHandle->GetOuterObjects(OuterObjects);
10
11 for (UObject* Object : OuterObjects)
12 {
13 if (UDlgNode* Node = Cast<UDlgNode>(Object))
14 {
15 return CastChecked<UDialogueGraphNode_Base>(Node->GetGraphNode());
16 }
17
18 if (UDialogueGraphNode_Base* Node = Cast<UDialogueGraphNode_Base>(Object))
19 {
20 return Node;
21 }
22 }
23
24 return nullptr;
25}
26
28{
29 if (UDialogueGraphNode_Base* BaseGraphNode = GetGraphNodeBaseFromPropertyHandle(PropertyHandle))
30 {
31 if (UDialogueGraphNode* Node = Cast<UDialogueGraphNode>(BaseGraphNode))
32 {
33 return Node;
34 }
35 if (UDialogueGraphNode_Edge* GraphEdge = Cast<UDialogueGraphNode_Edge>(BaseGraphNode))
36 {
37 if (GraphEdge->HasParentNode())
38 {
39 return GraphEdge->GetParentNode();
40 }
41 }
42 }
43
44 return nullptr;
45}
46
47UDlgDialogue* FDialogueDetailsPanelUtils::GetDialogueFromPropertyHandle(const TSharedRef<IPropertyHandle>& PropertyHandle)
48{
49 UDlgDialogue* Dialogue = nullptr;
50
51 // Check first children objects of property handle, should be a dialogue node or a graph node
52 if (UDialogueGraphNode_Base* GraphNode = GetGraphNodeBaseFromPropertyHandle(PropertyHandle))
53 {
54 Dialogue = GraphNode->GetDialogue();
55 }
56
57 // One last try, get to the root of the problem ;)
58 if (!IsValid(Dialogue))
59 {
60 TSharedPtr<IPropertyHandle> ParentHandle = PropertyHandle->GetParentHandle();
61 // Find the root property handle
62 while (ParentHandle.IsValid() && ParentHandle->GetParentHandle().IsValid())
63 {
64 ParentHandle = ParentHandle->GetParentHandle();
65 }
66
67 // The outer should be a dialogue
68 if (ParentHandle.IsValid())
69 {
70 TArray<UObject*> OuterObjects;
71 ParentHandle->GetOuterObjects(OuterObjects);
72 for (UObject* Object : OuterObjects)
73 {
74 if (UDlgDialogue* FoundDialogue = Cast<UDlgDialogue>(Object))
75 {
76 Dialogue = FoundDialogue;
77 break;
78 }
79 }
80 }
81 }
82
83 return Dialogue;
84}
85
86FName FDialogueDetailsPanelUtils::GetParticipantNameFromPropertyHandle(const TSharedRef<IPropertyHandle>& ParticipantNamePropertyHandle)
87{
88 FName ParticipantName = NAME_None;
89 if (ParticipantNamePropertyHandle->GetValue(ParticipantName) != FPropertyAccess::Success)
90 {
91 return ParticipantName;
92 }
93
94 // Try the node that owns this
95 if (ParticipantName.IsNone())
96 {
97 // Possible edge?
98 if (UDialogueGraphNode* GraphNode = GetClosestGraphNodeFromPropertyHandle(ParticipantNamePropertyHandle))
99 {
100 return GraphNode->GetDialogueNode().GetNodeParticipantName();
101 }
102 }
103
104 return ParticipantName;
105}
106
108{
109 if (Dialogue == nullptr)
110 {
111 return {};
112 }
113
114 TSet<FName> ParticipantNames;
115 Dialogue->GetAllParticipantNames(ParticipantNames);
116 FDlgHelper::SortDefault(ParticipantNames);
117 return ParticipantNames.Array();
118}
static void SortDefault(TArray< FName > &OutArray)
Definition DlgHelper.h:452
UCLASS(BlueprintType, Meta = (DisplayThumbnail = "true"))
Definition DlgDialogue.h:85
UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
Definition DlgNode.h:40
static TArray< FName > GetDialogueSortedParticipantNames(UDlgDialogue *Dialogue)
static FName GetParticipantNameFromPropertyHandle(const TSharedRef< IPropertyHandle > &ParticipantNamePropertyHandle)
static UDialogueGraphNode_Base * GetGraphNodeBaseFromPropertyHandle(const TSharedRef< IPropertyHandle > &PropertyHandle)
static UDlgDialogue * GetDialogueFromPropertyHandle(const TSharedRef< IPropertyHandle > &PropertyHandle)
static UDialogueGraphNode * GetClosestGraphNodeFromPropertyHandle(const TSharedRef< IPropertyHandle > &PropertyHandle)