Files
UnrealEngineUWP/Engine/Source/Editor/TextureEditor/Private/Customizations/TextureDetailsCustomization.cpp

287 lines
9.3 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Customizations/TextureDetailsCustomization.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 "Misc/MessageDialog.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Engine/Texture.h"
#include "Engine/Texture2D.h"
#include "Editor.h"
#include "DetailLayoutBuilder.h"
#include "DetailWidgetRow.h"
#include "IDetailPropertyRow.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 "DetailCategoryBuilder.h"
#include "Widgets/Input/SNumericEntryBox.h"
#include "Widgets/Input/STextComboBox.h"
#define LOCTEXT_NAMESPACE "FTextureDetails"
TSharedRef<IDetailCustomization> FTextureDetails::MakeInstance()
{
return MakeShareable(new FTextureDetails);
}
void FTextureDetails::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{
TArray< TWeakObjectPtr<UObject> > ObjectsBeingCustomized;
DetailBuilder.GetObjectsBeingCustomized(ObjectsBeingCustomized);
if (ensure(ObjectsBeingCustomized.Num() == 1))
{
TextureBeingCustomized = ObjectsBeingCustomized[0];
}
DetailBuilder.EditCategory("LevelOfDetail");
DetailBuilder.EditCategory("Compression");
DetailBuilder.EditCategory("Texture");
DetailBuilder.EditCategory("Adjustments");
DetailBuilder.EditCategory("File Path");
MaxTextureSizePropertyHandle = DetailBuilder.GetProperty(GET_MEMBER_NAME_CHECKED(UTexture, MaxTextureSize));
PowerOfTwoModePropertyHandle = DetailBuilder.GetProperty(GET_MEMBER_NAME_CHECKED(UTexture, PowerOfTwoMode));
VirtualTextureStreamingPropertyHandle = DetailBuilder.GetProperty(GET_MEMBER_NAME_CHECKED(UTexture, VirtualTextureStreaming));
// Customize MaxTextureSize
if( MaxTextureSizePropertyHandle->IsValidHandle() )
{
IDetailCategoryBuilder& CompressionCategory = DetailBuilder.EditCategory("Compression");
IDetailPropertyRow& MaxTextureSizePropertyRow = CompressionCategory.AddProperty(GET_MEMBER_NAME_CHECKED(UTexture, MaxTextureSize));
TSharedPtr<SWidget> NameWidget;
TSharedPtr<SWidget> ValueWidget;
FDetailWidgetRow Row;
MaxTextureSizePropertyRow.GetDefaultWidgets(NameWidget, ValueWidget, Row);
int32 MaxTextureSize = 2048;
if (UTexture* Texture = Cast<UTexture>(TextureBeingCustomized.Get()))
{
MaxTextureSize = Texture->GetMaximumDimension();
}
const bool bShowChildren = true;
MaxTextureSizePropertyRow.CustomWidget(bShowChildren)
.NameContent()
.MinDesiredWidth(Row.NameWidget.MinWidth)
.MaxDesiredWidth(Row.NameWidget.MaxWidth)
[
NameWidget.ToSharedRef()
]
.ValueContent()
.MinDesiredWidth(Row.ValueWidget.MinWidth)
.MaxDesiredWidth(Row.ValueWidget.MaxWidth)
[
SNew(SNumericEntryBox<int32>)
.AllowSpin(true)
.Value(this, &FTextureDetails::OnGetMaxTextureSize)
.Font(IDetailLayoutBuilder::GetDetailFont())
.MinValue(0)
.MaxValue(MaxTextureSize)
.MinSliderValue(0)
.MaxSliderValue(MaxTextureSize)
.OnValueChanged(this, &FTextureDetails::OnMaxTextureSizeChanged)
.OnValueCommitted(this, &FTextureDetails::OnMaxTextureSizeCommitted)
.OnBeginSliderMovement(this, &FTextureDetails::OnBeginSliderMovement)
.OnEndSliderMovement(this, &FTextureDetails::OnEndSliderMovement)
];
}
// Customize PowerOfTwoMode
if( PowerOfTwoModePropertyHandle->IsValidHandle() )
{
IDetailCategoryBuilder& TextureCategory = DetailBuilder.EditCategory("Texture");
IDetailPropertyRow& PowerOfTwoModePropertyRow = TextureCategory.AddProperty(GET_MEMBER_NAME_CHECKED(UTexture, PowerOfTwoMode));
PowerOfTwoModePropertyHandle->SetOnPropertyResetToDefault(FSimpleDelegate::CreateSP(this, &FTextureDetails::OnPropertyResetToDefault));
// Generate a list of enum values for the combo box
TArray<FText> PowerOfTwoModeComboBoxToolTips;
TArray<bool> RestrictedList;
PowerOfTwoModePropertyHandle->GeneratePossibleValues(PowerOfTwoModeComboBoxList, PowerOfTwoModeComboBoxToolTips, RestrictedList);
uint8 PowerOfTwoMode;
ensure(PowerOfTwoModePropertyHandle->GetValue(PowerOfTwoMode) == FPropertyAccess::Success);
TSharedPtr<SWidget> NameWidget;
TSharedPtr<SWidget> ValueWidget;
FDetailWidgetRow Row;
PowerOfTwoModePropertyRow.GetDefaultWidgets(NameWidget, ValueWidget, Row);
const bool bShowChildren = true;
PowerOfTwoModePropertyRow.CustomWidget(bShowChildren)
.NameContent()
.MinDesiredWidth(Row.NameWidget.MinWidth)
.MaxDesiredWidth(Row.NameWidget.MaxWidth)
[
NameWidget.ToSharedRef()
]
.ValueContent()
.MinDesiredWidth(Row.ValueWidget.MinWidth)
.MaxDesiredWidth(Row.ValueWidget.MaxWidth)
[
SAssignNew(TextComboBox, STextComboBox)
.Font(IDetailLayoutBuilder::GetDetailFont())
.OptionsSource(&PowerOfTwoModeComboBoxList)
.InitiallySelectedItem(PowerOfTwoModeComboBoxList[PowerOfTwoMode])
.OnSelectionChanged(this, &FTextureDetails::OnPowerOfTwoModeChanged)
];
}
// Hide the option to enable VT streaming, if VT is disabled for the project
if (VirtualTextureStreamingPropertyHandle.IsValid())
{
static const auto CVarVirtualTexturesEnabled = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.VirtualTextures")); check(CVarVirtualTexturesEnabled);
const bool bVirtualTextureEnabled = CVarVirtualTexturesEnabled->GetValueOnAnyThread() != 0;
if (!bVirtualTextureEnabled)
{
DetailBuilder.HideProperty(VirtualTextureStreamingPropertyHandle);
}
}
}
bool FTextureDetails::CanEditMaxTextureSize() const
{
if (UTexture2D* Texture2D = Cast<UTexture2D>(TextureBeingCustomized.Get()))
{
if (!Texture2D->Source.IsPowerOfTwo() && Texture2D->PowerOfTwoMode == ETexturePowerOfTwoSetting::None)
{
return false;
}
}
return true;
}
void FTextureDetails::CreateMaxTextureSizeMessage() const
{
FMessageDialog::Open(EAppMsgType::Ok,
LOCTEXT("CannotEditMaxTextureSize", "Maximum Texture Size cannot be changed for this texture as it is a non power of two size. Change the Power of Two Mode to allow it to be padded to a power of two."));
}
/** @return The value or unset if properties with multiple values are viewed */
TOptional<int32> FTextureDetails::OnGetMaxTextureSize() const
{
int32 NumericVal;
if (MaxTextureSizePropertyHandle->GetValue(NumericVal) == FPropertyAccess::Success)
{
return NumericVal;
}
// Return an unset value so it displays the "multiple values" indicator instead
return TOptional<int32>();
}
void FTextureDetails::OnMaxTextureSizeChanged(int32 NewValue)
{
if (!CanEditMaxTextureSize())
{
return;
}
if (bIsUsingSlider)
{
int32 OrgValue(0);
if (MaxTextureSizePropertyHandle->GetValue(OrgValue) != FPropertyAccess::Fail)
{
// Value hasn't changed, so let's return now
if (OrgValue == NewValue)
{
return;
}
}
// We don't create a transaction for each property change when using the slider. Only once when the slider first is moved
EPropertyValueSetFlags::Type Flags = (EPropertyValueSetFlags::InteractiveChange | EPropertyValueSetFlags::NotTransactable);
MaxTextureSizePropertyHandle->SetValue(NewValue, Flags);
}
}
void FTextureDetails::OnMaxTextureSizeCommitted(int32 NewValue, ETextCommit::Type CommitInfo)
{
if (!CanEditMaxTextureSize())
{
if (CommitInfo == ETextCommit::OnEnter)
{
CreateMaxTextureSizeMessage();
}
return;
}
MaxTextureSizePropertyHandle->SetValue(NewValue);
}
/**
* Called when the slider begins to move. We create a transaction here to undo the property
*/
void FTextureDetails::OnBeginSliderMovement()
{
if (!CanEditMaxTextureSize())
{
return;
}
bIsUsingSlider = true;
GEditor->BeginTransaction(TEXT("TextureDetails"), LOCTEXT("SetMaximumTextureSize", "Edit Maximum Texture Size"), nullptr /* MaxTextureSizePropertyHandle->GetProperty() */ );
}
/**
* Called when the slider stops moving. We end the previously created transaction
*/
void FTextureDetails::OnEndSliderMovement(int32 NewValue)
{
if (!CanEditMaxTextureSize())
{
return;
}
bIsUsingSlider = false;
GEditor->EndTransaction();
}
bool FTextureDetails::CanEditPowerOfTwoMode(int32 NewPowerOfTwoMode) const
{
if (UTexture2D* Texture2D = Cast<UTexture2D>(TextureBeingCustomized.Get()))
{
if (!Texture2D->Source.IsPowerOfTwo() && Texture2D->MaxTextureSize > 0 && NewPowerOfTwoMode == ETexturePowerOfTwoSetting::None)
{
return false;
}
}
return true;
}
void FTextureDetails::CreatePowerOfTwoModeMessage() const
{
FMessageDialog::Open(EAppMsgType::Ok,
LOCTEXT("CannotEditPowerOfTwoMode", "Power of Two Mode cannot be changed to None for this texture as it is a non power of two size and has a Maximum Texture Size override. Change the Maximum Texture Size to 0 before attempting to change the Power of Two Mode."));
}
void FTextureDetails::OnPropertyResetToDefault() const
{
uint8 CurrentPowerOfTwoMode;
ensure(PowerOfTwoModePropertyHandle->GetValue(CurrentPowerOfTwoMode) == FPropertyAccess::Success);
TextComboBox->SetSelectedItem(PowerOfTwoModeComboBoxList[CurrentPowerOfTwoMode]);
}
void FTextureDetails::OnPowerOfTwoModeChanged(TSharedPtr<FString> NewValue, ESelectInfo::Type SelectInfo)
{
int32 NewPowerOfTwoMode = PowerOfTwoModeComboBoxList.Find(NewValue);
check(NewPowerOfTwoMode != INDEX_NONE);
if (!CanEditPowerOfTwoMode(NewPowerOfTwoMode))
{
CreatePowerOfTwoModeMessage();
uint8 CurrentPowerOfTwoMode;
ensure(PowerOfTwoModePropertyHandle->GetValue(CurrentPowerOfTwoMode) == FPropertyAccess::Success);
TextComboBox->SetSelectedItem(PowerOfTwoModeComboBoxList[CurrentPowerOfTwoMode]);
return;
}
int32 PowerOfTwoMode = PowerOfTwoModeComboBoxList.Find(NewValue);
check(PowerOfTwoMode != INDEX_NONE);
ensure(PowerOfTwoModePropertyHandle->SetValue(static_cast<uint8>(PowerOfTwoMode)) == FPropertyAccess::Success);
}
#undef LOCTEXT_NAMESPACE