A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
SGraphNode_DialogueK2Switch.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
3
4#include "ScopedTransaction.h"
5#include "Widgets/SBoxPanel.h"
6#include "Widgets/Images/SImage.h"
7#include "GraphEditorSettings.h"
8#include "NodeFactory.h"
9#include "KismetPins/SGraphPinExec.h"
10#include "Kismet2/BlueprintEditorUtils.h"
11#include "K2Node_Switch.h"
12
14
15
17// SGraphPinSwitchNodeDefaultCaseExec
19{
20public:
22 SLATE_END_ARGS()
23
24 void Construct(const FArguments& InArgs, UEdGraphPin* InPin)
25 {
26 SGraphPin::Construct(SGraphPin::FArguments().PinLabelStyle(FName("Graph.Node.DefaultPinName")), InPin);
27 CachePinIcons();
28 }
29};
30
32// SGraphNode_DialogueK2Switch
34{
35 GraphNode = CastChecked<UEdGraphNode>(InNode);
36 DialogueK2Node_Switch = InNode;
37
38 SetCursor(EMouseCursor::CardinalCross);
39 UpdateGraphNode();
40}
41
43{
44 UK2Node_Switch* SwitchNode = CastChecked<UK2Node_Switch>(GraphNode);
45 UEdGraphPin* DefaultPin = SwitchNode->GetDefaultPin();
46
47 // Create Pin widgets for each of the pins, except for the default pin
48 for (UEdGraphPin* CurrentPin : GraphNode->Pins)
49 {
50 if (!CurrentPin->bHidden && CurrentPin != DefaultPin)
51 {
52 TSharedPtr<SGraphPin> NewPin = FNodeFactory::CreatePinWidget(CurrentPin);
53 check(NewPin.IsValid());
54 AddPin(NewPin.ToSharedRef());
55 }
56 }
57
58 // Handle the default pin
59 if (DefaultPin != nullptr)
60 {
61 // Create some padding
62 RightNodeBox->AddSlot()
63 .AutoHeight()
64 .HAlign(HAlign_Right)
65 .VAlign(VAlign_Center)
66 .Padding(1.0f)
67 [
68 SNew(SImage)
69 .Image(FEditorStyle::GetBrush("Graph.Pin.DefaultPinSeparator"))
70 ];
71
72 // Create the pin itself
73 TSharedPtr<SGraphPin> NewPin = SNew(SGraphPinSwitchNodeDefaultCaseExec, DefaultPin);
74 AddPin(NewPin.ToSharedRef());
75 }
76}
77
78void SGraphNode_DialogueK2Switch::CreateOutputSideAddButton(TSharedPtr<SVerticalBox> OutputBox)
79{
80 TSharedRef<SWidget> AddPinButton = AddPinButtonContent(
81 NSLOCTEXT("SwitchStatementNode", "RefreshNodeButton", "Refresh Node"),
82 NSLOCTEXT("SwitchStatementNode", "RefreshNodeButton_Tooltip", "Refreshes the node with the dialogue values"));
83
84 FMargin AddPinPadding = Settings->GetOutputPinPadding();
85 AddPinPadding.Top += 6.0f;
86
87 OutputBox->AddSlot()
88 .AutoHeight()
89 .VAlign(VAlign_Center)
90 .Padding(AddPinPadding)
91 [
92 AddPinButton
93 ];
94}
95
97{
98 return EVisibility::Visible;
99}
100
102{
103 const FScopedTransaction Transaction(NSLOCTEXT("Kismet", "RefreshNode", "Refresh Node"));
104 DialogueK2Node_Switch->Modify();
105 FBlueprintEditorUtils::MarkBlueprintAsModified(DialogueK2Node_Switch->GetBlueprint());
106
107 // Reconstruct and notify
108 DialogueK2Node_Switch->ReconstructNode();
109 UpdateGraphNode();
110 GraphNode->GetGraph()->NotifyGraphChanged();
111
112 return FReply::Handled();
113}
void CreateOutputSideAddButton(TSharedPtr< SVerticalBox > OutputBox) override
UDialogueK2Node_SwitchDialogueCallback * DialogueK2Node_Switch
void Construct(const FArguments &InArgs, UDialogueK2Node_SwitchDialogueCallback *InNode)
EVisibility IsAddPinButtonVisible() const override
void Construct(const FArguments &InArgs, UEdGraphPin *InPin)
SLATE_BEGIN_ARGS(SGraphPinSwitchNodeDefaultCaseExec)