2020-10-08 18:56:55 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "Tools/PlacementLassoSelectTool.h"
|
2021-02-08 17:13:32 -04:00
|
|
|
|
|
|
|
|
#include "AssetPlacementEdMode.h"
|
|
|
|
|
#include "AssetPlacementSettings.h"
|
2021-02-22 12:53:35 -04:00
|
|
|
#include "Editor.h"
|
2021-02-08 17:13:32 -04:00
|
|
|
#include "Elements/Framework/EngineElementsLibrary.h"
|
|
|
|
|
#include "Elements/Framework/TypedElementHandle.h"
|
|
|
|
|
#include "Elements/Framework/TypedElementRegistry.h"
|
|
|
|
|
#include "Elements/Interfaces/TypedElementObjectInterface.h"
|
2020-10-08 18:56:55 -04:00
|
|
|
#include "InteractiveToolManager.h"
|
2021-02-08 17:13:32 -04:00
|
|
|
#include "InstancedFoliageActor.h"
|
|
|
|
|
#include "ToolContextInterfaces.h"
|
|
|
|
|
#include "UObject/Object.h"
|
|
|
|
|
#include "BaseBehaviors/KeyAsModifierInputBehavior.h"
|
|
|
|
|
#include "Elements/Framework/TypedElementSelectionSet.h"
|
2021-02-18 13:11:17 -04:00
|
|
|
#include "Modes/PlacementModeSubsystem.h"
|
2021-05-05 15:22:49 -04:00
|
|
|
#include "Tools/AssetEditorContextInterface.h"
|
|
|
|
|
#include "EditorModeManager.h"
|
|
|
|
|
#include "ContextObjectStore.h"
|
2020-10-08 18:56:55 -04:00
|
|
|
|
|
|
|
|
constexpr TCHAR UPlacementModeLassoSelectTool::ToolName[];
|
|
|
|
|
|
2021-06-23 17:43:35 -04:00
|
|
|
namespace PlacementModeLassoToolInternal
|
|
|
|
|
{
|
|
|
|
|
FTypedElementSelectionOptions SelectionOptions {};
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-08 17:13:32 -04:00
|
|
|
UPlacementBrushToolBase* UPlacementModeLassoSelectToolBuilder::FactoryToolInstance(UObject* Outer) const
|
2020-10-08 18:56:55 -04:00
|
|
|
{
|
2021-02-08 17:13:32 -04:00
|
|
|
return NewObject<UPlacementModeLassoSelectTool>(Outer);
|
2020-10-08 18:56:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-08 17:13:32 -04:00
|
|
|
void UPlacementModeLassoSelectTool::OnBeginDrag(const FRay& Ray)
|
2020-10-08 18:56:55 -04:00
|
|
|
{
|
2021-02-08 17:13:32 -04:00
|
|
|
Super::OnBeginDrag(Ray);
|
|
|
|
|
|
2021-06-23 17:43:35 -04:00
|
|
|
ElementsFromDrag.Empty();
|
2021-02-08 17:13:32 -04:00
|
|
|
GetToolManager()->BeginUndoTransaction(NSLOCTEXT("AssetPlacementEdMode", "BrushSelect", "Select Elements"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UPlacementModeLassoSelectTool::OnEndDrag(const FRay& Ray)
|
|
|
|
|
{
|
2021-06-23 17:43:35 -04:00
|
|
|
if (IAssetEditorContextInterface* AssetEditorContext = GetToolManager()->GetContextObjectStore()->FindContext<IAssetEditorContextInterface>())
|
|
|
|
|
{
|
|
|
|
|
if (UTypedElementSelectionSet* SelectionSet = AssetEditorContext->GetMutableSelectionSet())
|
|
|
|
|
{
|
|
|
|
|
bool bSelectElements = !bCtrlToggle;
|
|
|
|
|
for (const FTypedElementHandle& HitElement : ElementsFromDrag)
|
|
|
|
|
{
|
|
|
|
|
if (!FoliageElementUtil::FoliageInstanceElementsEnabled())
|
|
|
|
|
{
|
|
|
|
|
if (TTypedElement<UTypedElementObjectInterface> ObjectInterface = UTypedElementRegistry::GetInstance()->GetElement<UTypedElementObjectInterface>(HitElement))
|
|
|
|
|
{
|
|
|
|
|
if (AInstancedFoliageActor* FoliageActor = ObjectInterface.GetObjectAs<AInstancedFoliageActor>())
|
|
|
|
|
{
|
|
|
|
|
FoliageActor->ForEachFoliageInfo([this, bSelectElements](UFoliageType* InFoliageType, FFoliageInfo& InFoliageInfo)
|
|
|
|
|
{
|
|
|
|
|
FTypedElementHandle SourceObjectHandle = UEngineElementsLibrary::AcquireEditorObjectElementHandle(InFoliageType->GetSource());
|
|
|
|
|
if (GEditor->GetEditorSubsystem<UPlacementModeSubsystem>()->DoesCurrentPaletteSupportElement(SourceObjectHandle))
|
|
|
|
|
{
|
|
|
|
|
TArray<int32> Instances;
|
|
|
|
|
FSphere SphereToCheck(LastBrushStamp.WorldPosition, LastBrushStamp.Radius);
|
|
|
|
|
InFoliageInfo.GetInstancesInsideSphere(SphereToCheck, Instances);
|
|
|
|
|
InFoliageInfo.SelectInstances(bSelectElements, Instances);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bSelectElements)
|
|
|
|
|
{
|
|
|
|
|
SelectionSet->SelectElement(HitElement, PlacementModeLassoToolInternal::SelectionOptions);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SelectionSet->DeselectElement(HitElement, PlacementModeLassoToolInternal::SelectionOptions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-08 17:13:32 -04:00
|
|
|
GetToolManager()->EndUndoTransaction();
|
|
|
|
|
|
|
|
|
|
Super::OnEndDrag(Ray);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UPlacementModeLassoSelectTool::OnTick(float DeltaTime)
|
|
|
|
|
{
|
|
|
|
|
if (!bInBrushStroke)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 17:43:35 -04:00
|
|
|
ElementsFromDrag.Append(GetElementsInBrushRadius(LastDeviceInputRay));
|
2020-10-08 18:56:55 -04:00
|
|
|
}
|