2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2019-04-04 16:11:44 -04:00
# include "InteractiveToolManager.h"
2020-11-13 14:07:30 -04:00
# include "Engine/Engine.h"
2019-09-10 12:01:07 -04:00
# include "InteractiveToolsContext.h"
2021-05-05 12:42:29 -04:00
# include "ContextObjectStore.h"
2019-09-10 14:40:38 -04:00
2022-09-24 13:57:58 -04:00
# include UE_INLINE_GENERATED_CPP_BY_NAME(InteractiveToolManager)
2019-09-10 14:40:38 -04:00
# define LOCTEXT_NAMESPACE "UInteractiveToolManager"
2019-04-04 16:11:44 -04:00
UInteractiveToolManager : : UInteractiveToolManager ( )
{
QueriesAPI = nullptr ;
TransactionsAPI = nullptr ;
InputRouter = nullptr ;
ActiveLeftBuilder = nullptr ;
ActiveLeftTool = nullptr ;
ActiveRightBuilder = nullptr ;
ActiveRightTool = nullptr ;
2020-02-22 17:01:16 -05:00
ActiveToolChangeTrackingMode = EToolChangeTrackingMode : : UndoToExit ;
2019-04-04 16:11:44 -04:00
}
void UInteractiveToolManager : : Initialize ( IToolsContextQueriesAPI * queriesAPI , IToolsContextTransactionsAPI * transactionsAPI , UInputRouter * InputRouterIn )
{
this - > QueriesAPI = queriesAPI ;
this - > TransactionsAPI = transactionsAPI ;
this - > InputRouter = InputRouterIn ;
2020-03-19 10:59:25 -04:00
bIsActive = true ;
2019-04-04 16:11:44 -04:00
}
void UInteractiveToolManager : : Shutdown ( )
{
this - > QueriesAPI = nullptr ;
if ( ActiveLeftTool ! = nullptr )
{
DeactivateTool ( EToolSide : : Left , EToolShutdownType : : Cancel ) ;
}
if ( ActiveRightTool ! = nullptr )
{
DeactivateTool ( EToolSide : : Right , EToolShutdownType : : Cancel ) ;
}
this - > TransactionsAPI = nullptr ;
2020-03-19 10:59:25 -04:00
bIsActive = false ;
2019-04-04 16:11:44 -04:00
}
2021-03-31 08:34:48 -04:00
void UInteractiveToolManager : : DoPostBuild ( EToolSide Side , UInteractiveTool * InBuiltTool , UInteractiveToolBuilder * InToolBuilder , const FToolBuilderState & InBuilderState )
{
2021-08-03 20:17:09 -04:00
InToolBuilder - > PostBuildTool ( InBuiltTool , InBuilderState ) ;
2021-03-31 08:34:48 -04:00
OnToolPostBuild . Broadcast ( this , Side , InBuiltTool , InToolBuilder , InBuilderState ) ;
}
2021-08-03 20:17:09 -04:00
void UInteractiveToolManager : : DoPostSetup ( EToolSide Side , UInteractiveTool * InInteractiveTool , UInteractiveToolBuilder * InToolBuilder , const FToolBuilderState & InBuilderState )
2021-03-31 08:34:48 -04:00
{
2021-08-03 20:17:09 -04:00
InToolBuilder - > PostSetupTool ( InInteractiveTool , InBuilderState ) ;
2021-03-31 08:34:48 -04:00
OnToolPostSetup . Broadcast ( this , Side , InInteractiveTool ) ;
}
2019-04-04 16:11:44 -04:00
void UInteractiveToolManager : : RegisterToolType ( const FString & Identifier , UInteractiveToolBuilder * Builder )
{
2021-05-28 02:04:32 -04:00
if ( ensure ( ToolBuilders . Contains ( Identifier ) = = false ) )
{
ToolBuilders . Add ( Identifier , Builder ) ;
}
2019-04-04 16:11:44 -04:00
}
2020-09-02 15:43:58 -04:00
void UInteractiveToolManager : : UnregisterToolType ( const FString & Identifier )
{
if ( ActiveLeftToolName = = Identifier )
{
DeactivateTool ( EToolSide : : Left , EToolShutdownType : : Cancel ) ;
}
if ( ActiveRightToolName = = Identifier )
{
DeactivateTool ( EToolSide : : Right , EToolShutdownType : : Cancel ) ;
}
ToolBuilders . Remove ( Identifier ) ;
}
2019-04-04 16:11:44 -04:00
bool UInteractiveToolManager : : SelectActiveToolType ( EToolSide Side , const FString & Identifier )
{
if ( ToolBuilders . Contains ( Identifier ) )
{
UInteractiveToolBuilder * Builder = ToolBuilders [ Identifier ] ;
if ( Side = = EToolSide : : Right )
{
ActiveRightBuilder = Builder ;
2020-02-22 17:01:16 -05:00
ActiveRightBuilderName = Identifier ;
2019-04-04 16:11:44 -04:00
}
else
{
ActiveLeftBuilder = Builder ;
2020-02-22 17:01:16 -05:00
ActiveLeftBuilderName = Identifier ;
2019-04-04 16:11:44 -04:00
}
return true ;
}
return false ;
}
2020-10-08 18:56:55 -04:00
bool UInteractiveToolManager : : CanActivateTool ( EToolSide Side , FString Identifier )
2019-04-04 16:11:44 -04:00
{
2021-05-28 02:04:32 -04:00
if ( ensure ( Side = = EToolSide : : Left ) = = false ) // TODO: support right-side tool
{
return false ;
}
2019-04-04 16:11:44 -04:00
if ( ToolBuilders . Contains ( Identifier ) )
{
FToolBuilderState InputState ;
QueriesAPI - > GetCurrentSelectionState ( InputState ) ;
UInteractiveToolBuilder * Builder = ToolBuilders [ Identifier ] ;
return Builder - > CanBuildTool ( InputState ) ;
}
return false ;
}
bool UInteractiveToolManager : : ActivateTool ( EToolSide Side )
{
2021-05-28 02:04:32 -04:00
if ( ensure ( Side = = EToolSide : : Left ) = = false ) // TODO: support right-side tool
{
return false ;
}
2019-04-04 16:11:44 -04:00
2020-02-22 17:01:16 -05:00
// wrap tool change in a transaction so that deactivate and activate are grouped
bool bInTransaction = false ;
if ( ActiveToolChangeTrackingMode = = EToolChangeTrackingMode : : FullUndoRedo )
{
BeginUndoTransaction ( LOCTEXT ( " ToolChange " , " Change Tool " ) ) ;
bInTransaction = true ;
}
if ( ActiveLeftTool ! = nullptr )
2019-04-04 16:11:44 -04:00
{
2021-08-24 14:36:58 -04:00
DeactivateTool ( EToolSide : : Left , ActiveLeftTool - > CanAccept ( ) ? EToolShutdownType : : Accept : EToolShutdownType : : Completed ) ;
2019-04-04 16:11:44 -04:00
}
2020-02-22 17:01:16 -05:00
if ( ActiveLeftBuilder = = nullptr | | ActivateToolInternal ( Side ) = = false )
2019-04-04 16:11:44 -04:00
{
2020-02-22 17:01:16 -05:00
if ( bInTransaction )
{
EndUndoTransaction ( ) ;
}
2019-04-04 16:11:44 -04:00
return false ;
}
2020-02-22 17:01:16 -05:00
if ( ActiveToolChangeTrackingMode = = EToolChangeTrackingMode : : FullUndoRedo )
{
2021-05-28 02:04:32 -04:00
if ( ensure ( TransactionsAPI ) )
{
TransactionsAPI - > AppendChange ( this , MakeUnique < FActivateToolChange > ( Side , ActiveLeftToolName ) , LOCTEXT ( " ActivateToolChange " , " Activate Tool " ) ) ;
}
2020-02-22 17:01:16 -05:00
}
else if ( ActiveToolChangeTrackingMode = = EToolChangeTrackingMode : : UndoToExit )
{
EmitObjectChange ( this , MakeUnique < FBeginToolChange > ( ) , LOCTEXT ( " ActivateToolChange " , " Activate Tool " ) ) ;
}
if ( bInTransaction )
{
EndUndoTransaction ( ) ;
}
return true ;
}
bool UInteractiveToolManager : : ActivateToolInternal ( EToolSide Side )
{
2020-11-13 14:07:30 -04:00
// We'll keep track of whether the last activated tool has dealt with the stored
// tool selection, because we want the default behavior to be a clear of the stored
// tool selection on the invocation of any tool that doesn't do anything with it.
bActiveToolMadeSelectionStoreRequest = false ; // TODO: When we support multiple sides, this approach will need adjustment
2019-04-04 16:11:44 -04:00
// construct input state we will pass to tools
FToolBuilderState InputState ;
QueriesAPI - > GetCurrentSelectionState ( InputState ) ;
if ( ActiveLeftBuilder - > CanBuildTool ( InputState ) = = false )
{
2020-02-22 17:01:16 -05:00
TransactionsAPI - > DisplayMessage ( LOCTEXT ( " ActivateToolCanBuildFailMessage " , " UInteractiveToolManager::ActivateTool: CanBuildTool returned false. " ) , EToolMessageLevel : : Internal ) ;
2019-04-04 16:11:44 -04:00
return false ;
}
ActiveLeftTool = ActiveLeftBuilder - > BuildTool ( InputState ) ;
if ( ActiveLeftTool = = nullptr )
{
return false ;
}
2020-02-22 17:01:16 -05:00
ActiveLeftToolName = ActiveLeftBuilderName ;
2021-03-31 08:34:48 -04:00
DoPostBuild ( Side , ActiveLeftTool , ActiveLeftBuilder , InputState ) ;
2019-04-04 16:11:44 -04:00
2022-11-29 12:35:38 -05:00
bInToolSetup = true ;
2019-04-04 16:11:44 -04:00
ActiveLeftTool - > Setup ( ) ;
2022-11-29 12:35:38 -05:00
bInToolSetup = false ;
if ( bToolRequestedTerminationDuringSetup )
{
bToolRequestedTerminationDuringSetup = false ;
ActiveLeftTool - > Shutdown ( EToolShutdownType : : Cancel ) ; // need to give Tool a chance to clean up...
ActiveLeftTool = nullptr ;
ActiveLeftToolName . Empty ( ) ;
return false ;
}
2021-08-03 20:17:09 -04:00
DoPostSetup ( Side , ActiveLeftTool , ActiveLeftBuilder , InputState ) ;
2019-04-04 16:11:44 -04:00
// register new active input behaviors
InputRouter - > RegisterSource ( ActiveLeftTool ) ;
PostInvalidation ( ) ;
2019-05-06 15:41:42 -04:00
OnToolStarted . Broadcast ( this , ActiveLeftTool ) ;
2019-04-04 16:11:44 -04:00
return true ;
}
2020-02-22 17:01:16 -05:00
2019-04-04 16:11:44 -04:00
void UInteractiveToolManager : : DeactivateTool ( EToolSide Side , EToolShutdownType ShutdownType )
{
2021-05-28 02:04:32 -04:00
if ( ensure ( Side = = EToolSide : : Left ) = = false ) // TODO: support right-side tool
{
return ;
}
2023-04-24 23:20:54 -04:00
if ( bInToolShutdown )
{
return ;
}
2021-05-28 02:04:32 -04:00
2019-04-04 16:11:44 -04:00
if ( ActiveLeftTool ! = nullptr )
{
2020-02-22 17:01:16 -05:00
if ( ActiveToolChangeTrackingMode = = EToolChangeTrackingMode : : FullUndoRedo )
{
2021-05-28 02:04:32 -04:00
if ( ensure ( TransactionsAPI ) )
{
TransactionsAPI - > AppendChange ( this , MakeUnique < FActivateToolChange > ( Side , ActiveLeftToolName , ShutdownType ) , LOCTEXT ( " DeactivateToolChange " , " Deactivate Tool " ) ) ;
}
2020-02-22 17:01:16 -05:00
}
DeactivateToolInternal ( Side , ShutdownType ) ;
}
}
void UInteractiveToolManager : : DeactivateToolInternal ( EToolSide Side , EToolShutdownType ShutdownType )
{
if ( Side = = EToolSide : : Left )
{
2021-05-28 02:04:32 -04:00
if ( ! ensure ( ActiveLeftTool ) )
{
return ;
}
2023-04-24 23:20:54 -04:00
bInToolShutdown = true ;
2019-04-04 16:11:44 -04:00
InputRouter - > ForceTerminateSource ( ActiveLeftTool ) ;
ActiveLeftTool - > Shutdown ( ShutdownType ) ;
InputRouter - > DeregisterSource ( ActiveLeftTool ) ;
2019-05-06 15:41:42 -04:00
UInteractiveTool * DoneTool = ActiveLeftTool ;
2019-04-04 16:11:44 -04:00
ActiveLeftTool = nullptr ;
2020-02-22 17:01:16 -05:00
ActiveLeftToolName . Empty ( ) ;
2019-04-04 16:11:44 -04:00
PostInvalidation ( ) ;
2019-05-06 15:41:42 -04:00
2023-10-23 22:46:23 -04:00
OnToolEndedWithStatus . Broadcast ( this , DoneTool , ShutdownType ) ;
2019-05-06 15:41:42 -04:00
OnToolEnded . Broadcast ( this , DoneTool ) ;
2023-04-24 23:20:54 -04:00
bInToolShutdown = false ;
2019-04-04 16:11:44 -04:00
}
}
2020-02-22 17:01:16 -05:00
2019-04-27 20:21:05 -04:00
bool UInteractiveToolManager : : HasActiveTool ( EToolSide Side ) const
2019-04-04 16:11:44 -04:00
{
return ( Side = = EToolSide : : Left ) ? ( ActiveLeftTool ! = nullptr ) : ( ActiveRightTool ! = nullptr ) ;
}
2019-04-27 20:21:05 -04:00
bool UInteractiveToolManager : : HasAnyActiveTool ( ) const
{
return ActiveLeftTool ! = nullptr | | ActiveRightTool ! = nullptr ;
}
2019-04-04 16:11:44 -04:00
UInteractiveTool * UInteractiveToolManager : : GetActiveTool ( EToolSide Side )
{
return ( Side = = EToolSide : : Left ) ? ActiveLeftTool : ActiveRightTool ;
}
2019-10-24 16:55:47 -04:00
UInteractiveToolBuilder * UInteractiveToolManager : : GetActiveToolBuilder ( EToolSide Side )
{
return ( Side = = EToolSide : : Left ) ? ActiveLeftBuilder : ActiveRightBuilder ;
}
2020-03-27 14:26:54 -04:00
FString UInteractiveToolManager : : GetActiveToolName ( EToolSide Side )
{
if ( GetActiveTool ( Side ) = = nullptr )
{
return FString ( ) ;
}
2020-03-30 12:05:28 -04:00
return ( Side = = EToolSide : : Left ) ? ActiveLeftToolName : ActiveRightToolName ;
2020-03-27 14:26:54 -04:00
}
2019-04-04 16:11:44 -04:00
bool UInteractiveToolManager : : CanAcceptActiveTool ( EToolSide Side )
{
if ( ActiveLeftTool ! = nullptr )
{
return ActiveLeftTool - > HasAccept ( ) & & ActiveLeftTool - > CanAccept ( ) ;
}
return false ;
}
bool UInteractiveToolManager : : CanCancelActiveTool ( EToolSide Side )
{
if ( ActiveLeftTool ! = nullptr )
{
return ActiveLeftTool - > HasCancel ( ) ;
}
return false ;
}
2020-02-22 17:01:16 -05:00
void UInteractiveToolManager : : ConfigureChangeTrackingMode ( EToolChangeTrackingMode ChangeMode )
{
ActiveToolChangeTrackingMode = ChangeMode ;
}
2019-04-04 16:11:44 -04:00
void UInteractiveToolManager : : Tick ( float DeltaTime )
{
if ( ActiveLeftTool ! = nullptr )
{
ActiveLeftTool - > Tick ( DeltaTime ) ;
}
if ( ActiveRightTool ! = nullptr )
{
ActiveRightTool - > Tick ( DeltaTime ) ;
}
}
void UInteractiveToolManager : : Render ( IToolsContextRenderAPI * RenderAPI )
{
if ( ActiveLeftTool ! = nullptr )
{
ActiveLeftTool - > Render ( RenderAPI ) ;
}
if ( ActiveRightTool ! = nullptr )
{
ActiveRightTool - > Render ( RenderAPI ) ;
}
}
2020-09-18 09:25:18 -04:00
void UInteractiveToolManager : : DrawHUD ( FCanvas * Canvas , IToolsContextRenderAPI * RenderAPI )
2020-08-31 16:54:59 -04:00
{
if ( ActiveLeftTool ! = nullptr )
{
2020-09-18 09:25:18 -04:00
ActiveLeftTool - > DrawHUD ( Canvas , RenderAPI ) ;
2020-08-31 16:54:59 -04:00
}
if ( ActiveRightTool ! = nullptr )
{
2020-09-18 09:25:18 -04:00
ActiveRightTool - > DrawHUD ( Canvas , RenderAPI ) ;
2020-08-31 16:54:59 -04:00
}
}
2019-04-04 16:11:44 -04:00
2019-09-10 12:01:07 -04:00
UInteractiveGizmoManager * UInteractiveToolManager : : GetPairedGizmoManager ( )
{
return Cast < UInteractiveToolsContext > ( GetOuter ( ) ) - > GizmoManager ;
}
2021-05-05 12:42:29 -04:00
UContextObjectStore * UInteractiveToolManager : : GetContextObjectStore ( ) const
{
return Cast < UInteractiveToolsContext > ( GetOuter ( ) ) - > ContextObjectStore ;
}
2019-09-16 14:06:18 -04:00
void UInteractiveToolManager : : DisplayMessage ( const FText & Message , EToolMessageLevel Level )
2019-04-08 15:37:19 -04:00
{
2019-09-16 14:06:18 -04:00
TransactionsAPI - > DisplayMessage ( Message , Level ) ;
2019-04-08 15:37:19 -04:00
}
2019-04-04 16:11:44 -04:00
void UInteractiveToolManager : : PostInvalidation ( )
{
TransactionsAPI - > PostInvalidation ( ) ;
}
void UInteractiveToolManager : : BeginUndoTransaction ( const FText & Description )
{
TransactionsAPI - > BeginUndoTransaction ( Description ) ;
}
void UInteractiveToolManager : : EndUndoTransaction ( )
{
TransactionsAPI - > EndUndoTransaction ( ) ;
}
2019-09-23 21:52:12 -04:00
void UInteractiveToolManager : : EmitObjectChange ( UObject * TargetObject , TUniquePtr < FToolCommandChange > Change , const FText & Description )
2019-04-04 16:11:44 -04:00
{
2021-05-28 02:04:32 -04:00
// Currently we do not support undo/redo of changes emitted /during/ a Tool after the Tool exits,
// because we do not support "undo back into a Tool". So once a Tool exits, any Changes it emitted are considered invalid.
// We do not assume we can modify the external history/transaction system (because in the Editor we cannot)
// so all we can do is mark those changes as "expired" and hope that the external transaction system respects that.
// The Tools themselves will not be around to know whether they have exited, so we wrap
// the changes they emit in a FToolChangeWrapperChange which will allow the ToolManager
// to decide whether the change is still valid/applicable.
2019-09-10 14:40:38 -04:00
2021-05-28 02:04:32 -04:00
// Note: if you do not want this wrapping behavior for particular changes, you can use the TransactionsAPI directly
// via GetContextTransactionsAPI()
// If you hit this ensure from a Gizmo, you may have accidentally registered the ToolManager as the Gizmo's TransactionProvider,
// this should only be done if the Gizmo is embedded inside a Tool
if ( ensure ( HasActiveTool ( EToolSide : : Left ) ) )
{
TUniquePtr < FToolChangeWrapperChange > Wrapper = MakeUnique < FToolChangeWrapperChange > ( ) ;
Wrapper - > ToolManager = this ;
Wrapper - > ActiveTool = GetActiveTool ( EToolSide : : Left ) ;
Wrapper - > ToolChange = MoveTemp ( Change ) ;
TransactionsAPI - > AppendChange ( TargetObject , MoveTemp ( Wrapper ) , Description ) ;
}
2019-04-04 16:11:44 -04:00
}
2023-09-12 00:11:43 -04:00
bool UInteractiveToolManager : : RequestSelectionChange ( const FSelectedObjectsChangeList & SelectionChange )
2019-05-06 15:41:42 -04:00
{
return TransactionsAPI - > RequestSelectionChange ( SelectionChange ) ;
}
2019-09-10 14:40:38 -04:00
2022-11-29 12:35:38 -05:00
bool UInteractiveToolManager : : PostActiveToolShutdownRequest ( UInteractiveTool * Tool , EToolShutdownType ShutdownType ,
bool bShowUnexpectedShutdownMessage , const FText & UnexpectedShutdownMessage )
2022-06-28 14:01:02 -04:00
{
2022-11-29 12:35:38 -05:00
if ( bShowUnexpectedShutdownMessage )
{
if ( OnToolUnexpectedShutdownMessage . IsBound ( ) = = false )
{
if ( UnexpectedShutdownMessage . IsEmpty ( ) )
{
2022-11-30 11:23:13 -05:00
FString ToolName = ( Tool ! = nullptr ) ? Tool - > GetToolInfo ( ) . ToolDisplayName . ToString ( ) : FString ( TEXT ( " (Null Tool) " ) ) ;
2022-11-29 12:35:38 -05:00
if ( bInToolSetup )
{
2022-11-30 11:23:13 -05:00
UE_LOG ( LogTemp , Error , TEXT ( " [InteractiveToolManager] Tool %s Could not be Initialized " ) , * ToolName ) ;
2022-11-29 12:35:38 -05:00
}
else
{
2022-11-30 11:23:13 -05:00
UE_LOG ( LogTemp , Error , TEXT ( " [InteractiveToolManager] Tool %s was Shut Down Automatically, no message provided " ) , * ToolName ) ;
2022-11-29 12:35:38 -05:00
}
}
else
{
UE_LOG ( LogTemp , Error , TEXT ( " [InteractiveToolManager] %s " ) , * UnexpectedShutdownMessage . ToString ( ) ) ;
}
}
else
{
OnToolUnexpectedShutdownMessage . Broadcast ( this , Tool , UnexpectedShutdownMessage , bInToolSetup ) ;
}
}
// if Tool calls this function from it's Setup() function, then we need to do some special-case handling because
// the code below can't be run yet
if ( bInToolSetup )
{
bToolRequestedTerminationDuringSetup = true ;
return true ;
}
2022-06-28 14:01:02 -04:00
bool bIsActiveTool = ( Tool ! = nullptr ) & & ( ActiveLeftTool = = Tool | | ActiveRightTool = = Tool ) ;
if ( ! bIsActiveTool )
{
return false ;
}
bool bHandled = false ;
if ( OnToolShutdownRequest . IsBound ( ) )
{
bHandled = OnToolShutdownRequest . Execute ( this , Tool , ShutdownType ) ;
}
if ( ! bHandled )
{
EToolSide WhichSide = ( ActiveLeftTool = = Tool ) ? EToolSide : : Left : EToolSide : : Right ;
DeactivateTool ( WhichSide , ShutdownType ) ;
}
return true ;
}
2019-09-10 14:40:38 -04:00
void FBeginToolChange : : Apply ( UObject * Object )
{
// do nothing on apply, we do not want to re-enter the tool
}
void FBeginToolChange : : Revert ( UObject * Object )
{
// On revert, if a tool is active, we cancel it.
// Note that this should only happen once, because any further tool activations
// would be pushing their own FBeginToolChange
UInteractiveToolManager * ToolManager = CastChecked < UInteractiveToolManager > ( Object ) ;
if ( ToolManager - > HasAnyActiveTool ( ) )
{
2020-02-22 17:01:16 -05:00
ToolManager - > DeactivateToolInternal ( EToolSide : : Left , EToolShutdownType : : Cancel ) ;
2019-09-10 14:40:38 -04:00
}
}
bool FBeginToolChange : : HasExpired ( UObject * Object ) const
{
UInteractiveToolManager * ToolManager = CastChecked < UInteractiveToolManager > ( Object ) ;
2020-03-19 10:59:25 -04:00
return ( ToolManager = = nullptr ) | | ( ToolManager - > IsActive ( ) = = false ) | | ( ToolManager - > HasAnyActiveTool ( ) = = false ) ;
2019-09-10 14:40:38 -04:00
}
FString FBeginToolChange : : ToString ( ) const
{
return FString ( TEXT ( " Begin Tool " ) ) ;
}
2020-02-22 17:01:16 -05:00
void FActivateToolChange : : Apply ( UObject * Object )
{
UInteractiveToolManager * ToolManager = CastChecked < UInteractiveToolManager > ( Object ) ;
if ( ToolManager )
{
if ( bIsDeactivate )
{
ToolManager - > DeactivateToolInternal ( Side , ShutdownType ) ;
}
else
{
ToolManager - > SelectActiveToolType ( Side , ToolType ) ;
ToolManager - > ActivateToolInternal ( Side ) ;
}
}
}
void FActivateToolChange : : Revert ( UObject * Object )
{
UInteractiveToolManager * ToolManager = CastChecked < UInteractiveToolManager > ( Object ) ;
if ( ToolManager )
{
if ( bIsDeactivate )
{
ToolManager - > SelectActiveToolType ( Side , ToolType ) ;
ToolManager - > ActivateToolInternal ( Side ) ;
}
else
{
ToolManager - > DeactivateToolInternal ( Side , ShutdownType ) ;
}
}
}
bool FActivateToolChange : : HasExpired ( UObject * Object ) const
{
UInteractiveToolManager * ToolManager = CastChecked < UInteractiveToolManager > ( Object ) ;
2020-03-19 10:59:25 -04:00
return ( ToolManager = = nullptr ) | | ( ToolManager - > IsActive ( ) = = false ) ;
2020-02-22 17:01:16 -05:00
}
FString FActivateToolChange : : ToString ( ) const
{
return FString ( TEXT ( " Change Tool " ) ) ;
}
2019-09-10 14:40:38 -04:00
void FToolChangeWrapperChange : : Apply ( UObject * Object )
{
if ( ToolChange . IsValid ( ) )
{
ToolChange - > Apply ( Object ) ;
}
}
void FToolChangeWrapperChange : : Revert ( UObject * Object )
{
if ( ToolChange . IsValid ( ) )
{
ToolChange - > Revert ( Object ) ;
}
}
bool FToolChangeWrapperChange : : HasExpired ( UObject * Object ) const
{
if ( ToolChange . IsValid ( ) & & ToolManager . IsValid ( ) & & ActiveTool . IsValid ( ) )
{
2020-01-27 20:11:15 -05:00
if ( ToolChange - > HasExpired ( Object ) )
{
return true ;
}
2019-09-10 14:40:38 -04:00
if ( ToolManager - > GetActiveTool ( EToolSide : : Left ) = = ActiveTool . Get ( ) )
{
return false ;
}
}
return true ;
}
FString FToolChangeWrapperChange : : ToString ( ) const
{
if ( ToolChange . IsValid ( ) )
{
return ToolChange - > ToString ( ) ;
}
return FString ( ) ;
}
2020-08-31 16:54:59 -04:00
# undef LOCTEXT_NAMESPACE
2022-09-24 13:57:58 -04:00