2021-01-18 12:50:54 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#include "SNewLevelInstanceDialog.h"
|
2021-01-20 12:26:28 -04:00
|
|
|
#include "IStructureDetailsView.h"
|
|
|
|
|
#include "IDetailPropertyRow.h"
|
|
|
|
|
#include "DetailCategoryBuilder.h"
|
|
|
|
|
#include "DetailWidgetRow.h"
|
2021-01-18 12:50:54 -04:00
|
|
|
#include "Widgets/Layout/SSpacer.h"
|
2021-01-20 12:26:28 -04:00
|
|
|
#include "Widgets/Input/SComboBox.h"
|
|
|
|
|
#include "Widgets/Input/SButton.h"
|
|
|
|
|
#include "PropertyEditorDelegates.h"
|
2021-01-18 12:50:54 -04:00
|
|
|
#include "LevelInstance/LevelInstanceSubsystem.h"
|
2021-01-20 12:26:28 -04:00
|
|
|
#include "Modules/ModuleManager.h"
|
|
|
|
|
#include "GameFramework/Actor.h"
|
2021-01-18 12:50:54 -04:00
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "LevelInstanceEditor"
|
|
|
|
|
|
2021-01-20 12:26:28 -04:00
|
|
|
const FVector2D SNewLevelInstanceDialog::DEFAULT_WINDOW_SIZE = FVector2D(400, 250);
|
2021-01-18 12:50:54 -04:00
|
|
|
|
|
|
|
|
void SNewLevelInstanceDialog::Construct(const FArguments& InArgs)
|
|
|
|
|
{
|
|
|
|
|
ParentWindowPtr = InArgs._ParentWindow.Get();
|
|
|
|
|
bClickedOk = false;
|
2021-01-20 12:26:28 -04:00
|
|
|
|
|
|
|
|
FPropertyEditorModule& PropertyEditorModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
|
|
|
|
|
|
|
|
|
|
TSharedPtr<IStructureDetailsView> StructureDetailsView;
|
|
|
|
|
|
|
|
|
|
FDetailsViewArgs DetailsViewArgs;
|
|
|
|
|
{
|
|
|
|
|
DetailsViewArgs.bAllowSearch = false;
|
|
|
|
|
DetailsViewArgs.bHideSelectionTip = true;
|
|
|
|
|
DetailsViewArgs.bLockable = false;
|
|
|
|
|
DetailsViewArgs.bSearchInitialKeyFocus = true;
|
|
|
|
|
DetailsViewArgs.bUpdatesFromSelection = false;
|
|
|
|
|
DetailsViewArgs.NotifyHook = nullptr;
|
|
|
|
|
DetailsViewArgs.bShowOptions = true;
|
|
|
|
|
DetailsViewArgs.bShowModifiedPropertiesOption = false;
|
|
|
|
|
DetailsViewArgs.bShowScrollBar = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FStructureDetailsViewArgs StructureViewArgs;
|
|
|
|
|
{
|
|
|
|
|
StructureViewArgs.bShowObjects = true;
|
|
|
|
|
StructureViewArgs.bShowAssets = true;
|
|
|
|
|
StructureViewArgs.bShowClasses = true;
|
|
|
|
|
StructureViewArgs.bShowInterfaces = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StructureDetailsView = PropertyEditorModule.CreateStructureDetailView(DetailsViewArgs, StructureViewArgs, nullptr);
|
|
|
|
|
StructureDetailsView->GetDetailsView()->SetGenericLayoutDetailsDelegate(FOnGetDetailCustomizationInstance::CreateStatic(&FNewLevelInstanceParamsDetails::MakeInstance, InArgs._PivotActors.Get()));
|
|
|
|
|
|
|
|
|
|
FStructOnScope* Struct = new FStructOnScope(FNewLevelInstanceParams::StaticStruct(), (uint8*)&CreationParams);
|
|
|
|
|
StructureDetailsView->SetStructureData(MakeShareable(Struct));
|
2021-01-18 12:50:54 -04:00
|
|
|
|
|
|
|
|
this->ChildSlot
|
|
|
|
|
[
|
|
|
|
|
SNew(SBorder)
|
|
|
|
|
.BorderImage(FEditorStyle::GetBrush("ToolPanel.GroupBorder"))
|
|
|
|
|
[
|
|
|
|
|
SNew(SVerticalBox)
|
|
|
|
|
+ SVerticalBox::Slot()
|
2021-01-20 12:54:33 -04:00
|
|
|
.AutoHeight()
|
2021-01-18 12:50:54 -04:00
|
|
|
[
|
2021-01-20 12:54:33 -04:00
|
|
|
SNew(SHorizontalBox)
|
|
|
|
|
+ SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
[
|
|
|
|
|
StructureDetailsView->GetWidget()->AsShared()
|
|
|
|
|
]
|
2021-01-18 12:50:54 -04:00
|
|
|
]
|
|
|
|
|
+ SVerticalBox::Slot()
|
|
|
|
|
.AutoHeight()
|
|
|
|
|
[
|
|
|
|
|
SNew(SHorizontalBox)
|
|
|
|
|
+ SHorizontalBox::Slot()
|
|
|
|
|
.FillWidth(1.f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SSpacer)
|
|
|
|
|
]
|
|
|
|
|
+ SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
.Padding(2.f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SButton)
|
|
|
|
|
.HAlign(HAlign_Center)
|
|
|
|
|
.IsEnabled(this, &SNewLevelInstanceDialog::IsOkEnabled)
|
|
|
|
|
.ContentPadding(FEditorStyle::GetMargin("StandardDialog.ContentPadding"))
|
|
|
|
|
.OnClicked(this, &SNewLevelInstanceDialog::OnOkClicked)
|
|
|
|
|
.Text(LOCTEXT("OkButton", "Ok"))
|
|
|
|
|
]
|
|
|
|
|
+ SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
.Padding(2.f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SButton)
|
|
|
|
|
.HAlign(HAlign_Center)
|
|
|
|
|
.ContentPadding(FEditorStyle::GetMargin("StandardDialog.ContentPadding"))
|
|
|
|
|
.OnClicked(this, &SNewLevelInstanceDialog::OnCancelClicked)
|
|
|
|
|
.Text(LOCTEXT("CancelButton", "Cancel"))
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SNewLevelInstanceDialog::IsOkEnabled() const
|
|
|
|
|
{
|
2021-01-20 12:26:28 -04:00
|
|
|
if (CreationParams.PivotType == ELevelInstancePivotType::Actor && !CreationParams.PivotActor)
|
2021-01-18 12:50:54 -04:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FReply SNewLevelInstanceDialog::OnOkClicked()
|
|
|
|
|
{
|
|
|
|
|
bClickedOk = true;
|
|
|
|
|
ParentWindowPtr.Pin()->RequestDestroyWindow();
|
|
|
|
|
return FReply::Handled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FReply SNewLevelInstanceDialog::OnCancelClicked()
|
|
|
|
|
{
|
|
|
|
|
bClickedOk = false;
|
|
|
|
|
ParentWindowPtr.Pin()->RequestDestroyWindow();
|
|
|
|
|
return FReply::Handled();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 12:26:28 -04:00
|
|
|
TSharedRef<SWidget> FNewLevelInstanceParamsDetails::OnGeneratePivotActorWidget(AActor* Actor) const
|
2021-01-18 12:50:54 -04:00
|
|
|
{
|
|
|
|
|
// If a row wasn't generated just create the default one, a simple text block of the item's name.
|
2021-01-20 12:26:28 -04:00
|
|
|
return SNew(STextBlock).Text(Actor ? FText::FromString(Actor->GetActorLabel()) : LOCTEXT("null", "null")).Font(IDetailLayoutBuilder::GetDetailFont());
|
2021-01-18 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
2021-01-20 12:26:28 -04:00
|
|
|
FText FNewLevelInstanceParamsDetails::GetSelectedPivotActorText() const
|
2021-01-18 12:50:54 -04:00
|
|
|
{
|
2021-01-20 12:26:28 -04:00
|
|
|
return CreationParams->PivotActor ? FText::FromString(CreationParams->PivotActor->GetActorLabel()) : LOCTEXT("none", "None");
|
2021-01-18 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
2021-01-20 12:26:28 -04:00
|
|
|
void FNewLevelInstanceParamsDetails::OnSelectedPivotActorChanged(AActor* NewValue, ESelectInfo::Type SelectionType)
|
2021-01-18 12:50:54 -04:00
|
|
|
{
|
2021-01-20 12:26:28 -04:00
|
|
|
CreationParams->PivotActor = NewValue;
|
2021-01-18 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
2021-01-20 12:26:28 -04:00
|
|
|
bool FNewLevelInstanceParamsDetails::IsPivotActorSelectionEnabled() const
|
2021-01-18 12:50:54 -04:00
|
|
|
{
|
2021-01-20 12:26:28 -04:00
|
|
|
return CreationParams->PivotType == ELevelInstancePivotType::Actor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FNewLevelInstanceParamsDetails::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
|
|
|
|
|
{
|
|
|
|
|
// Make sure we actually get a valid struct before continuing
|
|
|
|
|
TArray<TSharedPtr<FStructOnScope>> Structs;
|
|
|
|
|
DetailBuilder.GetStructsBeingCustomized(Structs);
|
|
|
|
|
|
|
|
|
|
if (Structs.Num() == 0)
|
|
|
|
|
{
|
|
|
|
|
// Nothing being customized
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const UStruct* Struct = Structs[0]->GetStruct();
|
|
|
|
|
if (!Struct || Struct != FNewLevelInstanceParams::StaticStruct())
|
|
|
|
|
{
|
|
|
|
|
// Invalid struct
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get ptr to our actual type
|
|
|
|
|
CreationParams = (FNewLevelInstanceParams*)Structs[0]->GetStructMemory();
|
|
|
|
|
|
|
|
|
|
TSharedPtr<IPropertyHandle> PivotTypeProperty = DetailBuilder.GetProperty(GET_MEMBER_NAME_CHECKED(FNewLevelInstanceParams, PivotType), (UClass*)FNewLevelInstanceParams::StaticStruct());
|
|
|
|
|
TSharedPtr<IPropertyHandle> PivotActorProperty = DetailBuilder.GetProperty(GET_MEMBER_NAME_CHECKED(FNewLevelInstanceParams, PivotActor), (UClass*)FNewLevelInstanceParams::StaticStruct());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IDetailCategoryBuilder& PivotCategoryBuilder = DetailBuilder.EditCategory("Pivot", FText::GetEmpty(), ECategoryPriority::Uncommon);
|
|
|
|
|
PivotCategoryBuilder.AddProperty(PivotTypeProperty);
|
|
|
|
|
IDetailPropertyRow& PivotActorPropertyRow = PivotCategoryBuilder.AddProperty(PivotActorProperty);
|
|
|
|
|
|
|
|
|
|
TSharedPtr<SWidget> NameWidget;
|
|
|
|
|
TSharedPtr<SWidget> ValueWidget;
|
|
|
|
|
FDetailWidgetRow Row;
|
|
|
|
|
PivotActorPropertyRow.GetDefaultWidgets(NameWidget, ValueWidget, Row);
|
|
|
|
|
|
|
|
|
|
const bool bShowChildren = true;
|
|
|
|
|
PivotActorPropertyRow.CustomWidget(bShowChildren)
|
|
|
|
|
.NameContent()
|
|
|
|
|
.MinDesiredWidth(Row.NameWidget.MinWidth)
|
|
|
|
|
.MaxDesiredWidth(Row.NameWidget.MaxWidth)
|
|
|
|
|
[
|
|
|
|
|
NameWidget.ToSharedRef()
|
|
|
|
|
]
|
|
|
|
|
.ValueContent()
|
|
|
|
|
.MinDesiredWidth(Row.ValueWidget.MinWidth)
|
|
|
|
|
.MaxDesiredWidth(Row.ValueWidget.MaxWidth)
|
|
|
|
|
[
|
|
|
|
|
SNew(SComboBox<AActor*>)
|
|
|
|
|
.OptionsSource(&PivotActors)
|
|
|
|
|
.OnGenerateWidget(this, &FNewLevelInstanceParamsDetails::OnGeneratePivotActorWidget)
|
|
|
|
|
.OnSelectionChanged(this, &FNewLevelInstanceParamsDetails::OnSelectedPivotActorChanged)
|
|
|
|
|
.IsEnabled(this, &FNewLevelInstanceParamsDetails::IsPivotActorSelectionEnabled)
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.Text(this, &FNewLevelInstanceParamsDetails::GetSelectedPivotActorText)
|
|
|
|
|
.Font(DetailBuilder.GetDetailFont())
|
|
|
|
|
]
|
|
|
|
|
];
|
2021-01-18 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|