2021-11-29 14:47:15 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "LevelInstanceEditorModeToolkit.h"
2023-04-27 11:14:32 -04:00
# include "LevelInstanceEditorMode.h"
2022-08-24 22:45:13 -04:00
# include "Internationalization/Internationalization.h"
2023-04-27 11:14:32 -04:00
# include "Widgets/SWidget.h"
# include "Widgets/Text/STextBlock.h"
# include "Widgets/Images/SImage.h"
# include "Widgets/Input/SButton.h"
# include "Tools/UEdMode.h"
# include "Toolkits/IToolkitHost.h"
# include "Styling/SlateIconFinder.h"
# include "LevelInstance/LevelInstanceActor.h"
# include "LevelInstance/ILevelInstanceEditorModule.h"
# include "Engine/World.h"
2022-08-24 22:45:13 -04:00
class FAssetEditorModeUILayer ;
2021-11-29 14:47:15 -05:00
# define LOCTEXT_NAMESPACE "LevelInstanceEditorModeToolkit"
2024-04-19 15:13:28 -04:00
struct FLevelInstanceEditorModeToolkitHelper
{
static FText GetToolkitDisplayText ( ULevelInstanceSubsystem * LevelInstanceSubsystem )
{
if ( LevelInstanceSubsystem - > GetEditingLevelInstance ( ) )
{
return LOCTEXT ( " LevelInstanceEditToolkitDisplayText " , " Level Instance Edit " ) ;
}
else if ( LevelInstanceSubsystem - > GetEditingPropertyOverridesLevelInstance ( ) )
{
return LOCTEXT ( " LevelInstanceOverrideToolkitDisplayText " , " Level Instance Override " ) ;
}
return FText ( ) ;
}
static FText GetToolkitSaveCancelButtonTooltipText ( ULevelInstanceSubsystem * LevelInstanceSubsystem , bool bDiscard )
{
if ( LevelInstanceSubsystem - > GetEditingLevelInstance ( ) )
{
return bDiscard ? LOCTEXT ( " LevelInstanceCancelEditToolkitTooltip " , " Cancel edits and exit " ) : LOCTEXT ( " LevelInstanceSaveEditToolkitTooltip " , " Save edits and exit " ) ;
}
else if ( LevelInstanceSubsystem - > GetEditingPropertyOverridesLevelInstance ( ) )
{
return bDiscard ? LOCTEXT ( " LevelInstanceCancelOverrideToolkitTooltip " , " Cancel overrides and exit " ) : LOCTEXT ( " LevelInstanceSaveOverrideToolkitTooltip " , " Save overrides and exit " ) ;
}
return FText ( ) ;
}
static FReply OnSaveCancelButtonClicked ( ULevelInstanceSubsystem * LevelInstanceSubsystem , bool bDiscard )
{
if ( ILevelInstanceInterface * LevelInstance = LevelInstanceSubsystem - > GetEditingLevelInstance ( ) )
{
LevelInstance - > ExitEdit ( bDiscard ) ;
}
else if ( ILevelInstanceInterface * LevelInstanceOverride = LevelInstanceSubsystem - > GetEditingPropertyOverridesLevelInstance ( ) )
{
LevelInstanceOverride - > ExitEditPropertyOverrides ( bDiscard ) ;
}
return FReply : : Handled ( ) ;
}
static bool IsCancelButtonEnabled ( ULevelInstanceSubsystem * LevelInstanceSubsystem )
{
if ( ILevelInstanceInterface * LevelInstance = LevelInstanceSubsystem - > GetEditingLevelInstance ( ) )
{
return LevelInstance - > CanExitEdit ( true ) ;
}
else if ( ILevelInstanceInterface * LevelInstanceOverride = LevelInstanceSubsystem - > GetEditingPropertyOverridesLevelInstance ( ) )
{
return LevelInstanceOverride - > CanExitEditPropertyOverrides ( true ) ;
}
return false ;
}
} ;
2021-11-29 14:47:15 -05:00
FLevelInstanceEditorModeToolkit : : FLevelInstanceEditorModeToolkit ( )
{
}
2023-04-27 11:14:32 -04:00
FLevelInstanceEditorModeToolkit : : ~ FLevelInstanceEditorModeToolkit ( )
{
2023-04-28 15:57:07 -04:00
if ( IsHosted ( ) & & ViewportOverlayWidget . IsValid ( ) )
2023-04-27 11:14:32 -04:00
{
GetToolkitHost ( ) - > RemoveViewportOverlayWidget ( ViewportOverlayWidget . ToSharedRef ( ) ) ;
}
}
void FLevelInstanceEditorModeToolkit : : Init ( const TSharedPtr < IToolkitHost > & InitToolkitHost , TWeakObjectPtr < UEdMode > InOwningMode )
{
FModeToolkit : : Init ( InitToolkitHost , InOwningMode ) ;
2024-02-22 08:26:27 -05:00
ULevelInstanceSubsystem * LevelInstanceSubsystem = UWorld : : GetSubsystem < ULevelInstanceSubsystem > ( InitToolkitHost - > GetWorld ( ) ) ;
2023-04-27 11:14:32 -04:00
check ( LevelInstanceSubsystem ) ;
// ViewportOverlay
SAssignNew ( ViewportOverlayWidget , SHorizontalBox )
2024-02-22 08:26:27 -05:00
+ SHorizontalBox : : Slot ( )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Bottom )
. Padding ( FMargin ( 0.0f , 0.0f , 0.f , 15.f ) )
[
SNew ( SBorder )
. BorderImage ( FAppStyle : : Get ( ) . GetBrush ( " EditorViewport.OverlayBrush " ) )
. Padding ( 8.f )
2023-04-27 11:14:32 -04:00
[
2024-02-22 08:26:27 -05:00
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Center )
2024-04-19 15:13:28 -04:00
. Padding ( FMargin ( 4.f , 0.f , 0.f , 0.f ) )
2023-04-27 11:14:32 -04:00
[
2024-02-22 08:26:27 -05:00
SNew ( SImage )
. Image ( FSlateIconFinder : : FindIconBrushForClass ( ALevelInstance : : StaticClass ( ) ) )
2023-04-27 11:14:32 -04:00
]
2024-02-22 08:26:27 -05:00
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Center )
2024-04-19 15:13:28 -04:00
. Padding ( FMargin ( 8.f , 0.f , 0.f , 0.f ) )
2024-02-22 08:26:27 -05:00
[
SNew ( STextBlock )
2024-04-19 15:13:28 -04:00
. Text_Static ( & FLevelInstanceEditorModeToolkitHelper : : GetToolkitDisplayText , LevelInstanceSubsystem )
2024-02-22 08:26:27 -05:00
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
2024-04-19 15:13:28 -04:00
. Padding ( FMargin ( 8.0 , 0.f , 0.f , 0.f ) )
2024-02-22 08:26:27 -05:00
[
SNew ( SButton )
. ButtonStyle ( FAppStyle : : Get ( ) , " PrimaryButton " )
. TextStyle ( FAppStyle : : Get ( ) , " DialogButtonText " )
2024-04-19 15:13:28 -04:00
. Text ( LOCTEXT ( " SaveButtonText " , " Save " ) )
. ToolTipText_Static ( & FLevelInstanceEditorModeToolkitHelper : : GetToolkitSaveCancelButtonTooltipText , LevelInstanceSubsystem , false )
2024-02-22 08:26:27 -05:00
. HAlign ( HAlign_Center )
2024-04-19 15:13:28 -04:00
. OnClicked_Static ( & FLevelInstanceEditorModeToolkitHelper : : OnSaveCancelButtonClicked , LevelInstanceSubsystem , false )
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. Padding ( FMargin ( 4.0 , 0.f , 4.f , 0.f ) )
[
SNew ( SButton )
. TextStyle ( FAppStyle : : Get ( ) , " DialogButtonText " )
. Text ( LOCTEXT ( " CancelButtonText " , " Cancel " ) )
. ToolTipText_Static ( & FLevelInstanceEditorModeToolkitHelper : : GetToolkitSaveCancelButtonTooltipText , LevelInstanceSubsystem , true )
. HAlign ( HAlign_Center )
. OnClicked_Static ( & FLevelInstanceEditorModeToolkitHelper : : OnSaveCancelButtonClicked , LevelInstanceSubsystem , true )
. IsEnabled_Static ( & FLevelInstanceEditorModeToolkitHelper : : IsCancelButtonEnabled , LevelInstanceSubsystem )
2024-02-22 08:26:27 -05:00
]
]
] ;
2023-04-27 11:14:32 -04:00
GetToolkitHost ( ) - > AddViewportOverlayWidget ( ViewportOverlayWidget . ToSharedRef ( ) ) ;
}
2021-11-29 14:47:15 -05:00
FName FLevelInstanceEditorModeToolkit : : GetToolkitFName ( ) const
{
return FName ( " LevelInstanceEditorModeToolkit " ) ;
}
FText FLevelInstanceEditorModeToolkit : : GetBaseToolkitName ( ) const
{
return LOCTEXT ( " ToolkitDisplayName " , " Level Instance Editor Mode " ) ;
}
2023-04-27 11:14:32 -04:00
void FLevelInstanceEditorModeToolkit : : RequestModeUITabs ( )
2021-11-29 14:47:15 -05:00
{
2023-04-27 11:14:32 -04:00
// No Tabs
2021-11-29 14:47:15 -05:00
}
# undef LOCTEXT_NAMESPACE