A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
SDialogueActionMenu.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
3
4#include "EdGraph/EdGraph.h"
5#include "EditorStyleSet.h"
6#include "Framework/Application/SlateApplication.h"
7
8
10// SDialogueActionMenu
16
17void SDialogueActionMenu::Construct(const FArguments& InArgs)
18{
19 bActionExecuted = false;
20 Graph = InArgs._Graph;
21 DraggedFromPins = InArgs._DraggedFromPins;
22 NewNodePosition = InArgs._NewNodePosition;
23 OnClosedCallback = InArgs._OnClosedCallback;
24 AutoExpandActionMenu = InArgs._AutoExpandActionMenu;
25 OnCloseReasonCallback = InArgs._OnCloseReason;
26
27 // Build the widget layout
28 SBorder::Construct(SBorder::FArguments()
29 .BorderImage(FEditorStyle::GetBrush("Menu.Background"))
30 .Padding(5)
31 [
32 // Achieving fixed width by nesting items within a fixed width box.
33 SNew(SBox)
34 .WidthOverride(400)
35 .HeightOverride(400)
36 [
37 SAssignNew(GraphActionMenu, SGraphActionMenu)
39 .OnCollectAllActions(this, &Self::CollectAllActions)
41 ]
42 ]
43 );
44}
45
46void SDialogueActionMenu::CollectAllActions(FGraphActionListBuilderBase& OutAllActions)
47{
48 // Build up the context object
49 FGraphContextMenuBuilder ContextMenuBuilder(Graph);
50 if (DraggedFromPins.Num() > 0)
51 {
52 ContextMenuBuilder.FromPin = DraggedFromPins[0];
53 }
54
55 // Determine all possible actions
56 Graph->GetSchema()->GetGraphContextActions(ContextMenuBuilder);
57
58 // Copy the added options back to the main list
59 OutAllActions.Append(ContextMenuBuilder);
60}
61
62void SDialogueActionMenu::OnActionSelected(const TArray<TSharedPtr<FEdGraphSchemaAction>>& SelectedAction, ESelectInfo::Type InSelectionType)
63{
64 if (!IsValid(Graph))
65 {
66 return;
67 }
68
69 if (InSelectionType == ESelectInfo::OnMouseClick || InSelectionType == ESelectInfo::OnKeyPress || SelectedAction.Num() == 0)
70 {
71 for (int32 ActionIndex = 0; ActionIndex < SelectedAction.Num(); ActionIndex++)
72 {
73 TSharedPtr<FEdGraphSchemaAction> CurrentAction = SelectedAction[ActionIndex];
74
75 if (CurrentAction.IsValid())
76 {
77 if (!bActionExecuted)
78 {
79 FSlateApplication::Get().DismissAllMenus();
80 bActionExecuted = true;
81 }
82
83 CurrentAction->PerformAction(Graph, DraggedFromPins, NewNodePosition);
84 }
85 }
86 }
87}
TSharedPtr< SGraphActionMenu > GraphActionMenu
void Construct(const FArguments &InArgs)
TArray< UEdGraphPin * > DraggedFromPins
void OnActionSelected(const TArray< TSharedPtr< FEdGraphSchemaAction > > &SelectedAction, ESelectInfo::Type InSelectionType)
FDialogueActionMenuClosedReason OnCloseReasonCallback
void CollectAllActions(FGraphActionListBuilderBase &OutAllActions)
SGraphEditor::FActionMenuClosed OnClosedCallback