A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueK2Node_SwitchDialogueCallback.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
3
4#include "BlueprintNodeSpawner.h"
5#include "BlueprintActionDatabaseRegistrar.h"
6#include "EdGraphSchema_K2.h"
7#include "Kismet/KismetMathLibrary.h"
8#include "UObject/UObjectIterator.h"
9
11#include "DlgManager.h"
13
14#define LOCTEXT_NAMESPACE "DlgK2Node_Select"
15
17 : Super(ObjectInitializer)
18{
19 FunctionName = TEXT("NotEqual_NameName");
20 FunctionClass = UKismetMathLibrary::StaticClass();
21 bHasDefaultPin = true;
22 AdvancedPinDisplay = ENodeAdvancedPins::NoPins;
23}
24
26// Begin UEdGraphNode interface
28{
30 Super::AllocateDefaultPins();
31}
32
34{
35 return LOCTEXT("DlgCallbackSwitch_NodeTitle", "Switch on Relevant Dialogue Callback");
36}
37
39{
40 return LOCTEXT("DlgCallbackSwitch_Tooltip", "Selects an output based on the input");
41}
42// End UEdGraphNode interface
44
46// Begin UK2Node Interface
47void UDialogueK2Node_SwitchDialogueCallback::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
48{
49 // actions get registered under specific object-keys; the idea is that
50 // actions might have to be updated (or deleted) if their object-key is
51 // mutated (or removed)... here we use the node's class (so if the node
52 // type disappears, then the action should go with it)
53 UClass* ActionKey = GetClass();
54
55 // to keep from needlessly instantiating a UBlueprintNodeSpawner, first
56 // check to make sure that the registrar is looking for actions of this type
57 // (could be regenerating actions for a specific asset, and therefore the
58 // registrar would only accept actions corresponding to that asset)
59 if (ActionRegistrar.IsOpenForRegistration(ActionKey))
60 {
61 UBlueprintNodeSpawner* NodeSpawner = UBlueprintNodeSpawner::Create(GetClass());
62 check(NodeSpawner);
63
64 ActionRegistrar.AddBlueprintAction(ActionKey, NodeSpawner);
65 }
66}
67
69{
70 return LOCTEXT("DlgCallbackSwitch_MenuCategory", "Dialogue|Switch");
71}
72
74{
75 const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();
76 UEdGraphPin* Pin = CreatePin(EGPD_Input, K2Schema->PC_Name, GetSelectionPinName());
77 K2Schema->SetPinAutogeneratedDefaultValueBasedOnType(Pin);
78}
79// End UK2Node Interface
81
83// Begin UK2Node_Switch Interface
85{
86 FEdGraphPinType PinType;
87 PinType.PinCategory = UEdGraphSchema_K2::PC_Name;
88 return PinType;
89}
90
92{
93 // Stop removing option pins, should never arrive here
94 if (TargetPin != GetDefaultPin())
95 {
96 return;
97 }
98
99 Super::RemovePinFromSwitchNode(TargetPin);
100}
101
103{
104 // Do not allow to remove normal pins, only the execution pin
105 if (TargetPin != GetDefaultPin())
106 {
107 return false;
108 }
109
110 return Super::CanRemoveExecutionPin(TargetPin);
111}
112
114{
115 return Index < DialoguePinNames.Num() ? DialoguePinNames[Index] : NAME_None;
116}
117
119{
120 checkNoEntry();
121 return NAME_None;
122}
123
125{
126 const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();
127 for (const auto& PinName : DialoguePinNames)
128 {
129 CreatePin(EGPD_Output, K2Schema->PC_Exec, PinName);
130 }
131}
132
134{
135 // Copied from base class, because it is not exported
136 // TODO PR
137 // Set properties on the function pin
138 UEdGraphPin* FunctionPin = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Object, FunctionClass, FunctionName);
139 FunctionPin->bDefaultValueIsReadOnly = true;
140 FunctionPin->bNotConnectable = true;
141 FunctionPin->bHidden = true;
142
143#if ENGINE_MINOR_VERSION >= 25
144 UFunction* Function = FindUField<UFunction>(FunctionClass, FunctionName);
145#else
146 UFunction* Function = FindField<UFunction>(FunctionClass, FunctionName);
147#endif
148 const bool bIsStaticFunc = Function->HasAllFunctionFlags(FUNC_Static);
149 if (bIsStaticFunc)
150 {
151 // Wire up the self to the CDO of the class if it's not us
152 if (UBlueprint* BP = GetBlueprint())
153 {
154 UClass* FunctionOwnerClass = Function->GetOuterUClass();
155 if (!BP->SkeletonGeneratedClass->IsChildOf(FunctionOwnerClass))
156 {
157 FunctionPin->DefaultObject = FunctionOwnerClass->GetDefaultObject();
158 }
159 }
160 }
161}
162
164{
165 // overwrite default behaviour, should never be used
166 if (RefreshPinNames())
167 {
168 ReconstructNode();
169 }
170}
171// End UK2Node_Switch Interface
173
175// Begin own functions
177{
178 const FName ParticipantName = FDialogueBlueprintUtilities::GetParticipantNameFromNode(this);
179 if (ParticipantName == NAME_None)
180 {
181 return false;
182 }
183
184 TArray<FName> NewPinNames;
185 switch (CallbackType)
186 {
188 UDlgManager::GetAllDialoguesEventNames(ParticipantName, NewPinNames);
189 break;
190
192 UDlgManager::GetAllDialoguesConditionNames(ParticipantName, NewPinNames);
193 break;
194
196 UDlgManager::GetAllDialoguesFloatNames(ParticipantName, NewPinNames);
197 break;
198
200 UDlgManager::GetAllDialoguesIntNames(ParticipantName, NewPinNames);
201 break;
202
204 UDlgManager::GetAllDialoguesBoolNames(ParticipantName, NewPinNames);
205 break;
206
208 UDlgManager::GetAllDialoguesNameNames(ParticipantName, NewPinNames);
209 break;
210
211 default:
212 unimplemented();
213 }
214
215 // Size changed, simply copy
216 if (NewPinNames.Num() != DialoguePinNames.Num())
217 {
218 DialoguePinNames = NewPinNames;
219 return true;
220 }
221
222 // Find any difference, if any
223 for (int32 i = 0; i < NewPinNames.Num(); ++i)
224 {
225 if (NewPinNames[i] != DialoguePinNames[i])
226 {
227 DialoguePinNames = NewPinNames;
228 return true;
229 }
230 }
231
232 return false;
233}
234// End own functions
236
237#undef LOCTEXT_NAMESPACE
static FName GetParticipantNameFromNode(const UK2Node *Node)
void GetMenuActions(FBlueprintActionDatabaseRegistrar &ActionRegistrar) const override
UDialogueK2Node_SwitchDialogueCallback(const FObjectInitializer &ObjectInitializer)
FText GetNodeTitle(ENodeTitleType::Type TitleType) const override
bool CanRemoveExecutionPin(UEdGraphPin *TargetPin) const override
void RemovePinFromSwitchNode(UEdGraphPin *TargetPin) override
static void GetAllDialoguesNameNames(FName ParticipantName, TArray< FName > &OutArray)
UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
static void GetAllDialoguesBoolNames(FName ParticipantName, TArray< FName > &OutArray)
UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
static void GetAllDialoguesEventNames(FName ParticipantName, TArray< FName > &OutArray)
UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
static void GetAllDialoguesIntNames(FName ParticipantName, TArray< FName > &OutArray)
UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
static void GetAllDialoguesConditionNames(FName ParticipantName, TArray< FName > &OutArray)
UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
static void GetAllDialoguesFloatNames(FName ParticipantName, TArray< FName > &OutArray)
UFUNCTION(BlueprintPure, Category = "Dialogue|Data")