2020-04-21 23:51:57 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
2020-08-11 01:36:57 -04:00
|
|
|
#include "PropertySets/OnAcceptProperties.h"
|
2020-04-21 23:51:57 -04:00
|
|
|
|
2020-04-22 02:32:09 -04:00
|
|
|
#include "GameFramework/Actor.h"
|
|
|
|
|
#include "UObject/UObjectGlobals.h"
|
2020-04-21 23:51:57 -04:00
|
|
|
#include "InteractiveToolManager.h"
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "UOnAcceptHandleSourcesProperties"
|
|
|
|
|
|
|
|
|
|
|
2021-10-28 11:24:32 -04:00
|
|
|
void UOnAcceptHandleSourcesPropertiesBase::ApplyMethod(const TArray<AActor*>& Actors, UInteractiveToolManager* ToolManager, const AActor* MustKeepActor)
|
2020-04-21 23:51:57 -04:00
|
|
|
{
|
2021-10-28 11:24:32 -04:00
|
|
|
const EHandleSourcesMethod HandleInputs = GetHandleInputs();
|
|
|
|
|
|
2020-04-21 23:51:57 -04:00
|
|
|
// Hide or destroy the sources
|
2021-10-28 11:24:32 -04:00
|
|
|
bool bKeepSources = HandleInputs == EHandleSourcesMethod::KeepSources;
|
|
|
|
|
if (Actors.Num() == 1 && (HandleInputs == EHandleSourcesMethod::KeepFirstSource || HandleInputs == EHandleSourcesMethod::KeepLastSource))
|
2020-04-21 23:51:57 -04:00
|
|
|
{
|
2021-03-10 23:10:46 -04:00
|
|
|
// if there's only one actor, keeping any source == keeping all sources
|
|
|
|
|
bKeepSources = true;
|
|
|
|
|
}
|
|
|
|
|
if (!bKeepSources)
|
|
|
|
|
{
|
2021-10-28 11:24:32 -04:00
|
|
|
bool bDelete = HandleInputs == EHandleSourcesMethod::DeleteSources
|
|
|
|
|
|| HandleInputs == EHandleSourcesMethod::KeepFirstSource
|
|
|
|
|
|| HandleInputs == EHandleSourcesMethod::KeepLastSource;
|
2020-04-21 23:51:57 -04:00
|
|
|
if (bDelete)
|
|
|
|
|
{
|
2021-10-28 11:24:32 -04:00
|
|
|
ToolManager->BeginUndoTransaction(LOCTEXT("RemoveSources", "Remove Inputs"));
|
2020-04-21 23:51:57 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#if WITH_EDITOR
|
2021-10-28 11:24:32 -04:00
|
|
|
ToolManager->BeginUndoTransaction(LOCTEXT("HideSources", "Hide Inputs"));
|
2020-04-21 23:51:57 -04:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 11:24:32 -04:00
|
|
|
const int32 ActorIdxBegin = HandleInputs == EHandleSourcesMethod::KeepFirstSource ? 1 : 0;
|
|
|
|
|
const int32 ActorIdxEnd = HandleInputs == EHandleSourcesMethod::KeepLastSource ? Actors.Num() - 1 : Actors.Num();
|
2021-03-10 23:10:46 -04:00
|
|
|
|
2021-10-28 11:24:32 -04:00
|
|
|
for (int32 ActorIdx = ActorIdxBegin; ActorIdx < ActorIdxEnd; ActorIdx++)
|
|
|
|
|
{
|
2021-03-10 23:10:46 -04:00
|
|
|
AActor* Actor = Actors[ActorIdx];
|
2021-10-25 20:05:28 -04:00
|
|
|
if (Actor == MustKeepActor)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 23:51:57 -04:00
|
|
|
if (bDelete)
|
|
|
|
|
{
|
|
|
|
|
Actor->Destroy();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
// Save the actor to the transaction buffer to support undo/redo, but do
|
|
|
|
|
// not call Modify, as we do not want to dirty the actor's package and
|
|
|
|
|
// we're only editing temporary, transient values
|
|
|
|
|
SaveToTransactionBuffer(Actor, false);
|
|
|
|
|
Actor->SetIsTemporarilyHiddenInEditor(true);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (bDelete)
|
|
|
|
|
{
|
|
|
|
|
ToolManager->EndUndoTransaction();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
ToolManager->EndUndoTransaction();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|