Files

232 lines
6.6 KiB
C++
Raw Permalink Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "StatsCustomColumn.h"
#include "Containers/UnrealString.h"
#include "Fonts/SlateFontInfo.h"
#include "HAL/PlatformMath.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "IPropertyTable.h"
#include "IPropertyTableCell.h"
#include "IPropertyTableColumn.h"
#include "Internationalization/Internationalization.h"
#include "Math/Vector2D.h"
#include "Misc/Attribute.h"
#include "PropertyHandle.h"
#include "PropertyPath.h"
#include "SlotBase.h"
#include "StatsCellPresenter.h"
#include "Styling/AppStyle.h"
#include "Templates/TypeHash.h"
#include "UObject/Class.h"
#include "UObject/Field.h"
#include "UObject/UnrealNames.h"
#include "UObject/UnrealType.h"
#include "UObject/WeakFieldPtr.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/Text/STextBlock.h"
class IPropertyTableUtilities;
class SWidget;
class FNumericStatCellPresenter : public TSharedFromThis< FNumericStatCellPresenter >, public FStatsCellPresenter
{
public:
FNumericStatCellPresenter( const TSharedPtr< IPropertyHandle > PropertyHandle )
{
Text = FStatsCustomColumn::GetPropertyAsText( PropertyHandle );
}
virtual ~FNumericStatCellPresenter() {}
virtual TSharedRef< class SWidget > ConstructDisplayWidget() override
{
return
SNew( SHorizontalBox )
+SHorizontalBox::Slot()
.AutoWidth()
[
SNew( STextBlock )
.Text( Text )
];
}
};
bool FStatsCustomColumn::Supports( const TSharedRef< IPropertyTableColumn >& Column, const TSharedRef< IPropertyTableUtilities >& Utilities ) const
{
if( Column->GetDataSource()->IsValid() )
{
TSharedPtr< FPropertyPath > PropertyPath = Column->GetDataSource()->AsPropertyPath();
if( PropertyPath->GetNumProperties() > 0 )
{
const FPropertyInfo& PropertyInfo = PropertyPath->GetRootProperty();
return FStatsCustomColumn::SupportsProperty( PropertyInfo.Property.Get() );
}
}
return false;
}
TSharedPtr< SWidget > FStatsCustomColumn::CreateColumnLabel( const TSharedRef< IPropertyTableColumn >& Column, const TSharedRef< IPropertyTableUtilities >& Utilities, const FName& Style ) const
{
TSharedPtr< FPropertyPath > PropertyPath = Column->GetDataSource()->AsPropertyPath();
const FPropertyInfo& PropertyInfo = PropertyPath->GetRootProperty();
if( PropertyInfo.Property.Get()->HasMetaData( "ShowTotal" ) )
{
return
SNew( SVerticalBox )
+SVerticalBox::Slot()
.AutoHeight()
[
SNew( STextBlock )
.Font( FAppStyle::GetFontStyle( Style ) )
.Text( Column->GetDisplayName() )
]
+SVerticalBox::Slot()
.AutoHeight()
[
SNew( STextBlock )
.Font( FAppStyle::GetFontStyle(TEXT("BoldFont") ) )
.Text( this, &FStatsCustomColumn::GetTotalText, Column )
];
}
else
{
return
SNew( SHorizontalBox )
+SHorizontalBox::Slot()
.AutoWidth()
[
SNew( STextBlock )
.Font( FAppStyle::GetFontStyle( Style ) )
.Text( Column->GetDisplayName() )
];
}
}
TSharedPtr< IPropertyTableCellPresenter > FStatsCustomColumn::CreateCellPresenter( const TSharedRef< IPropertyTableCell >& Cell, const TSharedRef< IPropertyTableUtilities >& Utilities, const FName& Style ) const
{
TSharedPtr< IPropertyHandle > PropertyHandle = Cell->GetPropertyHandle();
if( PropertyHandle.IsValid() )
{
return MakeShareable( new FNumericStatCellPresenter( PropertyHandle ) );
}
return NULL;
}
FText FStatsCustomColumn::GetTotalText( TSharedRef< IPropertyTableColumn > Column ) const
{
TSharedPtr< FPropertyPath > PropertyPath = Column->GetDataSource()->AsPropertyPath();
const FPropertyInfo& PropertyInfo = PropertyPath->GetRootProperty();
const FString PropertyName = PropertyInfo.Property->GetNameCPP();
const FText* TotalText = TotalsMap.Find( PropertyName );
if( TotalText != NULL )
{
FText OutText = *TotalText;
if( PropertyInfo.Property.Get()->HasMetaData("Unit") )
{
FFormatNamedArguments Args;
Args.Add( TEXT("Value"), OutText );
Args.Add( TEXT("Unit"), FText::FromString( PropertyInfo.Property.Get()->GetMetaData("Unit") ) );
OutText = FText::Format( NSLOCTEXT("Stats", "Value + Unit", "{Value} {Unit}"), Args );
}
return OutText;
}
return FText::GetEmpty();
}
bool FStatsCustomColumn::SupportsProperty( const FProperty* Property )
{
if( Property->IsA( FFloatProperty::StaticClass() ) || Property->IsA( FIntProperty::StaticClass() ) )
{
return true;
}
if( Property->IsA( FStructProperty::StaticClass() ) )
{
return ( CastField<const FStructProperty>(Property)->Struct->GetFName() == NAME_Vector2D );
}
return false;
}
Copying //UE4/Dev-Enterprise to //UE4/Dev-Main (Source: //UE4/Dev-Enterprise @ 3490213) #lockdown Nick.Penwarden #rb JeanMichel.Dignard ========================== MAJOR FEATURES + CHANGES ========================== Change 3471737 on 2017/06/02 by Martin.Sevigny Changed Statistics panel export to CSV to output unformatted numeric values (no separation, no units). This allows Excel and Sheets to recognize the data a numbers so it's possible to properly sort and do arithmetic. Previous format was being recognized as strings. Change 3472839 on 2017/06/03 by JeanMichel.Dignard DatasmithImporter plugin - Used to import .mus files into UE DatasmithExporter - A DCC agnostic library to export to the .mus format DatasmithCore - A shared Datasmith library used by DatasmithImporter and DatasmithExporter ThirdParty - Added FreeImage and Itoo as Enterprise third party libraries Other - Removed an incorrect struct Rect forward declaration in IntRect.h - Added MinimalAPI to MaterialExpression Desaturation and Rotator Change 3482313 on 2017/06/09 by JeanMichel.Dignard - Added Algo::IntroSort that performs an introspective sort. Starts with quick sort and switches to heap sort when the iteration depth is too big. - Added TReversePredicate to invoke Predicate(B, A) when calling algos with a predicate. - Moved the heapify and heap sort code that was inside Array to separate Algo files. - Used IntroSort in LayoutUV because Sort can be problematic when importing big meshes. Change 3483881 on 2017/06/10 by JeanMichel.Dignard UBT - Added an Enterprise flag in the uproject file to specify that a project is using the enterprise plugins and modules. - A project will only depend on the enterprise assembly if it has the enterprise flag. - Enterprise plugins are only loaded for enterprise projects. - Added validation that Engine modules don't depend on Enterprise modules and that Enterprise modules don't depend on Game modules. - Fixed an issue where enterprise modules would end up in the game project binaries folder. Change 3485448 on 2017/06/12 by JeanMichel.Dignard - Adds DatasmithMaxExporter - Adds the DatasmithExport sample - Removes dllmain from tbbmalloc to fix issues with Programs outputting dlls. [CL 3490257 by Simon Tourangeau in Main branch]
2017-06-14 16:17:46 -04:00
FText FStatsCustomColumn::GetPropertyAsText( const TSharedPtr< IPropertyHandle > PropertyHandle , bool bGetRawValue )
{
FText Text;
Copying //UE4/Dev-Enterprise to //UE4/Dev-Main (Source: //UE4/Dev-Enterprise @ 3490213) #lockdown Nick.Penwarden #rb JeanMichel.Dignard ========================== MAJOR FEATURES + CHANGES ========================== Change 3471737 on 2017/06/02 by Martin.Sevigny Changed Statistics panel export to CSV to output unformatted numeric values (no separation, no units). This allows Excel and Sheets to recognize the data a numbers so it's possible to properly sort and do arithmetic. Previous format was being recognized as strings. Change 3472839 on 2017/06/03 by JeanMichel.Dignard DatasmithImporter plugin - Used to import .mus files into UE DatasmithExporter - A DCC agnostic library to export to the .mus format DatasmithCore - A shared Datasmith library used by DatasmithImporter and DatasmithExporter ThirdParty - Added FreeImage and Itoo as Enterprise third party libraries Other - Removed an incorrect struct Rect forward declaration in IntRect.h - Added MinimalAPI to MaterialExpression Desaturation and Rotator Change 3482313 on 2017/06/09 by JeanMichel.Dignard - Added Algo::IntroSort that performs an introspective sort. Starts with quick sort and switches to heap sort when the iteration depth is too big. - Added TReversePredicate to invoke Predicate(B, A) when calling algos with a predicate. - Moved the heapify and heap sort code that was inside Array to separate Algo files. - Used IntroSort in LayoutUV because Sort can be problematic when importing big meshes. Change 3483881 on 2017/06/10 by JeanMichel.Dignard UBT - Added an Enterprise flag in the uproject file to specify that a project is using the enterprise plugins and modules. - A project will only depend on the enterprise assembly if it has the enterprise flag. - Enterprise plugins are only loaded for enterprise projects. - Added validation that Engine modules don't depend on Enterprise modules and that Enterprise modules don't depend on Game modules. - Fixed an issue where enterprise modules would end up in the game project binaries folder. Change 3485448 on 2017/06/12 by JeanMichel.Dignard - Adds DatasmithMaxExporter - Adds the DatasmithExport sample - Removes dllmain from tbbmalloc to fix issues with Programs outputting dlls. [CL 3490257 by Simon Tourangeau in Main branch]
2017-06-14 16:17:46 -04:00
//Create a formatting option that doesn't group digits for readability. This will generate pure number strings.
FNumberFormattingOptions RawFormattingOptions;
FNumberFormattingOptions *RFOPointer = nullptr;
RawFormattingOptions.SetUseGrouping(false);
//Use ungrouped formatting option if requested by user. Leaving the pointer NULL will trigger usage of Locale default settings.
if (bGetRawValue)
{
RFOPointer = &RawFormattingOptions;
}
if( PropertyHandle->GetProperty()->IsA( FIntProperty::StaticClass() ) )
{
int32 IntValue = INT_MAX;
PropertyHandle->GetValue( IntValue );
if( IntValue == INT_MAX )
{
Text = NSLOCTEXT("Stats", "UnknownIntegerValue", "?");
}
else
{
Copying //UE4/Dev-Enterprise to //UE4/Dev-Main (Source: //UE4/Dev-Enterprise @ 3490213) #lockdown Nick.Penwarden #rb JeanMichel.Dignard ========================== MAJOR FEATURES + CHANGES ========================== Change 3471737 on 2017/06/02 by Martin.Sevigny Changed Statistics panel export to CSV to output unformatted numeric values (no separation, no units). This allows Excel and Sheets to recognize the data a numbers so it's possible to properly sort and do arithmetic. Previous format was being recognized as strings. Change 3472839 on 2017/06/03 by JeanMichel.Dignard DatasmithImporter plugin - Used to import .mus files into UE DatasmithExporter - A DCC agnostic library to export to the .mus format DatasmithCore - A shared Datasmith library used by DatasmithImporter and DatasmithExporter ThirdParty - Added FreeImage and Itoo as Enterprise third party libraries Other - Removed an incorrect struct Rect forward declaration in IntRect.h - Added MinimalAPI to MaterialExpression Desaturation and Rotator Change 3482313 on 2017/06/09 by JeanMichel.Dignard - Added Algo::IntroSort that performs an introspective sort. Starts with quick sort and switches to heap sort when the iteration depth is too big. - Added TReversePredicate to invoke Predicate(B, A) when calling algos with a predicate. - Moved the heapify and heap sort code that was inside Array to separate Algo files. - Used IntroSort in LayoutUV because Sort can be problematic when importing big meshes. Change 3483881 on 2017/06/10 by JeanMichel.Dignard UBT - Added an Enterprise flag in the uproject file to specify that a project is using the enterprise plugins and modules. - A project will only depend on the enterprise assembly if it has the enterprise flag. - Enterprise plugins are only loaded for enterprise projects. - Added validation that Engine modules don't depend on Enterprise modules and that Enterprise modules don't depend on Game modules. - Fixed an issue where enterprise modules would end up in the game project binaries folder. Change 3485448 on 2017/06/12 by JeanMichel.Dignard - Adds DatasmithMaxExporter - Adds the DatasmithExport sample - Removes dllmain from tbbmalloc to fix issues with Programs outputting dlls. [CL 3490257 by Simon Tourangeau in Main branch]
2017-06-14 16:17:46 -04:00
Text = FText::AsNumber( IntValue, RFOPointer);
}
}
else if( PropertyHandle->GetProperty()->IsA( FFloatProperty::StaticClass() ) )
{
float FloatValue = FLT_MAX;
PropertyHandle->GetValue( FloatValue );
if( FloatValue == FLT_MAX )
{
Text = NSLOCTEXT("Stats", "UnknownFloatValue", "?");
}
else
{
Copying //UE4/Dev-Enterprise to //UE4/Dev-Main (Source: //UE4/Dev-Enterprise @ 3490213) #lockdown Nick.Penwarden #rb JeanMichel.Dignard ========================== MAJOR FEATURES + CHANGES ========================== Change 3471737 on 2017/06/02 by Martin.Sevigny Changed Statistics panel export to CSV to output unformatted numeric values (no separation, no units). This allows Excel and Sheets to recognize the data a numbers so it's possible to properly sort and do arithmetic. Previous format was being recognized as strings. Change 3472839 on 2017/06/03 by JeanMichel.Dignard DatasmithImporter plugin - Used to import .mus files into UE DatasmithExporter - A DCC agnostic library to export to the .mus format DatasmithCore - A shared Datasmith library used by DatasmithImporter and DatasmithExporter ThirdParty - Added FreeImage and Itoo as Enterprise third party libraries Other - Removed an incorrect struct Rect forward declaration in IntRect.h - Added MinimalAPI to MaterialExpression Desaturation and Rotator Change 3482313 on 2017/06/09 by JeanMichel.Dignard - Added Algo::IntroSort that performs an introspective sort. Starts with quick sort and switches to heap sort when the iteration depth is too big. - Added TReversePredicate to invoke Predicate(B, A) when calling algos with a predicate. - Moved the heapify and heap sort code that was inside Array to separate Algo files. - Used IntroSort in LayoutUV because Sort can be problematic when importing big meshes. Change 3483881 on 2017/06/10 by JeanMichel.Dignard UBT - Added an Enterprise flag in the uproject file to specify that a project is using the enterprise plugins and modules. - A project will only depend on the enterprise assembly if it has the enterprise flag. - Enterprise plugins are only loaded for enterprise projects. - Added validation that Engine modules don't depend on Enterprise modules and that Enterprise modules don't depend on Game modules. - Fixed an issue where enterprise modules would end up in the game project binaries folder. Change 3485448 on 2017/06/12 by JeanMichel.Dignard - Adds DatasmithMaxExporter - Adds the DatasmithExport sample - Removes dllmain from tbbmalloc to fix issues with Programs outputting dlls. [CL 3490257 by Simon Tourangeau in Main branch]
2017-06-14 16:17:46 -04:00
Text = FText::AsNumber( FloatValue, RFOPointer);
}
}
else if( PropertyHandle->GetProperty()->IsA( FStructProperty::StaticClass() ) )
{
if( CastField<const FStructProperty>(PropertyHandle->GetProperty())->Struct->GetFName() == NAME_Vector2D )
{
FVector2D VectorValue(0.0f, 0.0f);
PropertyHandle->GetValue( VectorValue );
if( VectorValue.X == FLT_MAX || VectorValue.Y == FLT_MAX )
{
Text = NSLOCTEXT("Stats", "UnknownVectorValue", "?");
}
else
{
FFormatNamedArguments Args;
Args.Add( TEXT("VectorX"), VectorValue.X );
Args.Add( TEXT("VectorY"), VectorValue.Y );
Text = FText::Format( NSLOCTEXT("Stats", "VectorValue", "{VectorX}x{VectorY}"), Args );
}
}
}
Copying //UE4/Dev-Enterprise to //UE4/Dev-Main (Source: //UE4/Dev-Enterprise @ 3490213) #lockdown Nick.Penwarden #rb JeanMichel.Dignard ========================== MAJOR FEATURES + CHANGES ========================== Change 3471737 on 2017/06/02 by Martin.Sevigny Changed Statistics panel export to CSV to output unformatted numeric values (no separation, no units). This allows Excel and Sheets to recognize the data a numbers so it's possible to properly sort and do arithmetic. Previous format was being recognized as strings. Change 3472839 on 2017/06/03 by JeanMichel.Dignard DatasmithImporter plugin - Used to import .mus files into UE DatasmithExporter - A DCC agnostic library to export to the .mus format DatasmithCore - A shared Datasmith library used by DatasmithImporter and DatasmithExporter ThirdParty - Added FreeImage and Itoo as Enterprise third party libraries Other - Removed an incorrect struct Rect forward declaration in IntRect.h - Added MinimalAPI to MaterialExpression Desaturation and Rotator Change 3482313 on 2017/06/09 by JeanMichel.Dignard - Added Algo::IntroSort that performs an introspective sort. Starts with quick sort and switches to heap sort when the iteration depth is too big. - Added TReversePredicate to invoke Predicate(B, A) when calling algos with a predicate. - Moved the heapify and heap sort code that was inside Array to separate Algo files. - Used IntroSort in LayoutUV because Sort can be problematic when importing big meshes. Change 3483881 on 2017/06/10 by JeanMichel.Dignard UBT - Added an Enterprise flag in the uproject file to specify that a project is using the enterprise plugins and modules. - A project will only depend on the enterprise assembly if it has the enterprise flag. - Enterprise plugins are only loaded for enterprise projects. - Added validation that Engine modules don't depend on Enterprise modules and that Enterprise modules don't depend on Game modules. - Fixed an issue where enterprise modules would end up in the game project binaries folder. Change 3485448 on 2017/06/12 by JeanMichel.Dignard - Adds DatasmithMaxExporter - Adds the DatasmithExport sample - Removes dllmain from tbbmalloc to fix issues with Programs outputting dlls. [CL 3490257 by Simon Tourangeau in Main branch]
2017-06-14 16:17:46 -04:00
if (PropertyHandle->GetProperty()->HasMetaData("Unit") && !bGetRawValue)
{
FFormatNamedArguments Args;
Args.Add( TEXT("Value"), Text );
Args.Add( TEXT("Unit"), FText::FromString( PropertyHandle->GetProperty()->GetMetaData("Unit") ) );
Text = FText::Format( NSLOCTEXT("Stats", "Value + Unit", "{Value} {Unit}"), Args );
}
return Text;
}