Files

237 lines
6.2 KiB
C++
Raw Permalink Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "TranslationPickerWidget.h"
#include "Engine/GameEngine.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "Framework/Application/SlateApplication.h"
#include "Framework/Docking/TabManager.h"
#include "Internationalization/Internationalization.h"
#include "Internationalization/Text.h"
#include "Layout/Children.h"
#include "Math/MathFwd.h"
#include "Math/Vector2D.h"
#include "SlotBase.h"
#include "Styling/AppStyle.h"
#include "Styling/ISlateStyle.h"
#include "Styling/SlateTypes.h"
#include "TranslationPickerEditWindow.h"
#include "TranslationPickerFloatingWindow.h"
#include "Types/SlateEnums.h"
#include "UObject/NameTypes.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Input/SCheckBox.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/SToolTip.h"
#include "Widgets/SWindow.h"
#include "Widgets/Text/STextBlock.h"
#if WITH_EDITOR
#include "Editor.h"
#endif // WITH_EDITOR
class SWidget;
#define LOCTEXT_NAMESPACE "TranslationPicker"
void STranslationWidgetPicker::Construct(const FArguments& InArgs)
{
// Mimicking a toolbar button look
// Icon for the picker widget button
TSharedRef< SWidget > IconWidget =
SNew(SImage)
.Image(FAppStyle::GetBrush("TranslationEditor.TranslationPicker"));
// Style settings
FName StyleSet = FAppStyle::GetAppStyleSetName();
FName StyleName = "Toolbar";
Copying //UE4/Dev-Framework to //UE4/Dev-Main (Source: //UE4/Dev-Framework @ 2972815) #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2821607 on 2016/01/08 by Mieszko.Zielinski Added a way to limit amount of information logged by vlog by discarding logs from classes from outside of class whitelist #UE4 This feature was followed by refactoring of functions taking FVisualLogEntry pointers to use references instead. Change 2828384 on 2016/01/14 by Mieszko.Zielinski Back out of visual log refactor done as part of CL#2821607 #UE4 Change 2965743 on 2016/05/04 by Tom.Looman Added check to PostActorConstruction to avoid BeginPlay call on pendingkill actor. UE-27528 #rb MarcA Change 2965744 on 2016/05/04 by Marc.Audy VS2015 Shadow Variable fixes Change 2965813 on 2016/05/04 by Tom.Looman Moved UninitializeComponents outside (bActorInitialized) to always uninit components when actors gets destroyed early. UE-27529 #rb MarcA Change 2966564 on 2016/05/04 by Marc.Audy VS2015 shadow variable fixes Change 2967244 on 2016/05/05 by Jon.Nabozny Remove UPROPERTY from members that don't require serialization and aren't user editable. #JIRA UE-30155 Change 2967377 on 2016/05/05 by Lukasz.Furman fixed processing of AIMessages when new message appears during notify loop #ue4 Change 2967437 on 2016/05/05 by Marc.Audy Add a static One to TBigInt Remove numerous local statics and TEncryptionInt specific version in KeyGenerator.cpp Part of fixing shadow variables for VS2015 Change 2967465 on 2016/05/05 by Marc.Audy Fix VS2015 shadow variables fixes Change 2967552 on 2016/05/05 by Marc.Audy Fix compile error in DocumentationCode Change 2967556 on 2016/05/05 by Marc.Audy Enable shadow variable warnings in 2015 Change 2967836 on 2016/05/05 by Marc.Audy Another DocumentationCode project fix Change 2967941 on 2016/05/05 by Marc.Audy Make bShowHUD not config Expose HUD properties to blueprints Cleanup stale entries in BaseGame.ini Deprecate unnecessary colors in AHUD in favor of using FColor statics #jira UE-30045 Change 2969008 on 2016/05/06 by Marc.Audy VS2015 Shadow Variable fixes found by CIS Change 2969315 on 2016/05/06 by John.Abercrombie Duplicating CL 2969279 from //Fortnite/Main/ Behavior tree auxilary nodes, parallel tasks, active tasks, and aborting tasks shouldn't be ticked while the behavior tree is paused -------- Integrated using branch //Fortnite/Main/_to_//UE4/Dev-Framework of change#2969279 by John.Abercrombie on 2016/05/06 14:21:40. Change 2969611 on 2016/05/06 by Marc.Audy Default bShowHUD to true Change 2971041 on 2016/05/09 by Marc.Audy Add Get/Set Actor/Component TickInterval functions and expose to blueprints Change 2971072 on 2016/05/09 by Marc.Audy Fix VS2015 shadow variables warnings Change 2971629 on 2016/05/09 by Marc.Audy PR#1981 (contributed by EverNewJoy) CheatManager is blueprintable (though very basic exposure at this time) and can be set from PlayerController DebugCameraController is now visible and can be subclassed and specified via CheatManager blueprint #jira UE-25901 Change 2971632 on 2016/05/09 by Marc.Audy Missed file from CL# 2971629 [CL 2972828 by Marc Audy in Main branch]
2016-05-10 16:00:39 -04:00
FText ToolTipText = LOCTEXT("TranslationPickerTooltip", "Open the Translation Picker");
// Create the content for our button
TSharedRef< SWidget > ButtonContent =
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.FillWidth(1)
.VAlign(VAlign_Center)
[
SNew(SVerticalBox)
// Icon image
+ SVerticalBox::Slot()
.AutoHeight()
.HAlign(HAlign_Center) // Center the icon horizontally, so that large labels don't stretch out the artwork
[
IconWidget
]
// Label text
+ SVerticalBox::Slot().AutoHeight()
.HAlign(HAlign_Center) // Center the label text horizontally
[
SNew(STextBlock)
.Text(LOCTEXT("TranslationPicker", "Translation Picker"))
.TextStyle(FAppStyle::Get(), FName("ToolBar.Label")) // Smaller font for tool tip labels
.ShadowOffset(FVector2D::UnitVector)
]
];
FName CheckboxStyle = ISlateStyle::Join(StyleName, ".SToolBarButtonBlock.CheckBox.Padding");
ChildSlot
[
// Create a check box
SNew(SCheckBox)
// Use the tool bar style for this check box
.Style(FAppStyle::Get(), "ToolBar.ToggleButton")
// User will have set the focusable attribute for the block, honor it
.IsFocusable(false)
// Pass along the block's tool-tip string
Copying //UE4/Dev-Framework to //UE4/Dev-Main (Source: //UE4/Dev-Framework @ 2972815) #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2821607 on 2016/01/08 by Mieszko.Zielinski Added a way to limit amount of information logged by vlog by discarding logs from classes from outside of class whitelist #UE4 This feature was followed by refactoring of functions taking FVisualLogEntry pointers to use references instead. Change 2828384 on 2016/01/14 by Mieszko.Zielinski Back out of visual log refactor done as part of CL#2821607 #UE4 Change 2965743 on 2016/05/04 by Tom.Looman Added check to PostActorConstruction to avoid BeginPlay call on pendingkill actor. UE-27528 #rb MarcA Change 2965744 on 2016/05/04 by Marc.Audy VS2015 Shadow Variable fixes Change 2965813 on 2016/05/04 by Tom.Looman Moved UninitializeComponents outside (bActorInitialized) to always uninit components when actors gets destroyed early. UE-27529 #rb MarcA Change 2966564 on 2016/05/04 by Marc.Audy VS2015 shadow variable fixes Change 2967244 on 2016/05/05 by Jon.Nabozny Remove UPROPERTY from members that don't require serialization and aren't user editable. #JIRA UE-30155 Change 2967377 on 2016/05/05 by Lukasz.Furman fixed processing of AIMessages when new message appears during notify loop #ue4 Change 2967437 on 2016/05/05 by Marc.Audy Add a static One to TBigInt Remove numerous local statics and TEncryptionInt specific version in KeyGenerator.cpp Part of fixing shadow variables for VS2015 Change 2967465 on 2016/05/05 by Marc.Audy Fix VS2015 shadow variables fixes Change 2967552 on 2016/05/05 by Marc.Audy Fix compile error in DocumentationCode Change 2967556 on 2016/05/05 by Marc.Audy Enable shadow variable warnings in 2015 Change 2967836 on 2016/05/05 by Marc.Audy Another DocumentationCode project fix Change 2967941 on 2016/05/05 by Marc.Audy Make bShowHUD not config Expose HUD properties to blueprints Cleanup stale entries in BaseGame.ini Deprecate unnecessary colors in AHUD in favor of using FColor statics #jira UE-30045 Change 2969008 on 2016/05/06 by Marc.Audy VS2015 Shadow Variable fixes found by CIS Change 2969315 on 2016/05/06 by John.Abercrombie Duplicating CL 2969279 from //Fortnite/Main/ Behavior tree auxilary nodes, parallel tasks, active tasks, and aborting tasks shouldn't be ticked while the behavior tree is paused -------- Integrated using branch //Fortnite/Main/_to_//UE4/Dev-Framework of change#2969279 by John.Abercrombie on 2016/05/06 14:21:40. Change 2969611 on 2016/05/06 by Marc.Audy Default bShowHUD to true Change 2971041 on 2016/05/09 by Marc.Audy Add Get/Set Actor/Component TickInterval functions and expose to blueprints Change 2971072 on 2016/05/09 by Marc.Audy Fix VS2015 shadow variables warnings Change 2971629 on 2016/05/09 by Marc.Audy PR#1981 (contributed by EverNewJoy) CheatManager is blueprintable (though very basic exposure at this time) and can be set from PlayerController DebugCameraController is now visible and can be subclassed and specified via CheatManager blueprint #jira UE-25901 Change 2971632 on 2016/05/09 by Marc.Audy Missed file from CL# 2971629 [CL 2972828 by Marc Audy in Main branch]
2016-05-10 16:00:39 -04:00
.ToolTip(SNew(SToolTip).Text(ToolTipText))
[
ButtonContent
]
// Bind the button's "on checked" event to our object's method for this
.OnCheckStateChanged(this, &STranslationWidgetPicker::OnCheckStateChanged)
// Bind the check box's "checked" state to our user interface action
.IsChecked(this, &STranslationWidgetPicker::IsChecked)
.Padding(FAppStyle::Get().GetMargin(CheckboxStyle))
];
}
ECheckBoxState STranslationWidgetPicker::IsChecked() const
{
return TranslationPickerManager::IsPickerWindowOpen() ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
}
void STranslationWidgetPicker::OnCheckStateChanged(const ECheckBoxState NewCheckedState)
{
if (TranslationPickerManager::IsPickerWindowOpen())
{
TranslationPickerManager::ClosePickerWindow();
}
else
{
TranslationPickerManager::OpenPickerWindow();
}
}
TSharedPtr<SWindow> TranslationPickerManager::PickerWindow;
TSharedPtr<STranslationPickerFloatingWindow> TranslationPickerManager::PickerWindowWidget;
TSharedPtr<STranslationPickerOverlay> TranslationPickerManager::MainWindowOverlay;
TArray<FTranslationPickerTextAndGeom> TranslationPickerManager::PickedTexts;
bool TranslationPickerManager::bDrawBoxes = true;
bool TranslationPickerManager::OpenPickerWindow()
{
if (PickerWindow.IsValid() || PickerWindowWidget.IsValid())
{
return false;
}
TSharedPtr<SWindow> RootWindow = FGlobalTabmanager::Get()->GetRootWindow();
// Not picking previously, launch a picker window
{
TSharedRef<SWindow> NewWindow = SWindow::MakeCursorDecorator();
NewWindow->SetSizingRule(ESizingRule::FixedSize);
// The Edit window and Floating window should be roughly the same size, so it isn't too distracting switching between them
NewWindow->Resize(FVector2f(STranslationPickerEditWindow::DefaultEditWindowWidth, STranslationPickerEditWindow::DefaultEditWindowHeight));
NewWindow->MoveWindowTo(FSlateApplication::Get().GetCursorPos());
PickerWindow = NewWindow;
NewWindow->SetContent(
SAssignNew(PickerWindowWidget, STranslationPickerFloatingWindow)
.ParentWindow(NewWindow));
if (RootWindow.IsValid())
{
FSlateApplication::Get().AddWindowAsNativeChild(NewWindow, RootWindow.ToSharedRef());
}
else
{
FSlateApplication::Get().AddWindow(NewWindow);
}
}
// Create overlay for drawing text boxes
if (!MainWindowOverlay.IsValid())
{
MainWindowOverlay = SNew(STranslationPickerOverlay);
#if WITH_EDITOR
if (GIsEditor && IsValid(GEditor))
{
RootWindow->AddOverlaySlot()
[
MainWindowOverlay.ToSharedRef()
];
}
else
#endif // WITH_EDITOR
if (UGameEngine* GameEngine = Cast<UGameEngine>(GEngine))
{
if (TSharedPtr<SWindow> GameViewportWindow = GameEngine->GameViewportWindow.Pin())
{
GameViewportWindow->AddOverlaySlot()
[
MainWindowOverlay.ToSharedRef()
];
}
}
}
return true;
}
void TranslationPickerManager::ClosePickerWindow()
{
if (FSlateApplication::IsInitialized())
{
FSlateApplication::Get().RequestDestroyWindow(PickerWindow.ToSharedRef());
}
ResetPickerWindow();
}
void TranslationPickerManager::ResetPickerWindow()
{
PickerWindow.Reset();
PickerWindowWidget.Reset();
}
void TranslationPickerManager::RemoveOverlay()
{
if (!MainWindowOverlay.IsValid())
{
return;
}
#if WITH_EDITOR
TSharedPtr<SWindow> RootWindow = FGlobalTabmanager::Get()->GetRootWindow();
RootWindow->RemoveOverlaySlot(MainWindowOverlay.ToSharedRef());
MainWindowOverlay.Reset();
#else
if (UGameEngine* GameEngine = Cast<UGameEngine>(GEngine))
{
if (TSharedPtr<SWindow> GameViewportWindow = GameEngine->GameViewportWindow.Pin())
{
GameViewportWindow->RemoveOverlaySlot(MainWindowOverlay.ToSharedRef());
MainWindowOverlay.Reset();
}
}
#endif // WITH_EDITOR
}
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#undef LOCTEXT_NAMESPACE