2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2019-04-04 16:11:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "InteractiveToolsContext.h"
|
2020-12-03 09:48:56 -04:00
|
|
|
#include "ToolTargetManager.h"
|
2019-04-04 16:11:44 -04:00
|
|
|
|
|
|
|
|
UInteractiveToolsContext::UInteractiveToolsContext()
|
|
|
|
|
{
|
|
|
|
|
InputRouter = nullptr;
|
|
|
|
|
ToolManager = nullptr;
|
2020-12-03 09:48:56 -04:00
|
|
|
TargetManager = nullptr;
|
2019-10-24 14:44:46 -04:00
|
|
|
ToolManagerClass = UInteractiveToolManager::StaticClass();
|
2019-04-04 16:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UInteractiveToolsContext::Initialize(IToolsContextQueriesAPI* QueriesAPI, IToolsContextTransactionsAPI* TransactionsAPI)
|
|
|
|
|
{
|
|
|
|
|
InputRouter = NewObject<UInputRouter>(this);
|
|
|
|
|
InputRouter->Initialize(TransactionsAPI);
|
|
|
|
|
|
2019-10-24 14:44:46 -04:00
|
|
|
ToolManager = NewObject<UInteractiveToolManager>(this, ToolManagerClass.Get());
|
2019-04-04 16:11:44 -04:00
|
|
|
ToolManager->Initialize(QueriesAPI, TransactionsAPI, InputRouter);
|
2019-04-23 10:26:37 -04:00
|
|
|
|
2020-12-03 09:48:56 -04:00
|
|
|
TargetManager = NewObject<UToolTargetManager>(this);
|
|
|
|
|
TargetManager->Initialize();
|
|
|
|
|
|
2019-04-23 10:26:37 -04:00
|
|
|
GizmoManager = NewObject<UInteractiveGizmoManager>(this);
|
|
|
|
|
GizmoManager->Initialize(QueriesAPI, TransactionsAPI, InputRouter);
|
ToolsFramework: Standard implementations of Gizmos for axis position/angle and plane position. Used to implement a standard 3-axis translate/rotate transformer.
InteractiveGizmoManager now tracks Owner of Gizmos, for delete-by-owner support. Added Create3AxisTransformGizmo() to create standard Gizmo.
GizmoInterfaces.h: UInterfaces for gizmo components
AxisPositionGizmo, AxisAngleGizmo, PlanePositionGizmo: standard implementations of UInteractiveGizmo
GizmoBaseComponent, GizmoArrowComponent, GizmoRectangleComponent, GizmoCircleComponent: custom UPrimitiveComponent implementations for standard Gizmos
TransformGizmo: 3-axis transform gizmo built out of above elements
AxisSources.h, ParameterSourcesFloat/Vec2.h, StateTargets.h, HitTargets.h, TransformSources.h: UObjects used by Gizmos to expose implementation for customization.
ParameterToTransformAdapters.h: Gizmo ParameterSource implementations that convert axis/plane position and axis-angle to 3D translations/rotations
TransformProxy: wrapper around set of objects that provides a single FTransform, used by TransformGizmo to apply to multiple objects/etc
GizmoMath.h, GizmoRenderingUtil.h: utility functions for Gizmo implementation
#fyi Lauren.Ridge
#rb Michael.Daum
#rnx
[CL 8618015 by Ryan Schmidt in Dev-Editor branch]
2019-09-10 14:14:29 -04:00
|
|
|
|
|
|
|
|
GizmoManager->RegisterDefaultGizmos();
|
2019-04-04 16:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UInteractiveToolsContext::Shutdown()
|
|
|
|
|
{
|
|
|
|
|
// force-terminate any remaining captures/hovers/etc
|
|
|
|
|
InputRouter->ForceTerminateAll();
|
|
|
|
|
InputRouter->Shutdown();
|
|
|
|
|
InputRouter = nullptr;
|
|
|
|
|
|
2019-04-23 10:26:37 -04:00
|
|
|
GizmoManager->Shutdown();
|
|
|
|
|
GizmoManager = nullptr;
|
|
|
|
|
|
2019-04-04 16:11:44 -04:00
|
|
|
ToolManager->Shutdown();
|
|
|
|
|
ToolManager = nullptr;
|
|
|
|
|
}
|
2019-09-10 12:01:07 -04:00
|
|
|
|
|
|
|
|
void UInteractiveToolsContext::DeactivateActiveTool(EToolSide WhichSide, EToolShutdownType ShutdownType)
|
|
|
|
|
{
|
|
|
|
|
ToolManager->DeactivateTool(WhichSide, ShutdownType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UInteractiveToolsContext::DeactivateAllActiveTools()
|
|
|
|
|
{
|
|
|
|
|
if (ToolManager->HasActiveTool(EToolSide::Left))
|
|
|
|
|
{
|
|
|
|
|
EToolShutdownType ShutdownType = ToolManager->CanAcceptActiveTool(EToolSide::Left) ?
|
|
|
|
|
EToolShutdownType::Accept : EToolShutdownType::Cancel;
|
|
|
|
|
ToolManager->DeactivateTool(EToolSide::Left, ShutdownType);
|
|
|
|
|
}
|
|
|
|
|
if (ToolManager->HasActiveTool(EToolSide::Right))
|
|
|
|
|
{
|
|
|
|
|
EToolShutdownType ShutdownType = ToolManager->CanAcceptActiveTool(EToolSide::Right) ?
|
|
|
|
|
EToolShutdownType::Accept : EToolShutdownType::Cancel;
|
|
|
|
|
ToolManager->DeactivateTool(EToolSide::Right, ShutdownType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UInteractiveToolsContext::CanStartTool(EToolSide WhichSide, const FString& ToolTypeIdentifier) const
|
|
|
|
|
{
|
2020-11-05 18:33:19 -04:00
|
|
|
return ToolManager->CanActivateTool(WhichSide, ToolTypeIdentifier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UInteractiveToolsContext::HasActiveTool(EToolSide WhichSide) const
|
|
|
|
|
{
|
|
|
|
|
return ToolManager->HasActiveTool(WhichSide);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString UInteractiveToolsContext::GetActiveToolName(EToolSide WhichSide) const
|
|
|
|
|
{
|
|
|
|
|
return ToolManager->GetActiveToolName(WhichSide);
|
2019-09-10 12:01:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UInteractiveToolsContext::ActiveToolHasAccept(EToolSide WhichSide) const
|
|
|
|
|
{
|
|
|
|
|
return ToolManager->HasActiveTool(WhichSide) &&
|
|
|
|
|
ToolManager->GetActiveTool(WhichSide)->HasAccept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UInteractiveToolsContext::CanAcceptActiveTool(EToolSide WhichSide) const
|
|
|
|
|
{
|
|
|
|
|
return ToolManager->CanAcceptActiveTool(WhichSide);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UInteractiveToolsContext::CanCancelActiveTool(EToolSide WhichSide) const
|
|
|
|
|
{
|
|
|
|
|
return ToolManager->CanCancelActiveTool(WhichSide);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UInteractiveToolsContext::CanCompleteActiveTool(EToolSide WhichSide) const
|
|
|
|
|
{
|
|
|
|
|
return ToolManager->HasActiveTool(WhichSide) && CanCancelActiveTool(WhichSide) == false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UInteractiveToolsContext::StartTool(EToolSide WhichSide, const FString& ToolTypeIdentifier)
|
|
|
|
|
{
|
|
|
|
|
if (ToolManager->SelectActiveToolType(WhichSide, ToolTypeIdentifier) == false)
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("ToolManager: Unknown Tool Type %s"), *ToolTypeIdentifier);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ToolManager->ActivateTool(WhichSide);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UInteractiveToolsContext::EndTool(EToolSide WhichSide, EToolShutdownType ShutdownType)
|
|
|
|
|
{
|
|
|
|
|
DeactivateActiveTool(WhichSide, ShutdownType);
|
|
|
|
|
}
|
2019-10-24 14:44:46 -04:00
|
|
|
|
2020-12-09 16:32:39 -04:00
|
|
|
// Note: this takes FString by value so that it can be bound to delegates using CreateUObject. If you change it
|
|
|
|
|
// to a reference, you'll need to use CreateWeakLambda instead and capture ToolIdentifier by value there.
|
|
|
|
|
bool UInteractiveToolsContext::IsToolActive(EToolSide WhichSide, const FString ToolIdentifier) const
|
2019-10-24 14:44:46 -04:00
|
|
|
{
|
2020-12-09 16:32:39 -04:00
|
|
|
return GetActiveToolName(WhichSide) == ToolIdentifier;
|
2019-10-24 14:44:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UInteractiveToolsContext::PostToolNotificationMessage(const FText& Message)
|
|
|
|
|
{
|
|
|
|
|
OnToolNotificationMessage.Broadcast(Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UInteractiveToolsContext::PostToolWarningMessage(const FText& Message)
|
|
|
|
|
{
|
|
|
|
|
OnToolWarningMessage.Broadcast(Message);
|
|
|
|
|
}
|