// 具体代码见百度网盘TestReflection /***************************** SSURAAR_MainWnd.h ********************************/ #include "CoreMinimal.h" #include "Slate.h" #include "Engine/RendererSettings.h" DECLARE_DELEGATE_OneParam(FOnCustomStencilChanged, ECustomDepthStencil::Type) DECLARE_DELEGATE_OneParam(FOnAlphaChannelModeChanged, EAlphaChannelMode::Type) DECLARE_DELEGATE_OneParam(FOnFrameBufferPixelFormatChanged, EDefaultBackBufferPixelFormat::Type) class SSURAAR_MainWnd : public SCompoundWidget { public: SLATE_BEGIN_ARGS(SSURAAR_MainWnd){} SLATE_END_ARGS() void Construct(const FArguments& Args); TSharedRef<SWidget> MakeCustomStencilCombo(FOnCustomStencilChanged OnChanged, TAttribute<ECustomDepthStencil::Type> SelectedEnum, EOrientation Orientation); TSharedRef<SWidget> MakeAlphaChannelModeCombo(FOnAlphaChannelModeChanged OnChanged, TAttribute<EAlphaChannelMode::Type> SelectedEnum, EOrientation Orientation); TSharedRef<SWidget> MakeFrameBufferPixelFormatCombo(FOnFrameBufferPixelFormatChanged OnChanged, TAttribute<EDefaultBackBufferPixelFormat::Type> SelectedEnum, EOrientation Orientation); TSharedRef<SWidget> MakeSURACameraDriverDetails(); private: EVisibility CheckSuraCameraDriverExist() const; }; /********************************** SSURAAR_MainWnd.cpp ***********************************/ // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. #include "SSURAAR_MainWnd.h" #include <Kismet/GameplayStatics.h> #include "SSuraEnumComboBox.h" #include "SURACameraDriver.h" #include "Customizations/SURACameraDriverDetailsCustomization.h" #define LOCTEXT_NAMESPACE "SURAAR_MainWnd" void SSURAAR_MainWnd::Construct(const FArguments& Args) { FText PlaceholderText = LOCTEXT("PlaceholderText", "Placeholder"); auto Settings = GetMutableDefault<URendererSettings>(); ChildSlot [ SNew(SVerticalBox) +SVerticalBox::Slot() .AutoHeight() [ SNew(SUniformGridPanel) .SlotPadding(TAttribute<FMargin>(FMargin(4.0f))) +SUniformGridPanel::Slot(0, 0) .VAlign(EVerticalAlignment::VAlign_Center) [ SNew(STextBlock) .Text(LOCTEXT("Custom Depth-Stencil Pass", "Custom Depth-Stencil Pass")) ] +SUniformGridPanel::Slot(1, 0) .HAlign(EHorizontalAlignment::HAlign_Fill) .VAlign(EVerticalAlignment::VAlign_Fill) [ MakeCustomStencilCombo( FOnCustomStencilChanged::CreateLambda([&](ECustomDepthStencil::Type stencil) { auto Settings = GetMutableDefault<URendererSettings>(); Settings->CustomDepthStencil = stencil; }), TAttribute<ECustomDepthStencil::Type>::Create(TAttribute<ECustomDepthStencil::Type>::FGetter::CreateLambda([]() { auto Settings = GetDefault<URendererSettings>(); return Settings->CustomDepthStencil.GetValue(); })), Orient_Vertical ) ] +SUniformGridPanel::Slot(0, 1) .VAlign(EVerticalAlignment::VAlign_Center) [ SNew(STextBlock) .Text(LOCTEXT("Enable alpha channel support", "Enable alpha channel support in post processing")) ] +SUniformGridPanel::Slot(1, 1) .HAlign(EHorizontalAlignment::HAlign_Fill) .VAlign(EVerticalAlignment::VAlign_Fill) [ MakeAlphaChannelModeCombo( FOnAlphaChannelModeChanged::CreateLambda([&](EAlphaChannelMode::Type AlphaMode) { auto Settings = GetMutableDefault<URendererSettings>(); Settings->bEnableAlphaChannelInPostProcessing = AlphaMode; }), TAttribute<EAlphaChannelMode::Type>::Create(TAttribute<EAlphaChannelMode::Type>::FGetter::CreateLambda([]() { auto Settings = GetDefault<URendererSettings>(); return Settings->bEnableAlphaChannelInPostProcessing.GetValue(); })), Orient_Vertical ) ] +SUniformGridPanel::Slot(0, 2) .VAlign(EVerticalAlignment::VAlign_Center) [ SNew(STextBlock) .Text(LOCTEXT("Frame Buffer Pixel Format", "Frame Buffer Pixel Format")) ] +SUniformGridPanel::Slot(1, 2) .HAlign(EHorizontalAlignment::HAlign_Fill) .VAlign(EVerticalAlignment::VAlign_Fill) [ MakeFrameBufferPixelFormatCombo( FOnFrameBufferPixelFormatChanged::CreateLambda([&](EDefaultBackBufferPixelFormat::Type PixelFormat) { auto Settings = GetMutableDefault<URendererSettings>(); Settings->DefaultBackBufferPixelFormat = PixelFormat; }), TAttribute<EDefaultBackBufferPixelFormat::Type>::Create(TAttribute<EDefaultBackBufferPixelFormat::Type>::FGetter::CreateLambda([]() { auto Settings = GetDefault<URendererSettings>(); return Settings->DefaultBackBufferPixelFormat.GetValue(); })), Orient_Vertical ) ] ] +SVerticalBox::Slot() .AutoHeight() [ //SNew(STextBlock).Text(PlaceholderText) SNew(SHorizontalBox) +SHorizontalBox::Slot() .AutoWidth() [ SNew(SButton) // button for checking SURAAcameraDriver .Visibility_Raw(this, &SSURAAR_MainWnd::CheckSuraCameraDriverExist) .Content() [ SNew(STextBlock).Text(LOCTEXT("SetupEnv", "Setup Environment")) ] ] ] + SVerticalBox::Slot() [ MakeSURACameraDriverDetails() ] /*+SVerticalBox::Slot() [ SNew(STextBlock).Text(PlaceholderText) ]*/ ]; } TSharedRef<SWidget> SSURAAR_MainWnd::MakeCustomStencilCombo( FOnCustomStencilChanged OnChanged, TAttribute<ECustomDepthStencil::Type> SelectedEnum, EOrientation Orientation ) { TArray<SSuraEnumCombo<ECustomDepthStencil::Type>::FComboOption> CustomStencilInfo; CustomStencilInfo.Add(SSuraEnumCombo<ECustomDepthStencil::Type>::FComboOption( ECustomDepthStencil::Disabled, FSlateIcon(), LOCTEXT("CustomStencil.Disabled", "Disabled"))); CustomStencilInfo.Add(SSuraEnumCombo<ECustomDepthStencil::Type>::FComboOption( ECustomDepthStencil::Enabled, FSlateIcon(), LOCTEXT("CustomStencil.Enabled", "Enabled"))); CustomStencilInfo.Add(SSuraEnumCombo<ECustomDepthStencil::Type>::FComboOption( ECustomDepthStencil::EnabledOnDemand, FSlateIcon(), LOCTEXT("CustomStencil.EnabledOnDemand", "EnabledOnDemand"))); CustomStencilInfo.Add(SSuraEnumCombo<ECustomDepthStencil::Type>::FComboOption( ECustomDepthStencil::EnabledWithStencil, FSlateIcon(), LOCTEXT("CustomStencil.EnabledWithStencil", "EnabledWithStencil"))); return SNew(SSuraEnumCombo<ECustomDepthStencil::Type>, MoveTemp(CustomStencilInfo)) .SelectedEnum(SelectedEnum) .OnEnumChanged(OnChanged) .Orientation(Orientation); //.ToolTip(IDocumentation::Get()->CreateToolTip(LOCTEXT("GraphicsPresetTooltip", "Choose the graphical level to target (high-end only or scalable from low-end on up)."), NULL, TEXT("Shared/Editor/Settings/TargetHardware"), TEXT("GraphicalLevel"))); } TSharedRef<SWidget> SSURAAR_MainWnd::MakeAlphaChannelModeCombo( FOnAlphaChannelModeChanged OnChanged, TAttribute<EAlphaChannelMode::Type> SelectedEnum, EOrientation Orientation ) { TArray<SSuraEnumCombo<EAlphaChannelMode::Type>::FComboOption> AlphaChannelModeInfo; AlphaChannelModeInfo.Add(SSuraEnumCombo<EAlphaChannelMode::Type>::FComboOption( EAlphaChannelMode::Disabled, FSlateIcon(), LOCTEXT("AlphaChannelMode.Disabled", "Disabled"))); AlphaChannelModeInfo.Add(SSuraEnumCombo<EAlphaChannelMode::Type>::FComboOption( EAlphaChannelMode::LinearColorSpaceOnly, FSlateIcon(), LOCTEXT("AlphaChannelMode.LinearColorSpaceOnly", "LinearColorSpaceOnly"))); AlphaChannelModeInfo.Add(SSuraEnumCombo<EAlphaChannelMode::Type>::FComboOption( EAlphaChannelMode::AllowThroughTonemapper, FSlateIcon(), LOCTEXT("AlphaChannelMode.AllowThroughTonemapper", "AllowThroughTonemapper"))); return SNew(SSuraEnumCombo<EAlphaChannelMode::Type>, MoveTemp(AlphaChannelModeInfo)) .SelectedEnum(SelectedEnum) .OnEnumChanged(OnChanged) .Orientation(Orientation); //.ToolTip(IDocumentation::Get()->CreateToolTip(LOCTEXT("GraphicsPresetTooltip", "Choose the graphical level to target (high-end only or scalable from low-end on up)."), NULL, TEXT("Shared/Editor/Settings/TargetHardware"), TEXT("GraphicalLevel"))); } TSharedRef<SWidget> SSURAAR_MainWnd::MakeFrameBufferPixelFormatCombo( FOnFrameBufferPixelFormatChanged OnChanged, TAttribute<EDefaultBackBufferPixelFormat::Type> SelectedEnum, EOrientation Orientation ) { TArray<SSuraEnumCombo<EDefaultBackBufferPixelFormat::Type>::FComboOption> FramePixelFormatInfo; FramePixelFormatInfo.Add(SSuraEnumCombo<EDefaultBackBufferPixelFormat::Type>::FComboOption( EDefaultBackBufferPixelFormat::DBBPF_B8G8R8A8, FSlateIcon(), LOCTEXT("FramePixelFormat.DBBPF_B8G8R8A8", "8bit RGBA"))); FramePixelFormatInfo.Add(SSuraEnumCombo<EDefaultBackBufferPixelFormat::Type>::FComboOption( EDefaultBackBufferPixelFormat::DBBPF_A16B16G16R16_DEPRECATED, FSlateIcon(), LOCTEXT("FramePixelFormat.DBBPF_A16B16G16R16_DEPRECATED", "DEPRECATED - 16bit RGBA"), false)); FramePixelFormatInfo.Add(SSuraEnumCombo<EDefaultBackBufferPixelFormat::Type>::FComboOption( EDefaultBackBufferPixelFormat::DBBPF_FloatRGB_DEPRECATED, FSlateIcon(), LOCTEXT("FramePixelFormat.DBBPF_FloatRGB_DEPRECATED", "DEPRECATED - Float RGB"), false)); FramePixelFormatInfo.Add(SSuraEnumCombo<EDefaultBackBufferPixelFormat::Type>::FComboOption( EDefaultBackBufferPixelFormat::DBBPF_FloatRGBA, FSlateIcon(), LOCTEXT("FramePixelFormat.DBBPF_FloatRGBA", "Float RGBA"))); FramePixelFormatInfo.Add(SSuraEnumCombo<EDefaultBackBufferPixelFormat::Type>::FComboOption( EDefaultBackBufferPixelFormat::DBBPF_A2B10G10R10, FSlateIcon(), LOCTEXT("FramePixelFormat.DBBPF_A2B10G10R10", "10bit RGB, 2bit Alpha"))); return SNew(SSuraEnumCombo<EDefaultBackBufferPixelFormat::Type>, MoveTemp(FramePixelFormatInfo)) .SelectedEnum(SelectedEnum) .OnEnumChanged(OnChanged) .Orientation(Orientation); //.ToolTip(IDocumentation::Get()->CreateToolTip(LOCTEXT("GraphicsPresetTooltip", "Choose the graphical level to target (high-end only or scalable from low-end on up)."), NULL, TEXT("Shared/Editor/Settings/TargetHardware"), TEXT("GraphicalLevel"))); } EVisibility SSURAAR_MainWnd::CheckSuraCameraDriverExist() const { TArray<AActor*> OutActors; if (GWorld) { UGameplayStatics::GetAllActorsOfClass(GWorld, ASURACameraDriver::StaticClass(), OutActors); } if (OutActors.Num() == 0) { UE_LOG(LogTemp, Log, TEXT("No SuraCameraDriver found.")); return EVisibility::Visible; } else { return EVisibility::Collapsed; } } TSharedRef<SWidget> SSURAAR_MainWnd::MakeSURACameraDriverDetails( ) { FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>(TEXT("PropertyEditor")); FDetailsViewArgs Args; Args.bAllowSearch = false; Args.NameAreaSettings = FDetailsViewArgs::HideNameArea; TSharedRef<IDetailsView> View = PropertyModule.CreateDetailView(Args); View->RegisterInstancedCustomPropertyLayout(ASURACameraDriver::StaticClass(), FOnGetDetailCustomizationInstance::CreateStatic(&FSURACameraDriverDetailsCustomization::MakeInstance)); TArray<AActor*> OutActors; if (GWorld) { UGameplayStatics::GetAllActorsOfClass(GWorld, ASURACameraDriver::StaticClass(), OutActors); } if (OutActors.Num() > 0) { View->SetObject(OutActors[0], true); } return View; } #undef LOCTEXT_NAMESPACE |