Files
UnrealEngineUWP/Engine/Source/Runtime/Experimental/InteractiveToolsFramework/Private/InteractiveTool.cpp
ryan schmidt e7f3baf1ca Edigrate Dev-Editor updates to InteractiveToolsFramework, GeometryProcessing, MeshModelingToolset, and ModelingTools Editor Mode Plugins. Update a few files in new MeshPaint Plugin for UInteractiveTool rename of ::Tick() to ::OnTick().
#rb none
#rnx

#ROBOMERGE-SOURCE: CL 12908995 via CL 12908996 via CL 12909001
#ROBOMERGE-BOT: RELEASE (Release-Engine-Staging -> Main) (v682-12900288)

[CL 12909003 by ryan schmidt in Main branch]
2020-04-18 18:42:59 -04:00

256 lines
5.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "InteractiveTool.h"
#include "InteractiveToolManager.h"
#include "UObject/Class.h"
#define LOCTEXT_NAMESPACE "UInteractiveTool"
#if WITH_EDITOR
void UInteractiveToolPropertySet::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
OnModified.Broadcast(this, PropertyChangedEvent.Property);
}
#endif
UInteractiveTool::UInteractiveTool()
{
// tools need to be transactional or undo/redo won't work on their uproperties
SetFlags(RF_Transactional);
// tools don't get saved but this isn't necessary because they are created in the transient package...
//SetFlags(RF_Transient);
InputBehaviors = NewObject<UInputBehaviorSet>(this, TEXT("InputBehaviors"));
// initialize ToolInfo
#if WITH_EDITORONLY_DATA
DefaultToolInfo.ToolDisplayName = GetClass()->GetDisplayNameText();
#else
DefaultToolInfo.ToolDisplayName = FText(LOCTEXT("DefaultInteractiveToolName", "DefaultToolName"));
#endif
}
void UInteractiveTool::Setup()
{
}
void UInteractiveTool::Shutdown(EToolShutdownType ShutdownType)
{
InputBehaviors->RemoveAll();
ToolPropertyObjects.Reset();
}
void UInteractiveTool::Render(IToolsContextRenderAPI* RenderAPI)
{
}
void UInteractiveTool::AddInputBehavior(UInputBehavior* Behavior)
{
InputBehaviors->Add(Behavior);
}
const UInputBehaviorSet* UInteractiveTool::GetInputBehaviors() const
{
return InputBehaviors;
}
void UInteractiveTool::AddToolPropertySource(UObject* PropertyObject)
{
check(ToolPropertyObjects.Contains(PropertyObject) == false);
ToolPropertyObjects.Add(PropertyObject);
OnPropertySetsModified.Broadcast();
}
void UInteractiveTool::AddToolPropertySource(UInteractiveToolPropertySet* PropertySet)
{
check(ToolPropertyObjects.Contains(PropertySet) == false);
ToolPropertyObjects.Add(PropertySet);
// @todo do we need to create a lambda every time for this?
PropertySet->GetOnModified().AddLambda([this](UObject* PropertySetArg, FProperty* PropertyArg)
{
OnPropertyModified(PropertySetArg, PropertyArg);
});
OnPropertySetsModified.Broadcast();
}
bool UInteractiveTool::RemoveToolPropertySource(UInteractiveToolPropertySet* PropertySet)
{
int32 NumRemoved = ToolPropertyObjects.Remove(PropertySet);
if (NumRemoved == 0)
{
return false;
}
PropertySet->GetOnModified().Clear();
OnPropertySetsModified.Broadcast();
return true;
}
bool UInteractiveTool::ReplaceToolPropertySource(UInteractiveToolPropertySet* CurPropertySet, UInteractiveToolPropertySet* ReplaceWith, bool bSetToEnabled)
{
int32 Index = ToolPropertyObjects.Find(CurPropertySet);
if (Index == INDEX_NONE)
{
return false;
}
CurPropertySet->GetOnModified().Clear();
ReplaceWith->GetOnModified().AddLambda([this](UObject* PropertySetArg, FProperty* PropertyArg)
{
OnPropertyModified(PropertySetArg, PropertyArg);
});
ToolPropertyObjects[Index] = ReplaceWith;
if (bSetToEnabled)
{
ReplaceWith->bIsPropertySetEnabled = true;
}
OnPropertySetsModified.Broadcast();
return true;
}
bool UInteractiveTool::SetToolPropertySourceEnabled(UInteractiveToolPropertySet* PropertySet, bool bEnabled)
{
int32 Index = ToolPropertyObjects.Find(PropertySet);
if (Index == INDEX_NONE)
{
return false;
}
if (PropertySet->bIsPropertySetEnabled != bEnabled)
{
PropertySet->bIsPropertySetEnabled = bEnabled;
OnPropertySetsModified.Broadcast();
}
return true;
}
TArray<UObject*> UInteractiveTool::GetToolProperties(bool bEnabledOnly) const
{
if (bEnabledOnly == false)
{
return ToolPropertyObjects;
}
TArray<UObject*> Properties;
for (UObject* Object : ToolPropertyObjects)
{
UInteractiveToolPropertySet* Prop = Cast<UInteractiveToolPropertySet>(Object);
if (Prop == nullptr || Prop->IsPropertySetEnabled())
{
Properties.Add(Object);
}
}
return Properties;
}
void
UInteractiveToolPropertySet::SaveProperties(UInteractiveTool* SaveFromTool)
{
SaveRestoreProperties(SaveFromTool, true);
}
void
UInteractiveToolPropertySet::RestoreProperties(UInteractiveTool* RestoreToTool)
{
SaveRestoreProperties(RestoreToTool, false);
}
void UInteractiveToolPropertySet::SaveRestoreProperties(UInteractiveTool* RestoreToTool, bool bSaving)
{
UInteractiveToolPropertySet* PropertyCache = GetDynamicPropertyCache();
for ( FProperty* Prop : TFieldRange<FProperty>(GetClass()) )
{
#if WITH_EDITOR
if (!Prop->HasMetaData(TEXT("TransientToolProperty")))
#endif
{
void* DestValue = Prop->ContainerPtrToValuePtr<void>(this);
void* SrcValue = Prop->ContainerPtrToValuePtr<void>(PropertyCache);
if ( bSaving )
{
Swap(SrcValue, DestValue);
}
Prop->CopySingleValue(DestValue, SrcValue);
}
}
}
void UInteractiveTool::RegisterActions(FInteractiveToolActionSet& ActionSet)
{
}
FInteractiveToolActionSet* UInteractiveTool::GetActionSet()
{
if (ToolActionSet == nullptr)
{
ToolActionSet = new FInteractiveToolActionSet();
RegisterActions(*ToolActionSet);
}
return ToolActionSet;
}
void UInteractiveTool::ExecuteAction(int32 ActionID)
{
GetActionSet()->ExecuteAction(ActionID);
}
bool UInteractiveTool::HasCancel() const
{
return false;
}
bool UInteractiveTool::HasAccept() const
{
return false;
}
bool UInteractiveTool::CanAccept() const
{
return false;
}
void UInteractiveTool::Tick(float DeltaTime)
{
for (auto* Object : ToolPropertyObjects)
{
auto* Propset = Cast<UInteractiveToolPropertySet>(Object);
if ( Propset != nullptr )
{
if ( Propset->IsPropertySetEnabled() )
{
Propset->CheckAndUpdateWatched();
}
else
{
Propset->SilentUpdateWatched();
}
}
}
OnTick(DeltaTime);
}
UInteractiveToolManager* UInteractiveTool::GetToolManager() const
{
UInteractiveToolManager* ToolManager = Cast<UInteractiveToolManager>(GetOuter());
check(ToolManager != nullptr);
return ToolManager;
}
#undef LOCTEXT_NAMESPACE