A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueObject_CustomRowHelper.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
3
4#include "PropertyHandle.h"
5#include "DetailWidgetRow.h"
6#include "Widgets/Input/SButton.h"
7#include "Widgets/Input/SComboButton.h"
8#include "Widgets/Layout/SUniformGridPanel.h"
9#include "Internationalization/TextNamespaceUtil.h"
11#include "Editor.h"
13#include "Kismet2/KismetEditorUtilities.h"
14#include "Engine/Blueprint.h"
15#include "Kismet2/BlueprintEditorUtils.h"
16#include "Widgets/Images/SImage.h"
17#include "K2Node_Event.h"
18#include "SourceCodeNavigation.h"
19
20#define LOCTEXT_NAMESPACE "DialogueObject_CustomRowHelper"
21#define DEFAULT_FONT(...) FCoreStyle::GetDefaultFontStyle(__VA_ARGS__)
22
24// FDialogueObject_CustomRowHelper
26 PropertyRow(InPropertyRow)
27{
28}
29
31{
32 // SPropertyEditorClass for Classes
33 // SPropertyEditorAsset for EditInlineNew ?
34
35 // Get Default widgets
36 TSharedPtr<SWidget> DefaultNameWidget;
37 TSharedPtr<SWidget> DefaultValueWidget;
38 PropertyRow->GetDefaultWidgets(
39 DefaultNameWidget,
40 DefaultValueWidget,
41 false
42 );
43
44 FDetailWidgetRow& DetailWidgetRow = PropertyRow->CustomWidget(true);
45 DetailWidgetRow.NameContent()
46 [
47 DefaultNameWidget.ToSharedRef()
48 ];
49
50 TSharedPtr<SHorizontalBox> HorizontalBox;
51 DetailWidgetRow.ValueContent()
52 .MinDesiredWidth(GetRowMinimumDesiredWidth())
53 [
54 SAssignNew(HorizontalBox, SHorizontalBox)
55 ];
56
57 // Default previous widget
58 HorizontalBox->AddSlot()
59 .Padding(0.f, 0.f, 2.f, 0.f)
60 .FillWidth(1.f)
61 // .AutoWidth()
62 [
63 DefaultValueWidget.ToSharedRef()
64 ];
65
66 // Browse Asset
67 HorizontalBox->AddSlot()
68 .AutoWidth()
69 .VAlign(VAlign_Center)
70 .Padding(4.f)
71 [
72 SNew(SButton)
73 .ButtonStyle(FEditorStyle::Get(), "HoverHintOnly")
74 .ToolTipText(this, &Self::GetBrowseObjectText)
75 .ContentPadding(4.f)
76 .ForegroundColor(FSlateColor::UseForeground())
77 .Visibility(this, &Self::GetBrowseButtonVisibility)
78 .OnClicked(this, &Self::OnBrowseClicked)
79 [
80 SNew(SImage)
81 .Image(FEditorStyle::GetBrush("PropertyWindow.Button_Browse"))
82 .ColorAndOpacity(FSlateColor::UseForeground())
83 ]
84 ];
85
86 // Jump to Object
87 HorizontalBox->AddSlot()
88 .AutoWidth()
89 .VAlign(VAlign_Center)
90 .Padding(4.f, 2.f)
91 [
92 SNew(SButton)
93 .ButtonStyle(FEditorStyle::Get(), "HoverHintOnly")
94 .ToolTipText(this, &Self::GetJumpToObjectText)
95 .ContentPadding(4.f)
96 .ForegroundColor(FSlateColor::UseForeground())
97 .Visibility(this, &Self::GetOpenButtonVisibility)
98 .OnClicked(this, &Self::OnOpenClicked)
99 [
100 SNew(SImage)
101 .Image(FEditorStyle::GetBrush("PropertyWindow.Button_Edit"))
102 .ColorAndOpacity( FSlateColor::UseForeground() )
103
104 // SNew(STextBlock)
105 // .Text(LOCTEXT("OpenObjectKey", "Open"))
106 // .Font(DEFAULT_FONT("Regular", 10))
107 ]
108 ];
109}
110
112{
113 if (!PropertyRow)
114 {
115 return nullptr;
116 }
117
118 TSharedPtr<IPropertyHandle> PropertyHandle = PropertyRow->GetPropertyHandle();
119 if (!PropertyHandle.IsValid())
120 {
121 return nullptr;
122 }
123 UObject* Object = nullptr;
124 PropertyHandle->GetValue(Object);
125 return Object;
126}
127
129{
131 if (!Object)
132 {
133 return nullptr;
134 }
135
136 // Class
137 UClass* Class = Object->GetClass();
138 if (const UBlueprintGeneratedClass* BlueprintClass = Cast<UBlueprintGeneratedClass>(Class))
139 {
140 if (UBlueprint* Blueprint = Cast<UBlueprint>(BlueprintClass->ClassGeneratedBy))
141 {
142 return Blueprint;
143 }
144 }
145
146 return Cast<UBlueprint>(Object);
147}
148
149
151{
152 return GetBlueprint() != nullptr;
153}
154
156{
157 if (!GEditor)
158 {
159 return FReply::Handled();
160 }
161
162 static constexpr bool bFocusContentBrowser = true;
163 TArray<UObject*> ObjectsToSyncTo;
164 if (UBlueprint* Blueprint = GetBlueprint())
165 {
166 ObjectsToSyncTo.Add(Blueprint);
167 }
168 GEditor->SyncBrowserToObjects(ObjectsToSyncTo, bFocusContentBrowser);
169
170 return FReply::Handled();
171}
172
174{
175 if (UBlueprint* Blueprint = GetBlueprint())
176 {
178 Blueprint,
179 OpenType,
183 );
184 }
185 else if (UObject* Object = GetObject())
186 {
187 // Native
188 FSourceCodeNavigation::NavigateToClass(Object->GetClass());
189 }
190
191 return FReply::Handled();
192}
193
195{
196 return LOCTEXT("BrowseButtonToolTipText", "Browse to Asset in Content Browser");
197}
198
200{
201 if (IsObjectABlueprint())
202 {
203 return LOCTEXT("OpenObjectBlueprintTooltipKey", "Open Blueprint Editor");
204 }
205
206 // Native Class
207 return FText::Format(
208 LOCTEXT("OpenObjectBlueprintTooltipKey", "Open Source File in {0}"),
209 FSourceCodeNavigation::GetSelectedSourceCodeIDE()
210 );
211}
212
214{
215 if (!CanBeVisible())
216 {
217 return EVisibility::Collapsed;
218 }
219
220 if (UObject* Object = GetObject())
221 {
222 // Blueprint
223 if (IsObjectABlueprint())
224 {
225 return EVisibility::Visible;
226 }
227
228 // Native
229 return FSourceCodeNavigation::CanNavigateToClass(Object->GetClass()) ? EVisibility::Visible : EVisibility::Collapsed;
230 }
231
232 return EVisibility::Collapsed;
233}
234
236{
237 if (!CanBeVisible())
238 {
239 return EVisibility::Collapsed;
240 }
241
242 return IsObjectABlueprint() ? EVisibility::Visible : EVisibility::Collapsed;
243}
244
245#undef LOCTEXT_NAMESPACE
246#undef DEFAULT_FONT
static bool OpenBlueprintEditor(UBlueprint *Blueprint, EDialogueBlueprintOpenType OpenType=EDialogueBlueprintOpenType::None, FName FunctionNameToOpen=NAME_None, bool bForceFullEditor=true, bool bAddBlueprintFunctionIfItDoesNotExist=false)
FDialogueObject_CustomRowHelper(IDetailPropertyRow *InPropertyRow)