2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-08-21 20:30:51 -04:00
# include "ContentBrowserPCH.h"
# include "SAssetDialog.h"
# define LOCTEXT_NAMESPACE "ContentBrowser"
2014-09-01 13:25:23 -04:00
SAssetDialog : : SAssetDialog ( )
: DialogType ( EAssetDialogType : : Open )
, ExistingAssetPolicy ( ESaveAssetDialogExistingAssetPolicy : : Disallow )
, bLastInputValidityCheckSuccessful ( false )
2014-09-15 21:28:40 -04:00
, bPendingFocusNextFrame ( true )
2014-11-19 03:38:05 -05:00
, bValidAssetsChosen ( false )
2014-09-01 13:25:23 -04:00
{
}
2014-11-19 03:38:05 -05:00
SAssetDialog : : ~ SAssetDialog ( )
{
if ( ! bValidAssetsChosen )
{
OnAssetDialogCancelled . ExecuteIfBound ( ) ;
}
}
2014-08-21 20:30:51 -04:00
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SAssetDialog : : Construct ( const FArguments & InArgs , const FSharedAssetDialogConfig & InConfig )
{
DialogType = InConfig . GetDialogType ( ) ;
AssetClassNames = InConfig . AssetClassNames ;
const FString DefaultPath = InConfig . DefaultPath ;
2014-12-19 17:44:49 -05:00
RegisterActiveTimer ( 0.f , FWidgetActiveTimerDelegate : : CreateSP ( this , & SAssetDialog : : SetFocusPostConstruct ) ) ;
---- Merging with SlateDev branch ----
Introduces the concept of "Active Ticking" to allow Slate to go to sleep when there is no need to update the UI.
While asleep, Slate will skip the Tick & Paint pass for that frame entirely.
- There are TWO ways to "wake" Slate and cause a Tick/Paint pass:
1. Provide some sort of input (mouse movement, clicks, and key presses). Slate will always tick when the user is active.
- Therefore, if the logic in a given widget's Tick is only relevant in response to user action, there is no need to register an active tick.
2. Register an Active Tick. Currently this is an all-or-nothing situation, so if a single active tick needs to execute, all of Slate will be ticked.
- The purpose of an Active Tick is to allow a widget to "drive" Slate and guarantee a Tick/Paint pass in the absence of any user action.
- Examples include animation, async operations that update periodically, progress updates, loading bars, etc.
- An empty active tick is registered for viewports when they are real-time, so game project widgets are unaffected by this change and should continue to work as before.
- An Active Tick is registered by creating an FWidgetActiveTickDelegate and passing it to SWidget::RegisterActiveTick()
- There are THREE ways to unregister an active tick:
1. Return EActiveTickReturnType::StopTicking from the active tick function
2. Pass the FActiveTickHandle returned by RegisterActiveTick() to SWidget::UnregisterActiveTick()
3. Destroy the widget responsible for the active tick
- Sleeping is currently disabled, can be enabled with Slate.AllowSlateToSleep cvar
- There is currently a little buffer time during which Slate continues to tick following any input. Long-term, this is planned to be removed.
- The duration of the buffer can be adjusted using Slate.SleepBufferPostInput cvar (defaults to 1.0f)
- The FCurveSequence API has been updated to work with the active tick system
- Playing a curve sequence now requires that you pass the widget being animated by the sequence
- The active tick will automatically be registered on behalf of the widget and unregister when the sequence is complete
- GetLerpLooping() has been removed. Instead, pass true as the second param to Play() to indicate that the animation will loop. This causes the active tick to be registered indefinitely until paused or jumped to the start/end.
[CL 2391669 by Dan Hertzka in Main branch]
2014-12-17 16:07:57 -05:00
2014-08-21 20:30:51 -04:00
FPathPickerConfig PathPickerConfig ;
PathPickerConfig . DefaultPath = DefaultPath ;
PathPickerConfig . bFocusSearchBoxWhenOpened = false ;
PathPickerConfig . OnPathSelected = FOnPathSelected : : CreateSP ( this , & SAssetDialog : : HandlePathSelected ) ;
2014-09-15 20:43:33 -04:00
PathPickerConfig . SetPathsDelegates . Add ( & SetPathsDelegate ) ;
2014-08-21 20:30:51 -04:00
FAssetPickerConfig AssetPickerConfig ;
AssetPickerConfig . Filter . ClassNames . Append ( AssetClassNames ) ;
AssetPickerConfig . Filter . PackagePaths . Add ( FName ( * DefaultPath ) ) ;
AssetPickerConfig . bAllowDragging = false ;
AssetPickerConfig . InitialAssetViewType = EAssetViewType : : Tile ;
AssetPickerConfig . OnAssetSelected = FOnAssetSelected : : CreateSP ( this , & SAssetDialog : : OnAssetSelected ) ;
AssetPickerConfig . OnAssetsActivated = FOnAssetsActivated : : CreateSP ( this , & SAssetDialog : : OnAssetsActivated ) ;
AssetPickerConfig . SetFilterDelegates . Add ( & SetFilterDelegate ) ;
AssetPickerConfig . GetCurrentSelectionDelegates . Add ( & GetCurrentSelectionDelegate ) ;
2014-08-22 19:06:27 -04:00
AssetPickerConfig . SaveSettingsName = TEXT ( " AssetDialog " ) ;
2014-09-15 20:43:33 -04:00
AssetPickerConfig . bCanShowFolders = true ;
2015-06-30 11:03:51 -04:00
AssetPickerConfig . bCanShowDevelopersFolder = true ;
2014-09-15 20:43:33 -04:00
AssetPickerConfig . OnFolderEntered = FOnPathSelected : : CreateSP ( this , & SAssetDialog : : HandleAssetViewFolderEntered ) ;
2014-08-21 20:30:51 -04:00
SetCurrentlySelectedPath ( DefaultPath ) ;
// Open and save specific configuration
FText ConfirmButtonText ;
bool bIncludeNameBox = false ;
if ( DialogType = = EAssetDialogType : : Open )
{
const FOpenAssetDialogConfig & OpenAssetConfig = static_cast < const FOpenAssetDialogConfig & > ( InConfig ) ;
PathPickerConfig . bAllowContextMenu = false ;
ConfirmButtonText = LOCTEXT ( " AssetDialogOpenButton " , " Open " ) ;
AssetPickerConfig . SelectionMode = OpenAssetConfig . bAllowMultipleSelection ? ESelectionMode : : Multi : ESelectionMode : : Single ;
2014-09-15 21:28:40 -04:00
AssetPickerConfig . bFocusSearchBoxWhenOpened = true ;
2014-08-21 20:30:51 -04:00
bIncludeNameBox = false ;
}
else if ( DialogType = = EAssetDialogType : : Save )
{
const FSaveAssetDialogConfig & SaveAssetConfig = static_cast < const FSaveAssetDialogConfig & > ( InConfig ) ;
PathPickerConfig . bAllowContextMenu = true ;
ConfirmButtonText = LOCTEXT ( " AssetDialogSaveButton " , " Save " ) ;
AssetPickerConfig . SelectionMode = ESelectionMode : : Single ;
2014-09-15 21:28:40 -04:00
AssetPickerConfig . bFocusSearchBoxWhenOpened = false ;
2014-08-21 20:30:51 -04:00
bIncludeNameBox = true ;
2014-09-01 13:25:23 -04:00
ExistingAssetPolicy = SaveAssetConfig . ExistingAssetPolicy ;
2014-08-21 20:30:51 -04:00
SetCurrentlyEnteredAssetName ( SaveAssetConfig . DefaultAssetName ) ;
}
else
{
ensureMsgf ( 0 , TEXT ( " AssetDialog type %d is not supported. " ) , DialogType ) ;
}
2014-09-15 20:43:33 -04:00
TSharedPtr < SWidget > PathPicker = FContentBrowserSingleton : : Get ( ) . CreatePathPicker ( PathPickerConfig ) ;
TSharedPtr < SWidget > AssetPicker = FContentBrowserSingleton : : Get ( ) . CreateAssetPicker ( AssetPickerConfig ) ;
2014-08-21 20:30:51 -04:00
// The root widget in this dialog.
TSharedRef < SVerticalBox > MainVerticalBox = SNew ( SVerticalBox ) ;
// Path/Asset view
MainVerticalBox - > AddSlot ( )
. FillHeight ( 1 )
. Padding ( 0 , 0 , 0 , 4 )
[
SNew ( SSplitter )
+ SSplitter : : Slot ( )
. Value ( 0.25f )
[
SNew ( SBorder )
. BorderImage ( FEditorStyle : : GetBrush ( " ToolPanel.GroupBorder " ) )
[
PathPicker . ToSharedRef ( )
]
]
+ SSplitter : : Slot ( )
. Value ( 0.75f )
[
SNew ( SBorder )
. BorderImage ( FEditorStyle : : GetBrush ( " ToolPanel.GroupBorder " ) )
[
AssetPicker . ToSharedRef ( )
]
]
] ;
// Input error strip, if we are using a name box
if ( bIncludeNameBox )
{
// Name Error label
MainVerticalBox - > AddSlot ( )
. AutoHeight ( )
[
// Constant height, whether the label is visible or not
SNew ( SBox ) . HeightOverride ( 18 )
[
SNew ( SBorder )
. Visibility ( this , & SAssetDialog : : GetNameErrorLabelVisibility )
. BorderImage ( FEditorStyle : : GetBrush ( " AssetDialog.ErrorLabelBorder " ) )
. Content ( )
[
SNew ( STextBlock )
. Text ( this , & SAssetDialog : : GetNameErrorLabelText )
. TextStyle ( FEditorStyle : : Get ( ) , " AssetDialog.ErrorLabelFont " )
]
]
] ;
}
2014-12-10 10:08:13 -05:00
TSharedRef < SVerticalBox > LabelsBox = SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. FillHeight ( 1 )
. VAlign ( VAlign_Center )
. Padding ( 0 , 2 , 0 , 2 )
[
SNew ( STextBlock ) . Text ( LOCTEXT ( " PathBoxLabel " , " Path: " ) )
] ;
2014-08-21 20:30:51 -04:00
2014-12-10 10:08:13 -05:00
TSharedRef < SVerticalBox > ContentBox = SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. FillHeight ( 1 )
. VAlign ( VAlign_Center )
. Padding ( 0 , 2 , 0 , 2 )
[
SAssignNew ( PathText , STextBlock )
. Text ( this , & SAssetDialog : : GetPathNameText )
] ;
if ( bIncludeNameBox )
2014-08-21 20:30:51 -04:00
{
2014-12-10 10:08:13 -05:00
LabelsBox - > AddSlot ( )
. FillHeight ( 1 )
2014-08-21 20:30:51 -04:00
. VAlign ( VAlign_Center )
2014-12-10 10:08:13 -05:00
. Padding ( 0 , 2 , 0 , 2 )
2014-08-21 20:30:51 -04:00
[
SNew ( STextBlock ) . Text ( LOCTEXT ( " NameBoxLabel " , " Name: " ) )
] ;
2014-12-10 10:08:13 -05:00
ContentBox - > AddSlot ( )
. FillHeight ( 1 )
2014-08-21 20:30:51 -04:00
. VAlign ( VAlign_Center )
2014-12-10 10:08:13 -05:00
. Padding ( 0 , 2 , 0 , 2 )
2014-08-21 20:30:51 -04:00
[
2014-09-15 21:28:40 -04:00
SAssignNew ( NameEditableText , SEditableTextBox )
2014-08-21 20:30:51 -04:00
. Text ( this , & SAssetDialog : : GetAssetNameText )
. OnTextCommitted ( this , & SAssetDialog : : OnAssetNameTextCommited )
. OnTextChanged ( this , & SAssetDialog : : OnAssetNameTextCommited , ETextCommit : : Default )
2014-09-15 21:28:40 -04:00
. SelectAllTextWhenFocused ( true )
2014-08-21 20:30:51 -04:00
] ;
}
2014-12-10 10:08:13 -05:00
// Buttons and asset name
TSharedRef < SHorizontalBox > ButtonsAndNameBox = SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
2014-08-21 20:30:51 -04:00
. AutoWidth ( )
2014-12-10 10:08:13 -05:00
. HAlign ( HAlign_Right )
2015-01-26 18:36:26 -05:00
. VAlign ( VAlign_Bottom )
. Padding ( bIncludeNameBox ? 80 : 4 , 20 , 4 , 3 )
2014-12-10 10:08:13 -05:00
[
LabelsBox
]
+ SHorizontalBox : : Slot ( )
. FillWidth ( 1 )
2015-01-26 18:36:26 -05:00
. VAlign ( VAlign_Bottom )
2014-12-10 10:08:13 -05:00
. Padding ( 4 , 3 )
[
ContentBox
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Bottom )
2014-08-21 20:30:51 -04:00
. Padding ( 4 , 3 )
[
SNew ( SButton )
. Text ( ConfirmButtonText )
2015-01-26 18:36:26 -05:00
. ContentPadding ( FMargin ( 8 , 2 , 8 , 2 ) )
2014-08-21 20:30:51 -04:00
. IsEnabled ( this , & SAssetDialog : : IsConfirmButtonEnabled )
. OnClicked ( this , & SAssetDialog : : OnConfirmClicked )
2014-12-10 10:08:13 -05:00
]
+ SHorizontalBox : : Slot ( )
2014-08-21 20:30:51 -04:00
. AutoWidth ( )
2014-12-10 10:08:13 -05:00
. VAlign ( VAlign_Bottom )
2014-08-21 20:30:51 -04:00
. Padding ( 4 , 3 )
[
SNew ( SButton )
2015-01-26 18:36:26 -05:00
. ContentPadding ( FMargin ( 8 , 2 , 8 , 2 ) )
2014-08-21 20:30:51 -04:00
. Text ( LOCTEXT ( " AssetDialogCancelButton " , " Cancel " ) )
. OnClicked ( this , & SAssetDialog : : OnCancelClicked )
] ;
MainVerticalBox - > AddSlot ( )
. AutoHeight ( )
2014-12-10 10:08:13 -05:00
. HAlign ( HAlign_Fill )
2015-01-26 18:36:26 -05:00
. Padding ( 0 )
2014-08-21 20:30:51 -04:00
[
2015-01-26 18:36:26 -05:00
ButtonsAndNameBox
2014-08-21 20:30:51 -04:00
] ;
ChildSlot
[
MainVerticalBox
] ;
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
2014-10-30 12:29:36 -04:00
FReply SAssetDialog : : OnKeyDown ( const FGeometry & MyGeometry , const FKeyEvent & InKeyEvent )
2014-08-21 20:30:51 -04:00
{
2014-10-30 12:29:36 -04:00
if ( InKeyEvent . GetKey ( ) = = EKeys : : Escape )
2014-08-21 20:30:51 -04:00
{
CloseDialog ( ) ;
return FReply : : Handled ( ) ;
}
2014-10-30 12:29:36 -04:00
return SCompoundWidget : : OnKeyDown ( MyGeometry , InKeyEvent ) ;
2014-08-21 20:30:51 -04:00
}
2014-12-19 17:44:49 -05:00
EActiveTimerReturnType SAssetDialog : : SetFocusPostConstruct ( double InCurrentTime , float InDeltaTime )
2014-09-15 21:28:40 -04:00
{
---- Merging with SlateDev branch ----
Introduces the concept of "Active Ticking" to allow Slate to go to sleep when there is no need to update the UI.
While asleep, Slate will skip the Tick & Paint pass for that frame entirely.
- There are TWO ways to "wake" Slate and cause a Tick/Paint pass:
1. Provide some sort of input (mouse movement, clicks, and key presses). Slate will always tick when the user is active.
- Therefore, if the logic in a given widget's Tick is only relevant in response to user action, there is no need to register an active tick.
2. Register an Active Tick. Currently this is an all-or-nothing situation, so if a single active tick needs to execute, all of Slate will be ticked.
- The purpose of an Active Tick is to allow a widget to "drive" Slate and guarantee a Tick/Paint pass in the absence of any user action.
- Examples include animation, async operations that update periodically, progress updates, loading bars, etc.
- An empty active tick is registered for viewports when they are real-time, so game project widgets are unaffected by this change and should continue to work as before.
- An Active Tick is registered by creating an FWidgetActiveTickDelegate and passing it to SWidget::RegisterActiveTick()
- There are THREE ways to unregister an active tick:
1. Return EActiveTickReturnType::StopTicking from the active tick function
2. Pass the FActiveTickHandle returned by RegisterActiveTick() to SWidget::UnregisterActiveTick()
3. Destroy the widget responsible for the active tick
- Sleeping is currently disabled, can be enabled with Slate.AllowSlateToSleep cvar
- There is currently a little buffer time during which Slate continues to tick following any input. Long-term, this is planned to be removed.
- The duration of the buffer can be adjusted using Slate.SleepBufferPostInput cvar (defaults to 1.0f)
- The FCurveSequence API has been updated to work with the active tick system
- Playing a curve sequence now requires that you pass the widget being animated by the sequence
- The active tick will automatically be registered on behalf of the widget and unregister when the sequence is complete
- GetLerpLooping() has been removed. Instead, pass true as the second param to Play() to indicate that the animation will loop. This causes the active tick to be registered indefinitely until paused or jumped to the start/end.
[CL 2391669 by Dan Hertzka in Main branch]
2014-12-17 16:07:57 -05:00
FocusNameBox ( ) ;
2014-12-19 17:44:49 -05:00
return EActiveTimerReturnType : : Stop ;
2014-09-15 21:28:40 -04:00
}
2014-08-21 20:30:51 -04:00
void SAssetDialog : : SetOnAssetsChosenForOpen ( const FOnAssetsChosenForOpen & InOnAssetsChosenForOpen )
{
OnAssetsChosenForOpen = InOnAssetsChosenForOpen ;
}
void SAssetDialog : : SetOnObjectPathChosenForSave ( const FOnObjectPathChosenForSave & InOnObjectPathChosenForSave )
{
OnObjectPathChosenForSave = InOnObjectPathChosenForSave ;
}
2014-11-19 03:38:05 -05:00
void SAssetDialog : : SetOnAssetDialogCancelled ( const FOnAssetDialogCancelled & InOnAssetDialogCancelled )
{
OnAssetDialogCancelled = InOnAssetDialogCancelled ;
}
2014-09-15 21:28:40 -04:00
void SAssetDialog : : FocusNameBox ( )
{
if ( NameEditableText . IsValid ( ) )
{
2014-10-30 12:29:36 -04:00
FSlateApplication : : Get ( ) . SetKeyboardFocus ( NameEditableText . ToSharedRef ( ) , EFocusCause : : SetDirectly ) ;
2014-09-15 21:28:40 -04:00
}
}
2014-08-21 20:30:51 -04:00
FText SAssetDialog : : GetAssetNameText ( ) const
{
return FText : : FromString ( CurrentlyEnteredAssetName ) ;
}
2014-12-10 10:08:13 -05:00
FText SAssetDialog : : GetPathNameText ( ) const
{
return FText : : FromString ( CurrentlySelectedPath ) ;
}
2014-08-21 20:30:51 -04:00
void SAssetDialog : : OnAssetNameTextCommited ( const FText & InText , ETextCommit : : Type InCommitType )
{
SetCurrentlyEnteredAssetName ( InText . ToString ( ) ) ;
if ( InCommitType = = ETextCommit : : OnEnter )
{
CommitObjectPathForSave ( ) ;
}
}
EVisibility SAssetDialog : : GetNameErrorLabelVisibility ( ) const
{
return GetNameErrorLabelText ( ) . IsEmpty ( ) ? EVisibility : : Hidden : EVisibility : : Visible ;
}
2015-01-07 09:52:40 -05:00
FText SAssetDialog : : GetNameErrorLabelText ( ) const
2014-08-21 20:30:51 -04:00
{
if ( ! bLastInputValidityCheckSuccessful )
{
2015-01-07 09:52:40 -05:00
return LastInputValidityErrorText ;
2014-08-21 20:30:51 -04:00
}
2015-01-07 09:52:40 -05:00
return FText : : GetEmpty ( ) ;
2014-08-21 20:30:51 -04:00
}
void SAssetDialog : : HandlePathSelected ( const FString & NewPath )
{
FARFilter NewFilter ;
NewFilter . ClassNames . Append ( AssetClassNames ) ;
NewFilter . PackagePaths . Add ( FName ( * NewPath ) ) ;
SetCurrentlySelectedPath ( NewPath ) ;
SetFilterDelegate . ExecuteIfBound ( NewFilter ) ;
}
2014-09-15 20:43:33 -04:00
void SAssetDialog : : HandleAssetViewFolderEntered ( const FString & NewPath )
{
SetCurrentlySelectedPath ( NewPath ) ;
TArray < FString > NewPaths ;
NewPaths . Add ( NewPath ) ;
SetPathsDelegate . Execute ( NewPaths ) ;
}
2014-08-21 20:30:51 -04:00
bool SAssetDialog : : IsConfirmButtonEnabled ( ) const
{
if ( DialogType = = EAssetDialogType : : Open )
{
return CurrentlySelectedAssets . Num ( ) > 0 ;
}
else if ( DialogType = = EAssetDialogType : : Save )
{
return bLastInputValidityCheckSuccessful ;
}
else
{
ensureMsgf ( 0 , TEXT ( " AssetDialog type %d is not supported. " ) , DialogType ) ;
}
return false ;
}
FReply SAssetDialog : : OnConfirmClicked ( )
{
if ( DialogType = = EAssetDialogType : : Open )
{
TArray < FAssetData > SelectedAssets = GetCurrentSelectionDelegate . Execute ( ) ;
if ( SelectedAssets . Num ( ) > 0 )
{
ChooseAssetsForOpen ( SelectedAssets ) ;
}
}
else if ( DialogType = = EAssetDialogType : : Save )
{
// @todo save asset validation (e.g. "asset already exists" check)
CommitObjectPathForSave ( ) ;
}
else
{
ensureMsgf ( 0 , TEXT ( " AssetDialog type %d is not supported. " ) , DialogType ) ;
}
return FReply : : Handled ( ) ;
}
FReply SAssetDialog : : OnCancelClicked ( )
{
CloseDialog ( ) ;
return FReply : : Handled ( ) ;
}
void SAssetDialog : : OnAssetSelected ( const FAssetData & AssetData )
{
CurrentlySelectedAssets = GetCurrentSelectionDelegate . Execute ( ) ;
if ( AssetData . IsValid ( ) )
{
SetCurrentlySelectedPath ( AssetData . PackagePath . ToString ( ) ) ;
SetCurrentlyEnteredAssetName ( AssetData . AssetName . ToString ( ) ) ;
}
}
void SAssetDialog : : OnAssetsActivated ( const TArray < FAssetData > & SelectedAssets , EAssetTypeActivationMethod : : Type ActivationType )
{
const bool bCorrectActivationMethod = ( ActivationType = = EAssetTypeActivationMethod : : DoubleClicked | | ActivationType = = EAssetTypeActivationMethod : : Opened ) ;
if ( SelectedAssets . Num ( ) > 0 & & bCorrectActivationMethod )
{
if ( DialogType = = EAssetDialogType : : Open )
{
ChooseAssetsForOpen ( SelectedAssets ) ;
}
else if ( DialogType = = EAssetDialogType : : Save )
{
const FAssetData & AssetData = SelectedAssets [ 0 ] ;
SetCurrentlySelectedPath ( AssetData . PackagePath . ToString ( ) ) ;
SetCurrentlyEnteredAssetName ( AssetData . AssetName . ToString ( ) ) ;
CommitObjectPathForSave ( ) ;
}
else
{
ensureMsgf ( 0 , TEXT ( " AssetDialog type %d is not supported. " ) , DialogType ) ;
}
}
}
void SAssetDialog : : CloseDialog ( )
{
FWidgetPath WidgetPath ;
TSharedPtr < SWindow > ContainingWindow = FSlateApplication : : Get ( ) . FindWidgetWindow ( AsShared ( ) , WidgetPath ) ;
if ( ContainingWindow . IsValid ( ) )
{
ContainingWindow - > RequestDestroyWindow ( ) ;
}
}
void SAssetDialog : : SetCurrentlySelectedPath ( const FString & NewPath )
{
CurrentlySelectedPath = NewPath ;
UpdateInputValidity ( ) ;
}
void SAssetDialog : : SetCurrentlyEnteredAssetName ( const FString & NewName )
{
CurrentlyEnteredAssetName = NewName ;
UpdateInputValidity ( ) ;
}
void SAssetDialog : : UpdateInputValidity ( )
{
bLastInputValidityCheckSuccessful = true ;
if ( CurrentlyEnteredAssetName . IsEmpty ( ) )
{
// No error text for an empty name. Just fail validity.
LastInputValidityErrorText = FText : : GetEmpty ( ) ;
bLastInputValidityCheckSuccessful = false ;
}
if ( bLastInputValidityCheckSuccessful )
{
if ( CurrentlySelectedPath . IsEmpty ( ) )
{
LastInputValidityErrorText = LOCTEXT ( " AssetDialog_NoPathSelected " , " You must select a path. " ) ;
bLastInputValidityCheckSuccessful = false ;
}
}
if ( DialogType = = EAssetDialogType : : Save )
{
if ( bLastInputValidityCheckSuccessful )
{
const FString ObjectPath = GetObjectPathForSave ( ) ;
FText ErrorMessage ;
2014-09-01 13:25:23 -04:00
const bool bAllowExistingAsset = ( ExistingAssetPolicy = = ESaveAssetDialogExistingAssetPolicy : : AllowButWarn ) ;
if ( ! ContentBrowserUtils : : IsValidObjectPathForCreate ( ObjectPath , ErrorMessage , bAllowExistingAsset ) )
2014-08-21 20:30:51 -04:00
{
LastInputValidityErrorText = ErrorMessage ;
bLastInputValidityCheckSuccessful = false ;
}
}
}
}
void SAssetDialog : : ChooseAssetsForOpen ( const TArray < FAssetData > & SelectedAssets )
{
if ( ensure ( DialogType = = EAssetDialogType : : Open ) )
{
if ( SelectedAssets . Num ( ) > 0 )
{
2014-11-19 03:38:05 -05:00
bValidAssetsChosen = true ;
2014-08-21 20:30:51 -04:00
OnAssetsChosenForOpen . ExecuteIfBound ( SelectedAssets ) ;
CloseDialog ( ) ;
}
}
}
FString SAssetDialog : : GetObjectPathForSave ( ) const
{
return CurrentlySelectedPath / CurrentlyEnteredAssetName + TEXT ( " . " ) + CurrentlyEnteredAssetName ;
}
void SAssetDialog : : CommitObjectPathForSave ( )
{
if ( ensure ( DialogType = = EAssetDialogType : : Save ) )
{
if ( bLastInputValidityCheckSuccessful )
{
const FString ObjectPath = GetObjectPathForSave ( ) ;
2014-09-01 13:25:23 -04:00
bool bProceedWithSave = true ;
// If we were asked to warn on existing assets, do it now
if ( ExistingAssetPolicy = = ESaveAssetDialogExistingAssetPolicy : : AllowButWarn )
{
FAssetRegistryModule & AssetRegistryModule = FModuleManager : : LoadModuleChecked < FAssetRegistryModule > ( " AssetRegistry " ) ;
FAssetData ExistingAsset = AssetRegistryModule . Get ( ) . GetAssetByObjectPath ( FName ( * ObjectPath ) ) ;
if ( ExistingAsset . IsValid ( ) & & AssetClassNames . Contains ( ExistingAsset . AssetClass ) )
{
EAppReturnType : : Type ShouldReplace = FMessageDialog : : Open ( EAppMsgType : : YesNo , FText : : Format ( LOCTEXT ( " ReplaceAssetMessage " , " {ExistingAsset} already exists. Do you want to replace it? " ) , FText : : FromString ( CurrentlyEnteredAssetName ) ) ) ;
bProceedWithSave = ( ShouldReplace = = EAppReturnType : : Yes ) ;
}
}
if ( bProceedWithSave )
{
2014-11-19 03:38:05 -05:00
bValidAssetsChosen = true ;
2014-09-01 13:25:23 -04:00
OnObjectPathChosenForSave . ExecuteIfBound ( ObjectPath ) ;
CloseDialog ( ) ;
}
2014-08-21 20:30:51 -04:00
}
}
}
# undef LOCTEXT_NAMESPACE