2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "LandscapeEditorPrivatePCH.h"
# include "LandscapeEdMode.h"
# include "SLandscapeEditor.h"
# include "LandscapeEditorCommands.h"
# include "AssetThumbnail.h"
# include "LandscapeEditorObject.h"
# include "IDetailsView.h"
# include "PropertyEditorModule.h"
2014-09-18 16:42:52 -04:00
# include "Editor/IntroTutorials/Public/IIntroTutorials.h"
2014-03-14 14:13:41 -04:00
# define LOCTEXT_NAMESPACE "LandscapeEditor"
void SLandscapeAssetThumbnail : : Construct ( const FArguments & InArgs , UObject * Asset , TSharedRef < FAssetThumbnailPool > ThumbnailPool )
{
FIntPoint ThumbnailSize = InArgs . _ThumbnailSize ;
2014-07-17 12:20:34 -04:00
AssetThumbnail = MakeShareable ( new FAssetThumbnail ( Asset , ThumbnailSize . X , ThumbnailSize . Y , ThumbnailPool ) ) ;
2014-03-14 14:13:41 -04:00
ChildSlot
[
SNew ( SBox )
. WidthOverride ( ThumbnailSize . X )
. HeightOverride ( ThumbnailSize . Y )
[
AssetThumbnail - > MakeThumbnailWidget ( )
]
] ;
UMaterialInterface * MaterialInterface = Cast < UMaterialInterface > ( Asset ) ;
if ( MaterialInterface )
{
UMaterial : : OnMaterialCompilationFinished ( ) . AddSP ( this , & SLandscapeAssetThumbnail : : OnMaterialCompilationFinished ) ;
}
}
SLandscapeAssetThumbnail : : ~ SLandscapeAssetThumbnail ( )
{
UMaterial : : OnMaterialCompilationFinished ( ) . RemoveAll ( this ) ;
}
void SLandscapeAssetThumbnail : : OnMaterialCompilationFinished ( UMaterialInterface * MaterialInterface )
{
UMaterialInterface * MaterialAsset = Cast < UMaterialInterface > ( AssetThumbnail - > GetAsset ( ) ) ;
if ( MaterialAsset )
{
if ( MaterialAsset - > IsDependent ( MaterialInterface ) )
{
// Refresh thumbnail
AssetThumbnail - > SetAsset ( AssetThumbnail - > GetAsset ( ) ) ;
}
}
}
2014-07-17 12:20:34 -04:00
void SLandscapeAssetThumbnail : : SetAsset ( UObject * Asset )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
AssetThumbnail - > SetAsset ( Asset ) ;
2014-03-14 14:13:41 -04:00
}
//////////////////////////////////////////////////////////////////////////
void FLandscapeToolKit : : RegisterTabSpawners ( const TSharedRef < class FTabManager > & TabManager )
{
}
void FLandscapeToolKit : : UnregisterTabSpawners ( const TSharedRef < class FTabManager > & TabManager )
{
}
void FLandscapeToolKit : : Init ( const TSharedPtr < class IToolkitHost > & InitToolkitHost )
{
LandscapeEditorWidgets = SNew ( SLandscapeEditor , SharedThis ( this ) ) ;
FModeToolkit : : Init ( InitToolkitHost ) ;
}
FName FLandscapeToolKit : : GetToolkitFName ( ) const
{
return FName ( " LandscapeEditor " ) ;
}
FText FLandscapeToolKit : : GetBaseToolkitName ( ) const
{
return LOCTEXT ( " ToolkitName " , " Landscape Editor " ) ;
}
class FEdModeLandscape * FLandscapeToolKit : : GetEditorMode ( ) const
{
2014-06-18 10:16:16 -04:00
return ( FEdModeLandscape * ) GLevelEditorModeTools ( ) . GetActiveMode ( FBuiltinEditorModes : : EM_Landscape ) ;
2014-03-14 14:13:41 -04:00
}
TSharedPtr < SWidget > FLandscapeToolKit : : GetInlineContent ( ) const
{
return LandscapeEditorWidgets ;
}
void FLandscapeToolKit : : NotifyToolChanged ( )
{
LandscapeEditorWidgets - > NotifyToolChanged ( ) ;
}
void FLandscapeToolKit : : NotifyBrushChanged ( )
{
LandscapeEditorWidgets - > NotifyBrushChanged ( ) ;
}
//////////////////////////////////////////////////////////////////////////
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SLandscapeEditor : : Construct ( const FArguments & InArgs , TSharedRef < FLandscapeToolKit > InParentToolkit )
{
CommandList = InParentToolkit - > GetToolkitCommands ( ) ;
//FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
//TSharedPtr<SLevelEditor> LevelEditor = StaticCastSharedPtr<SLevelEditor>(LevelEditorModule.GetFirstLevelEditor());
//CommandList = LevelEditor->GetLevelEditorActions();
// Modes:
2014-07-17 12:20:34 -04:00
CommandList - > MapAction ( FLandscapeEditorCommands : : Get ( ) . ManageMode , FUIAction ( FExecuteAction : : CreateSP ( this , & SLandscapeEditor : : OnChangeMode , FName ( " ToolMode_Manage " ) ) , FCanExecuteAction : : CreateSP ( this , & SLandscapeEditor : : IsModeEnabled , FName ( TEXT ( " ToolMode_Manage " ) ) ) , FIsActionChecked : : CreateSP ( this , & SLandscapeEditor : : IsModeActive , FName ( TEXT ( " ToolMode_Manage " ) ) ) ) ) ;
CommandList - > MapAction ( FLandscapeEditorCommands : : Get ( ) . SculptMode , FUIAction ( FExecuteAction : : CreateSP ( this , & SLandscapeEditor : : OnChangeMode , FName ( " ToolMode_Sculpt " ) ) , FCanExecuteAction : : CreateSP ( this , & SLandscapeEditor : : IsModeEnabled , FName ( TEXT ( " ToolMode_Sculpt " ) ) ) , FIsActionChecked : : CreateSP ( this , & SLandscapeEditor : : IsModeActive , FName ( TEXT ( " ToolMode_Sculpt " ) ) ) ) ) ;
CommandList - > MapAction ( FLandscapeEditorCommands : : Get ( ) . PaintMode , FUIAction ( FExecuteAction : : CreateSP ( this , & SLandscapeEditor : : OnChangeMode , FName ( " ToolMode_Paint " ) ) , FCanExecuteAction : : CreateSP ( this , & SLandscapeEditor : : IsModeEnabled , FName ( TEXT ( " ToolMode_Paint " ) ) ) , FIsActionChecked : : CreateSP ( this , & SLandscapeEditor : : IsModeActive , FName ( TEXT ( " ToolMode_Paint " ) ) ) ) ) ;
2014-03-14 14:13:41 -04:00
FToolBarBuilder ModeSwitchButtons ( CommandList , FMultiBoxCustomization : : None ) ;
{
ModeSwitchButtons . AddToolBarButton ( FLandscapeEditorCommands : : Get ( ) . ManageMode , NAME_None , LOCTEXT ( " Mode.Manage " , " Manage " ) , LOCTEXT ( " Mode.Manage.Tooltip " , " Contains tools to add a new landscape, import/export landscape, add/remove components and manage streaming " ) ) ;
ModeSwitchButtons . AddToolBarButton ( FLandscapeEditorCommands : : Get ( ) . SculptMode , NAME_None , LOCTEXT ( " Mode.Sculpt " , " Sculpt " ) , LOCTEXT ( " Mode.Sculpt.Tooltip " , " Contains tools that modify the shape of a landscape " ) ) ;
ModeSwitchButtons . AddToolBarButton ( FLandscapeEditorCommands : : Get ( ) . PaintMode , NAME_None , LOCTEXT ( " Mode.Paint " , " Paint " ) , LOCTEXT ( " Mode.Paint.Tooltip " , " Contains tools that paint materials on to a landscape " ) ) ;
}
FPropertyEditorModule & PropertyEditorModule = FModuleManager : : LoadModuleChecked < FPropertyEditorModule > ( " PropertyEditor " ) ;
2015-01-26 17:14:50 -05:00
FDetailsViewArgs DetailsViewArgs ( false , false , false , FDetailsViewArgs : : HideNameArea ) ;
2014-03-14 14:13:41 -04:00
DetailsPanel = PropertyEditorModule . CreateDetailView ( DetailsViewArgs ) ;
DetailsPanel - > SetIsPropertyVisibleDelegate ( FIsPropertyVisible : : CreateSP ( this , & SLandscapeEditor : : GetIsPropertyVisible ) ) ;
FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
if ( LandscapeEdMode )
{
DetailsPanel - > SetObject ( LandscapeEdMode - > UISettings ) ;
}
2014-09-18 16:42:52 -04:00
IIntroTutorials & IntroTutorials = FModuleManager : : LoadModuleChecked < IIntroTutorials > ( TEXT ( " IntroTutorials " ) ) ;
2014-03-14 14:13:41 -04:00
ChildSlot
[
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0 , 0 , 0 , 5 )
[
SAssignNew ( Error , SErrorText )
]
+ SVerticalBox : : Slot ( )
. Padding ( 0 )
[
SNew ( SVerticalBox )
. IsEnabled ( this , & SLandscapeEditor : : GetLandscapeEditorIsEnabled )
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
2014-09-18 16:42:52 -04:00
. Padding ( 4 , 0 , 4 , 5 )
2014-03-14 14:13:41 -04:00
[
2014-09-18 16:42:52 -04:00
SNew ( SOverlay )
+ SOverlay : : Slot ( )
2014-03-14 14:13:41 -04:00
[
2014-09-18 16:42:52 -04:00
SNew ( SBorder )
. BorderImage ( FEditorStyle : : GetBrush ( " ToolPanel.GroupBorder " ) )
. HAlign ( HAlign_Center )
[
ModeSwitchButtons . MakeWidget ( )
]
]
// Tutorial link
+ SOverlay : : Slot ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Bottom )
. Padding ( 4 )
[
IntroTutorials . CreateTutorialsWidget ( TEXT ( " LandscapeMode " ) )
2014-03-14 14:13:41 -04:00
]
]
+ SVerticalBox : : Slot ( )
. Padding ( 0 )
[
DetailsPanel . ToSharedRef ( )
]
]
] ;
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
class FEdModeLandscape * SLandscapeEditor : : GetEditorMode ( ) const
{
2014-06-18 10:16:16 -04:00
return ( FEdModeLandscape * ) GLevelEditorModeTools ( ) . GetActiveMode ( FBuiltinEditorModes : : EM_Landscape ) ;
2014-03-14 14:13:41 -04:00
}
2014-10-17 08:42:36 -04:00
FText SLandscapeEditor : : GetErrorText ( ) const
2014-03-14 14:13:41 -04:00
{
2014-10-17 08:42:36 -04:00
const FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
ELandscapeEditingState EditState = LandscapeEdMode - > GetEditingState ( ) ;
switch ( EditState )
2014-03-14 14:13:41 -04:00
{
2014-10-17 08:42:36 -04:00
case ELandscapeEditingState : : SIEWorld :
2014-03-14 14:13:41 -04:00
{
2014-10-17 08:42:36 -04:00
2014-03-14 14:13:41 -04:00
if ( LandscapeEdMode - > NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
2014-10-17 08:42:36 -04:00
return LOCTEXT ( " IsSimulatingError_create " , " Can't create landscape while simulating! " ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-10-17 08:42:36 -04:00
return LOCTEXT ( " IsSimulatingError_edit " , " Can't edit landscape while simulating! " ) ;
2014-03-14 14:13:41 -04:00
}
2014-10-17 08:42:36 -04:00
break ;
2014-03-14 14:13:41 -04:00
}
2014-10-17 08:42:36 -04:00
case ELandscapeEditingState : : PIEWorld :
2014-03-14 14:13:41 -04:00
{
if ( LandscapeEdMode - > NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
2014-10-17 08:42:36 -04:00
return LOCTEXT ( " IsPIEError_create " , " Can't create landscape in PIE! " ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-10-17 08:42:36 -04:00
return LOCTEXT ( " IsPIEError_edit " , " Can't edit landscape in PIE! " ) ;
2014-03-14 14:13:41 -04:00
}
2014-10-17 08:42:36 -04:00
break ;
2014-03-14 14:13:41 -04:00
}
2014-10-17 08:42:36 -04:00
case ELandscapeEditingState : : BadFeatureLevel :
2014-03-14 14:13:41 -04:00
{
2014-10-17 08:42:36 -04:00
if ( LandscapeEdMode - > NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
2014-03-14 14:13:41 -04:00
{
2014-10-17 08:42:36 -04:00
return LOCTEXT ( " IsFLError_create " , " Can't create landscape with a feature level less than SM4! " ) ;
2014-03-14 14:13:41 -04:00
}
2014-10-17 08:42:36 -04:00
else
{
return LOCTEXT ( " IsFLError_edit " , " Can't edit landscape with a feature level less than SM4! " ) ;
}
break ;
2014-03-14 14:13:41 -04:00
}
2014-10-17 08:42:36 -04:00
case ELandscapeEditingState : : NoLandscape :
{
return LOCTEXT ( " NoLandscapeError " , " No Landscape! " ) ;
}
case ELandscapeEditingState : : Enabled :
{
return FText : : GetEmpty ( ) ;
}
default :
checkNoEntry ( ) ;
2014-03-14 14:13:41 -04:00
}
2014-10-17 08:42:36 -04:00
return FText : : GetEmpty ( ) ;
2014-03-14 14:13:41 -04:00
}
bool SLandscapeEditor : : GetLandscapeEditorIsEnabled ( ) const
{
FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
if ( LandscapeEdMode )
{
2014-10-17 08:42:36 -04:00
Error - > SetError ( GetErrorText ( ) ) ;
return LandscapeEdMode - > GetEditingState ( ) = = ELandscapeEditingState : : Enabled ;
2014-03-14 14:13:41 -04:00
}
return false ;
}
2014-06-24 13:07:20 -04:00
bool SLandscapeEditor : : GetIsPropertyVisible ( const FPropertyAndParent & PropertyAndParent ) const
2014-03-14 14:13:41 -04:00
{
2014-06-24 13:07:20 -04:00
const UProperty & Property = PropertyAndParent . Property ;
2014-03-14 14:13:41 -04:00
FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
2014-07-17 12:20:34 -04:00
if ( LandscapeEdMode ! = NULL & & LandscapeEdMode - > CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-06-24 13:07:20 -04:00
if ( Property . HasMetaData ( " ShowForMask " ) )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
const bool bMaskEnabled = LandscapeEdMode - > CurrentTool & &
LandscapeEdMode - > CurrentTool - > SupportsMask ( ) & &
2014-03-14 14:13:41 -04:00
LandscapeEdMode - > CurrentToolTarget . LandscapeInfo . IsValid ( ) & &
LandscapeEdMode - > CurrentToolTarget . LandscapeInfo - > SelectedRegion . Num ( ) > 0 ;
if ( bMaskEnabled )
{
return true ;
}
}
2014-06-24 13:07:20 -04:00
if ( Property . HasMetaData ( " ShowForTools " ) )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
const FName CurrentToolName = LandscapeEdMode - > CurrentTool - > GetToolName ( ) ;
2014-03-14 14:13:41 -04:00
TArray < FString > ShowForTools ;
2015-03-02 15:51:37 -05:00
Property . GetMetaData ( " ShowForTools " ) . ParseIntoArray ( ShowForTools , TEXT ( " , " ) , true ) ;
2014-03-14 14:13:41 -04:00
if ( ! ShowForTools . Contains ( CurrentToolName . ToString ( ) ) )
{
return false ;
}
}
2014-06-24 13:07:20 -04:00
if ( Property . HasMetaData ( " ShowForBrushes " ) )
2014-03-14 14:13:41 -04:00
{
const FName CurrentBrushSetName = LandscapeEdMode - > LandscapeBrushSets [ LandscapeEdMode - > CurrentBrushSetIndex ] . BrushSetName ;
2014-07-17 12:20:34 -04:00
// const FName CurrentBrushName = LandscapeEdMode->CurrentBrush->GetBrushName();
2014-03-14 14:13:41 -04:00
TArray < FString > ShowForBrushes ;
2015-03-02 15:51:37 -05:00
Property . GetMetaData ( " ShowForBrushes " ) . ParseIntoArray ( ShowForBrushes , TEXT ( " , " ) , true ) ;
2014-03-14 14:13:41 -04:00
if ( ! ShowForBrushes . Contains ( CurrentBrushSetName . ToString ( ) ) )
//&& !ShowForBrushes.Contains(CurrentBrushName.ToString())
{
return false ;
}
}
2014-06-24 13:07:20 -04:00
if ( Property . HasMetaData ( " ShowForTargetTypes " ) )
2014-04-23 17:50:08 -04:00
{
static const TCHAR * TargetTypeNames [ ] = { TEXT ( " Heightmap " ) , TEXT ( " Weightmap " ) , TEXT ( " Visibility " ) } ;
TArray < FString > ShowForTargetTypes ;
2015-03-02 15:51:37 -05:00
Property . GetMetaData ( " ShowForTargetTypes " ) . ParseIntoArray ( ShowForTargetTypes , TEXT ( " , " ) , true ) ;
2014-04-23 17:50:08 -04:00
const ELandscapeToolTargetType : : Type CurrentTargetType = LandscapeEdMode - > CurrentToolTarget . TargetType ;
if ( CurrentTargetType = = ELandscapeToolTargetType : : Invalid | |
ShowForTargetTypes . FindByKey ( TargetTypeNames [ CurrentTargetType ] ) = = nullptr )
{
return false ;
}
}
2014-03-14 14:13:41 -04:00
return true ;
}
return false ;
}
void SLandscapeEditor : : OnChangeMode ( FName ModeName )
{
FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
if ( LandscapeEdMode )
{
LandscapeEdMode - > SetCurrentToolMode ( ModeName ) ;
}
}
bool SLandscapeEditor : : IsModeEnabled ( FName ModeName ) const
{
FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
if ( LandscapeEdMode )
{
// Manage is the only mode enabled if we have no landscape
if ( ModeName = = " ToolMode_Manage " | | LandscapeEdMode - > GetLandscapeList ( ) . Num ( ) > 0 )
{
return true ;
}
}
return false ;
}
bool SLandscapeEditor : : IsModeActive ( FName ModeName ) const
{
FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
2014-07-17 12:20:34 -04:00
if ( LandscapeEdMode & & LandscapeEdMode - > CurrentTool )
2014-03-14 14:13:41 -04:00
{
return LandscapeEdMode - > CurrentToolMode - > ToolModeName = = ModeName ;
}
return false ;
}
void SLandscapeEditor : : NotifyToolChanged ( )
{
FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
if ( LandscapeEdMode )
{
// Refresh details panel
DetailsPanel - > SetObject ( LandscapeEdMode - > UISettings , true ) ;
}
}
void SLandscapeEditor : : NotifyBrushChanged ( )
{
FEdModeLandscape * LandscapeEdMode = GetEditorMode ( ) ;
if ( LandscapeEdMode )
{
// Refresh details panel
DetailsPanel - > SetObject ( LandscapeEdMode - > UISettings , true ) ;
}
}
# undef LOCTEXT_NAMESPACE