Files
UnrealEngineUWP/Engine/Source/Developer/BlueprintNativeCodeGen/Private/NativeCodeGenerationTool.cpp
Mike Beach 0a0d901a8b Copying //UE4/Dev-Blueprints to //UE4/Dev-Main (Source: //UE4/Dev-Blueprints @ 3298107)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3256692 on 2017/01/13 by Ben.Cosh

	This updates the blueprint variable config option tooltip to be more accurate when describing the config to override the value in.
	#Jira UE-40334 - Blueprint variables report the wrong config file in the UI when using the set from config option
	#Proj Kismet

Change 3258553 on 2017/01/16 by Phillip.Kavan

	[UE-40131] Revised fix that will work for "inclusive" BP nativization with data-only BPs.

	- Mirrored from //UE4/Release-4.15 (CL# 3258541).

	#jira UE-40131

Change 3258958 on 2017/01/16 by Mike.Beach

	Adopted fix from UDN - resolves problems with Blueprints which inherit from UDataAsset. Compiling/Reinstancing them was leaving the data asset packages empty.

Change 3259363 on 2017/01/16 by Mike.Beach

	Revising fix in UBlueprint::BeginCacheForCookedPlatformData(), saving off nativization data if the -nativizeAssets param is present (not just if it was enabled in packaging settings).

	#jira UE-40620

Change 3260722 on 2017/01/17 by Maciej.Mroz

	Exclude client-only BPGC from Server.

	#jira UE-39728

Change 3261420 on 2017/01/17 by Dan.Oconnor

	Final prototype of the GMinimalCompileOnLoad pass

Change 3262208 on 2017/01/18 by Dan.Oconnor

	SA fix

Change 3263168 on 2017/01/18 by Dan.Oconnor

	Tweak to minimal compile on load pass, doing node refreshing early because node refresh can trigger CDO generation (which cannot happen while reinstancing, unless the new class is ready)

Change 3263844 on 2017/01/19 by Maciej.Mroz

	Error when CDO is created for an incomplete dynamic class

Change 3264647 on 2017/01/19 by Mike.Beach

	PR #3146: Only ensure if ptr != nullptr (Contributed by projectgheist )

	#jira UE-40846

Change 3264818 on 2017/01/19 by Dan.Oconnor

	Undo overzealous use of GMinimalCompileOnLoad

Change 3265075 on 2017/01/19 by Dan.Oconnor

	Make sure we use the authoritative class for the component template, fixes reinst issue in GMinimalCompileOnLoad pass

Change 3265085 on 2017/01/19 by Mike.Beach

	Mirroring CL 3260397

	Making it so CreateEvent nodes are searchable using the function name they are bound to (as requested by Jeff Farris). To find this data across your content library, in unopened Blueprints, you'll have to resave those Blueprints (so the new data is available in the asset registry).

Change 3272401 on 2017/01/25 by Mike.Beach

	Fixed a bug where modifying certain timeline settings would not dirty the Blueprint.

	PR #3137: UE-40674: Mark TimeLine BP as modified (Contributed by projectgheist)

	#jira UE-40680, UE-40674

Change 3273050 on 2017/01/26 by Maciej.Mroz

	#jira ODIN-4913, UE-40974
	merged cl3268193 from Odin branch

	Nativization:
	- added ConstructTInlineValue function
	- TInlineValue structures will be initialized using UScriptStruct::InitializeStruct, instead of callind default constructor ( default constructor is unrealible)

Change 3273052 on 2017/01/26 by Maciej.Mroz

	#jira UE-40917
	merged cl#3270456 from Odin branch

	Nativization:
	Actor template from ChildActorComponent is a subobject of nativized class.

Change 3275646 on 2017/01/27 by Dan.Oconnor

	Fix obscure issue when reinstancing interface types

Change 3275811 on 2017/01/27 by Dan.Oconnor

	ImplementsGetWorld now properly inherited for blueprint types that derive from a blueprint type that derives from a native type that "ImplementsGetWorld"

Change 3275922 on 2017/01/27 by Dan.Oconnor

	Preserve trashed properties' names, don't force regen nodes when using the new compile manager (it has already regen'd nodes)

Change 3276037 on 2017/01/27 by Dan.Oconnor

	Uses Authoritative class for this type check, added const version of GetAuthoritativeClass

Change 3276109 on 2017/01/27 by Phillip.Kavan

	[UE-40894] Fix data loss issues with non-native Blueprint classes that override inherited component default values from a nativized parent Blueprint class hierarchy.

	change summary:
	- modified FBlueprintEditorUtils::BuildComponentInstancingData() to accept an additional parameter indicating whether or not to use the CDO or the template's Archetype as the basis for building the delta property list.
	- revised UBlueprint::BeginCacheForCookedPlatformData() to first generate "override" data for ICH records that override SCS nodes from parent classes that are targeted for nativization. this also makes the optimized component instancing feature compatible with nativization as well (should that ever become useful).
	- revised UBlueprintGeneratedClass::CheckAndApplyComponentTemplateOverrides() to utilize the additional delta property list data that's now generated at cook time along with a delta serialization pass against the ICH template that's serializes changed properties to a cached data block at load time. this cached "override" data is then applied to instanced subobjects inherited from nativized parent Blueprint classes using a minimal binary serialization pass.

	#jira UE-40894

Change 3277671 on 2017/01/30 by Mike.Beach

	Mirroring CL 3276602.

	Refactoring FBlueprintCompilerCppBackend::SortNodesInUberGraphExecutionGroup() a bit. Catching cases that weren't acounted for - detecting cyclical logic now when we've pulled a node/statement out of order, and other nodes need to fall through to that logic (not relying on a goto).

	#jira UE-41188, UE-41189, UE-41186, UE-41037

Change 3278454 on 2017/01/30 by Mike.Beach

	Mirroring CL 3278054

	Upgrading USimpleConstructionScript::FixupSceneNodeHierarchy() so that the SCS detects orphaned components, and adds them to the hierarchy (notifying users of the issue with a warning).

	#jira UE-41247

Change 3278814 on 2017/01/31 by Maciej.Mroz

	fixed CIS warning
	fixed FBlueprintNativeCodeGenModule::FindReplacedNameAndOuter

Change 3279398 on 2017/01/31 by Mike.Beach

	Back out changelist 3278454 - causing unforseen issues, restructuring the component hierarchy.

Change 3282200 on 2017/02/01 by Dan.Oconnor

	Moved ForceLoad helpers into UBlueprint so that new compile on load path can prod the linker into loading stuff before flushing the compilation queue

Change 3282269 on 2017/02/01 by Mike.Beach

	ClassGeneratedBy not dependable in cooked builds, must rely on class flags to determine if this is a Blueprint class.

Change 3284455 on 2017/02/02 by Dan.Oconnor

	Reinstancer optimizations and skipping loader reset when using the new compile manager

Change 3284463 on 2017/02/02 by Dan.Oconnor

	Handling missing GeneratedClass

Change 3284476 on 2017/02/02 by Dan.Oconnor

	Flush compilation manager when we would normally do a bytecode pass, this guarantees clients of LoadObject that we won't reinstance a pointer on load (giving them back a stale object)

Change 3284523 on 2017/02/02 by Dan.Oconnor

	Optimize FBlueprintUnloader::ReplaceStaleRefs, add option to skip reinstancing when recompiling bytecode, refactored bytecode recompilation options into a flag parameter

Change 3285731 on 2017/02/03 by Dan.Oconnor

	Merging //UE4/Dev-Main to Dev-Blueprints (//UE4/Dev-Blueprints)

	Auto resolved, with merging:
	K2Node_CreateDelegate.h/cpp, KismetCompiler.cpp, WidgetBlueprintCompiler.cpp, Kismet2.cpp, KismetReinstanceUtilities.cpp/h, KismetEditorUtils.h, BlueprintSupport.cpp, Class.cpp, LinkerLoad.cpp, Obj.cpp, Class.h, Object.h, BlueprintGeneratedClass.cpp, DefaultEngine.ini,

	Manually resolved:
	BlueprintEditorUtils.cpp, TestRunner.Automation.Tests.cs, OrionAutobuyCardStatEntry.cpp/h, OrionStateWidget_DraftLobby.cpp

	All else resolved safely (no merging)

Change 3286019 on 2017/02/03 by Dan.Oconnor

	Add assertion that was added in main

Change 3286031 on 2017/02/03 by Dan.Oconnor

	Build fix, missing include

Change 3286056 on 2017/02/03 by Mike.Beach

	Corrected fix (from CL 3278454, which had to be backed out) - USimpleConstructionScript::FixupSceneNodeHierarchy() so that the SCS detects orphaned components, and adds them to the hierarchy (notifying users of the issue with a warning).

	#jira UE-41247

Change 3286302 on 2017/02/03 by Dan.Oconnor

	Allow reinstancing to run very early or in other situation where GEditor is not yet set up

Change 3286386 on 2017/02/03 by Dan.Oconnor

	GMinimalCompileOnLoad checks no longer needed with my local changes to BlueprintCompilationManager

Change 3286391 on 2017/02/03 by Dan.Oconnor

	Missed old comment

Change 3286614 on 2017/02/03 by Dan.Oconnor

	GMinimalCompileOnLoad logic no longer needed

Change 3286655 on 2017/02/03 by Dan.Oconnor

	Refactor FKismetEditorUtilities::CompileBlueprint flags into EBlueprintCompileOptions

Change 3286662 on 2017/02/03 by Dan.Oconnor

	Build fix, missed file

Change 3288770 on 2017/02/06 by Mike.Beach

	Attempt to fix up CIS warnings from CL 3286056.

Change 3289236 on 2017/02/06 by Mike.Beach

	Missed fix for CIS warning.

Change 3289276 on 2017/02/06 by Dan.Oconnor

	Duplication of CDO is unnecessary
	#fyi Maciej.Mroz

Change 3289334 on 2017/02/06 by Dan.Oconnor

	Add option to skip all reinstancing logic when running CompileBlueprint - used locally by the blueprint compilation manager. Fixed Typo.

Change 3289443 on 2017/02/06 by Dan.Oconnor

	Further cleanup of GMinimalCompileOnLoad abuse. added flag to skip reinstancing and "stub on failure" compile pass

Change 3290509 on 2017/02/07 by Dan.Oconnor

	Addressed this with a change to the blueprint compiler manager - no modification needed

Change 3290534 on 2017/02/07 by Dan.Oconnor

	Remove old forward declare and outdated comment

Change 3291446 on 2017/02/07 by Dan.Oconnor

	This CPFUO call is unused with my latest iteration on the compiler manager

Change 3291516 on 2017/02/07 by Dan.Oconnor

	Running compile manager earlier means we don't need to worry about this weird (and costly) call

Change 3291534 on 2017/02/07 by Dan.Oconnor

	This compile children call is no longer running with latest improvents to the compile manager

Change 3292587 on 2017/02/08 by Maciej.Mroz

	#jira UE-41694
	Mirroring cl#3292273 from Odin branch

Change 3293344 on 2017/02/08 by Dan.Oconnor

	Iteration on blueprint compile manager - fortnite loads without issue. For now I do the three compile passes that are done by the existing load paths. Timing is actually quite reasonable. Centralizing reinstancing has sped things up.

	#fyi Maciej.Mroz

Change 3293565 on 2017/02/08 by Dan.Oconnor

	Back out changelist 3293344 -  wrong CL

Change 3293567 on 2017/02/08 by Dan.Oconnor

	Iteration on blueprint compile manager - fortnite loads without issue. For now I do the three compile passes that are done by the existing load paths. Timing is actually quite reasonable. Centralizing reinstancing has sped things up.

	#fyi Maciej.Mroz

Change 3294334 on 2017/02/09 by Phillip.Kavan

	[UE-41246] Fix misaligned memory access of noexport struct properties leading to incorrectly initialized values.

	- Mirrored from //Odin/Main/... (CL# 3284308).

	#jira UE-41246

Change 3294343 on 2017/02/09 by Phillip.Kavan

	[UE-41246] Add a whitelist mechanism to handle native noexport types that can support direct field access in nativized Blueprint code.

	- Mirrored from //Odin/Main/... (CL# 3285789).

	#jira UE-41246

Change 3295913 on 2017/02/09 by Dan.Oconnor

	Back out reinstancer optimization, failing to find a reference and it's causing a crash when a component is renamed
	#jira UE-41843

Change 3297279 on 2017/02/10 by Dan.Oconnor

	SA fix

Change 3297587 on 2017/02/10 by Mike.Beach

	Temporarily disabling a spurious warning that gets triggered in Fortnite, when correctly excluding client-only Blueprints.

	#jira UE-41880

Change 3298078 on 2017/02/10 by Dan.Oconnor

	Try to suppress confused SA warning

[CL 3298251 by Mike Beach in Main branch]
2017-02-10 19:50:34 -05:00

385 lines
11 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "NativeCodeGenerationTool.h"
#include "Input/Reply.h"
#include "Misc/Paths.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/SCompoundWidget.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/SWindow.h"
#include "Widgets/Text/STextBlock.h"
#include "Engine/BlueprintGeneratedClass.h"
#include "Engine/UserDefinedEnum.h"
#include "Engine/UserDefinedStruct.h"
#include "Editor.h"
#include "Widgets/Layout/SBorder.h"
#include "HAL/FileManager.h"
#include "Misc/FileHelper.h"
#include "Misc/ScopedSlowTask.h"
#include "Misc/App.h"
#include "Modules/ModuleManager.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Input/SMultiLineEditableTextBox.h"
#include "Widgets/Input/SButton.h"
#include "Widgets/Notifications/SErrorText.h"
#include "EditorStyleSet.h"
#include "SourceCodeNavigation.h"
#include "DesktopPlatformModule.h"
#include "IBlueprintCompilerCppBackendModule.h"
#include "BlueprintNativeCodeGenUtils.h"
//#include "Editor/KismetCompiler/Public/BlueprintCompilerCppBackendInterface.h"
#include "BlueprintCompilerCppBackendGatherDependencies.h"
#include "KismetCompilerModule.h"
#include "Widgets/Input/SDirectoryPicker.h"
#include "SourceCodeNavigation.h"
#define LOCTEXT_NAMESPACE "NativeCodeGenerationTool"
//
// THE CODE SHOULD BE MOVED TO GAMEPROJECTGENERATION
//
struct FGeneratedCodeData
{
FGeneratedCodeData(UBlueprint& InBlueprint)
: Blueprint(&InBlueprint)
{
FName GeneratedClassName, SkeletonClassName;
InBlueprint.GetBlueprintClassNames(GeneratedClassName, SkeletonClassName);
ClassName = GeneratedClassName.ToString();
IBlueprintCompilerCppBackendModule& CodeGenBackend = (IBlueprintCompilerCppBackendModule&)IBlueprintCompilerCppBackendModule::Get();
BaseFilename = CodeGenBackend.ConstructBaseFilename(&InBlueprint);
GatherUserDefinedDependencies(InBlueprint);
}
FString TypeDependencies;
FString ErrorString;
FString ClassName;
FString BaseFilename;
TWeakObjectPtr<UBlueprint> Blueprint;
TSet<UField*> DependentObjects;
TSet<UBlueprintGeneratedClass*> UnconvertedNeededClasses;
void GatherUserDefinedDependencies(UBlueprint& InBlueprint)
{
FGatherConvertedClassDependencies ClassDependencies(InBlueprint.GeneratedClass);
for (auto Iter : ClassDependencies.ConvertedClasses)
{
DependentObjects.Add(Iter);
}
for (auto Iter : ClassDependencies.ConvertedStructs)
{
DependentObjects.Add(Iter);
}
for (auto Iter : ClassDependencies.ConvertedEnum)
{
DependentObjects.Add(Iter);
}
if (DependentObjects.Num())
{
TypeDependencies = LOCTEXT("ConvertedDependencies", "Detected Dependencies:\n").ToString();
}
else
{
TypeDependencies = LOCTEXT("NoConvertedAssets", "No dependencies found.\n").ToString();
}
for (auto Obj : DependentObjects)
{
TypeDependencies += FString::Printf(TEXT("%s \t%s\n"), *Obj->GetClass()->GetName(), *Obj->GetPathName());
}
DependentObjects.Add(InBlueprint.GeneratedClass);
bool bUnconvertedHeader = false;
for (auto Asset : ClassDependencies.Assets)
{
if (auto BPGC = Cast<UBlueprintGeneratedClass>(Asset))
{
UnconvertedNeededClasses.Add(BPGC);
if (!bUnconvertedHeader)
{
bUnconvertedHeader = true;
TypeDependencies += LOCTEXT("NoConvertedDependencies", "\nUnconverted Dependencies, that require a warpper struct:\n").ToString();
}
TypeDependencies += FString::Printf(TEXT("%s \t%s\n"), *BPGC->GetClass()->GetName(), *BPGC->GetPathName());
}
}
}
static FString DefaultHeaderDir()
{
auto DefaultSourceDir = FPaths::ConvertRelativePathToFull(FPaths::GameIntermediateDir());
return FPaths::Combine(*DefaultSourceDir, TEXT("NativizationTest"), TEXT("Public"));
}
static FString DefaultSourceDir()
{
auto DefaultSourceDir = FPaths::ConvertRelativePathToFull(FPaths::GameIntermediateDir());
return FPaths::Combine(*DefaultSourceDir, TEXT("NativizationTest"), TEXT("Private"));
}
FString HeaderFileName() const
{
return BaseFilename + TEXT(".h");
}
FString SourceFileName() const
{
return BaseFilename + TEXT(".cpp");
}
bool Save(const FString& HeaderDirPath, const FString& CppDirPath)
{
if (!Blueprint.IsValid())
{
ErrorString += LOCTEXT("InvalidBlueprint", "Invalid Blueprint\n").ToString();
return false;
}
const int WorkParts = 3 +(4 * DependentObjects.Num());
FScopedSlowTask SlowTask(WorkParts, LOCTEXT("GeneratingCppFiles", "Generating C++ files.."));
SlowTask.MakeDialog();
IBlueprintCompilerCppBackendModule& CodeGenBackend = (IBlueprintCompilerCppBackendModule&)IBlueprintCompilerCppBackendModule::Get();
TArray<FString> CreatedFiles;
//for(auto Obj : DependentObjects)
UObject* Obj = Blueprint->GeneratedClass;
{
SlowTask.EnterProgressFrame();
TSharedPtr<FString> HeaderSource(new FString());
TSharedPtr<FString> CppSource(new FString());
TSharedPtr<FNativizationSummary> NativizationSummary(new FNativizationSummary());
FBlueprintNativeCodeGenUtils::GenerateCppCode(Obj, HeaderSource, CppSource, NativizationSummary, FCompilerNativizationOptions{});
SlowTask.EnterProgressFrame();
const FString BackendBaseFilename = CodeGenBackend.ConstructBaseFilename(Obj);
const FString FullHeaderFilename = FPaths::Combine(*HeaderDirPath, *(BackendBaseFilename + TEXT(".h")));
const bool bHeaderSaved = FFileHelper::SaveStringToFile(*HeaderSource, *FullHeaderFilename);
if (!bHeaderSaved)
{
ErrorString += FString::Printf(*LOCTEXT("HeaderNotSaved", "Header file wasn't saved. Check log for details. %s\n").ToString(), *Obj->GetPathName());
}
else
{
CreatedFiles.Add(FullHeaderFilename);
}
SlowTask.EnterProgressFrame();
if (!CppSource->IsEmpty())
{
const FString NewCppFilename = FPaths::Combine(*CppDirPath, *(BackendBaseFilename + TEXT(".cpp")));
const bool bCppSaved = FFileHelper::SaveStringToFile(*CppSource, *NewCppFilename);
if (!bCppSaved)
{
ErrorString += FString::Printf(*LOCTEXT("CppNotSaved", "Cpp file wasn't saved. Check log for details. %s\n").ToString(), *Obj->GetPathName());
}
else
{
CreatedFiles.Add(NewCppFilename);
}
}
}
SlowTask.EnterProgressFrame();
bool bSuccess = ErrorString.IsEmpty();
if (bSuccess && CreatedFiles.Num() > 0)
{
// assume the last element is the target cpp file
FSourceCodeNavigation::OpenSourceFile(CreatedFiles.Last());
}
return bSuccess;
}
};
class SNativeCodeGenerationDialog : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SNativeCodeGenerationDialog){}
SLATE_ARGUMENT(TSharedPtr<SWindow>, ParentWindow)
SLATE_ARGUMENT(TSharedPtr<FGeneratedCodeData>, GeneratedCodeData)
SLATE_END_ARGS()
private:
// Child widgets
TSharedPtr<SDirectoryPicker> HeaderDirectoryBrowser;
TSharedPtr<SDirectoryPicker> SourceDirectoryBrowser;
TSharedPtr<SErrorText> ErrorWidget;
//
TWeakPtr<SWindow> WeakParentWindow;
TSharedPtr<FGeneratedCodeData> GeneratedCodeData;
bool bSaved;
void CloseParentWindow()
{
auto ParentWindow = WeakParentWindow.Pin();
if (ParentWindow.IsValid())
{
ParentWindow->RequestDestroyWindow();
}
}
bool IsEditable() const
{
return !bSaved && GeneratedCodeData->ErrorString.IsEmpty();
}
FReply OnButtonClicked()
{
bSaved = GeneratedCodeData->Save(HeaderDirectoryBrowser->GetDirectory(), SourceDirectoryBrowser->GetDirectory());
ErrorWidget->SetError(GeneratedCodeData->ErrorString);
return FReply::Handled();
}
FText ButtonText() const
{
return IsEditable() ? LOCTEXT("Generate", "Generate") : LOCTEXT("Regenerate", "Regenerate");
}
FText GetClassName() const
{
return GeneratedCodeData.IsValid() ? FText::FromString(GeneratedCodeData->ClassName) : FText::GetEmpty();
}
public:
void Construct(const FArguments& InArgs)
{
GeneratedCodeData = InArgs._GeneratedCodeData;
bSaved = false;
WeakParentWindow = InArgs._ParentWindow;
ChildSlot
[
SNew(SBorder)
.Padding(4.f)
.BorderImage(FEditorStyle::GetBrush("ToolPanel.GroupBorder"))
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ClassName", "Class Name"))
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SNew(STextBlock)
.Text(this, &SNativeCodeGenerationDialog::GetClassName)
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HeaderPath", "Header Path"))
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SAssignNew(HeaderDirectoryBrowser, SDirectoryPicker)
.Directory(FGeneratedCodeData::DefaultHeaderDir())
.File(GeneratedCodeData->HeaderFileName())
.Message(LOCTEXT("HeaderDirectory", "Header Directory"))
.IsEnabled(this, &SNativeCodeGenerationDialog::IsEditable)
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("SourcePath", "Source Path"))
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SAssignNew(SourceDirectoryBrowser, SDirectoryPicker)
.Directory(FGeneratedCodeData::DefaultSourceDir())
.File(GeneratedCodeData->SourceFileName())
.Message(LOCTEXT("SourceDirectory", "Source Directory"))
.IsEnabled(this, &SNativeCodeGenerationDialog::IsEditable)
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("Dependencies", "Dependencies"))
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SNew(SBox)
.WidthOverride(360.0f)
.HeightOverride(200.0f)
[
SNew(SMultiLineEditableTextBox)
.IsReadOnly(true)
.Text(FText::FromString(GeneratedCodeData->TypeDependencies))
]
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
[
SAssignNew(ErrorWidget, SErrorText)
]
+ SVerticalBox::Slot()
.Padding(4.0f)
.AutoHeight()
.HAlign(HAlign_Right)
[
SNew(SButton)
.Text(this, &SNativeCodeGenerationDialog::ButtonText)
.OnClicked(this, &SNativeCodeGenerationDialog::OnButtonClicked)
]
]
];
ErrorWidget->SetError(GeneratedCodeData->ErrorString);
}
};
void FNativeCodeGenerationTool::Open(UBlueprint& Blueprint, TSharedRef< class FBlueprintEditor> Editor)
{
TSharedRef<FGeneratedCodeData> GeneratedCodeData(new FGeneratedCodeData(Blueprint));
TSharedRef<SWindow> PickerWindow = SNew(SWindow)
.Title(LOCTEXT("GenerateNativeCode", "Generate Native Code"))
.SizingRule(ESizingRule::Autosized)
.ClientSize(FVector2D(0.f, 300.f))
.SupportsMaximize(false)
.SupportsMinimize(false);
TSharedRef<SNativeCodeGenerationDialog> CodeGenerationDialog = SNew(SNativeCodeGenerationDialog)
.ParentWindow(PickerWindow)
.GeneratedCodeData(GeneratedCodeData);
PickerWindow->SetContent(CodeGenerationDialog);
GEditor->EditorAddModalWindow(PickerWindow);
}
bool FNativeCodeGenerationTool::CanGenerate(const UBlueprint& Blueprint)
{
return (Blueprint.Status == EBlueprintStatus::BS_UpToDate || Blueprint.Status == EBlueprintStatus::BS_UpToDateWithWarnings)
&& (Blueprint.BlueprintType == EBlueprintType::BPTYPE_Normal || Blueprint.BlueprintType == EBlueprintType::BPTYPE_FunctionLibrary)
&& Cast<UBlueprintGeneratedClass>(Blueprint.GeneratedClass);
}
#undef LOCTEXT_NAMESPACE