2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-05-23 21:04:31 -04:00
# include "Components/DynamicEntryBox.h"
# include "UMGPrivate.h"
# include "Widgets/Layout/SWrapBox.h"
# include "Widgets/SBoxPanel.h"
2019-01-29 07:17:05 -05:00
# include "Editor/WidgetCompilerLog.h"
2018-05-23 21:04:31 -04:00
# define LOCTEXT_NAMESPACE "UMG"
//////////////////////////////////////////////////////////////////////////
// UDynamicEntryBox
//////////////////////////////////////////////////////////////////////////
void UDynamicEntryBox : : Reset ( bool bDeleteWidgets )
{
2019-03-25 18:07:54 -04:00
ResetInternal ( bDeleteWidgets ) ;
2018-05-23 21:04:31 -04:00
}
void UDynamicEntryBox : : RemoveEntry ( UUserWidget * EntryWidget )
{
2019-03-25 18:07:54 -04:00
RemoveEntryInternal ( EntryWidget ) ;
2018-05-23 21:04:31 -04:00
}
# if WITH_EDITOR
2019-01-29 07:17:05 -05:00
void UDynamicEntryBox : : ValidateCompiledDefaults ( IWidgetCompilerLog & CompileLog ) const
2018-05-23 21:04:31 -04:00
{
2019-03-25 18:07:54 -04:00
Super : : ValidateCompiledDefaults ( CompileLog ) ;
2018-05-23 21:04:31 -04:00
if ( ! EntryWidgetClass )
{
2019-01-29 07:17:05 -05:00
CompileLog . Error ( FText : : Format ( LOCTEXT ( " Error_DynamicEntryBox_MissingEntryClass " , " {0} has no EntryWidgetClass specified - required for any Dynamic Entry Box to function. " ) , FText : : FromString ( GetName ( ) ) ) ) ;
2018-05-23 21:04:31 -04:00
}
2020-04-08 15:03:29 -04:00
else if ( CompileLog . GetContextClass ( ) & & EntryWidgetClass - > IsChildOf ( CompileLog . GetContextClass ( ) ) )
{
CompileLog . Error ( FText : : Format ( LOCTEXT ( " Error_DynamicEntryBox_RecursiveEntryClass " , " {0} has a recursive EntryWidgetClass specified (reference itself). " ) , FText : : FromString ( GetName ( ) ) ) ) ;
}
2018-05-23 21:04:31 -04:00
}
# endif
void UDynamicEntryBox : : SynchronizeProperties ( )
{
Super : : SynchronizeProperties ( ) ;
// At design-time, preview the desired number of entries
# if WITH_EDITORONLY_DATA
if ( IsDesignTime ( ) & & MyPanelWidget . IsValid ( ) )
{
2020-04-08 15:03:29 -04:00
if ( ! EntryWidgetClass | | ! IsEntryClassValid ( EntryWidgetClass ) )
2018-05-23 21:04:31 -04:00
{
// We have no entry class, so clear everything out
Reset ( true ) ;
}
else if ( MyPanelWidget - > GetChildren ( ) - > Num ( ) ! = NumDesignerPreviewEntries )
{
// When the number of entries to preview changes, the easiest thing to do is just soft-rebuild
Reset ( ) ;
2018-09-25 10:11:35 -04:00
int32 StartingNumber = MyPanelWidget - > GetChildren ( ) - > Num ( ) ;
while ( StartingNumber < NumDesignerPreviewEntries )
2018-05-23 21:04:31 -04:00
{
2018-09-25 10:11:35 -04:00
UUserWidget * PreviewEntry = CreateEntryInternal ( EntryWidgetClass ) ;
2020-08-11 01:36:57 -04:00
if ( PreviewEntry & & IsDesignTime ( ) & & OnPreviewEntryCreatedFunc )
2018-05-23 21:04:31 -04:00
{
OnPreviewEntryCreatedFunc ( PreviewEntry ) ;
}
2018-09-25 10:11:35 -04:00
StartingNumber + + ;
2018-05-23 21:04:31 -04:00
}
}
}
# endif
}
UUserWidget * UDynamicEntryBox : : BP_CreateEntry ( )
{
return CreateEntry ( ) ;
}
2018-09-25 10:11:35 -04:00
UUserWidget * UDynamicEntryBox : : BP_CreateEntryOfClass ( TSubclassOf < UUserWidget > EntryClass )
{
2020-04-08 15:03:29 -04:00
if ( EntryClass & & IsEntryClassValid ( EntryClass ) )
2018-09-25 10:11:35 -04:00
{
return CreateEntryInternal ( EntryClass ) ;
}
return nullptr ;
}
2018-05-23 21:04:31 -04:00
# undef LOCTEXT_NAMESPACE