2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "LyraBrightnessEditor.h"
2022-09-13 07:18:28 +00:00
2022-05-23 18:41:30 +00:00
# include "CommonButtonBase.h"
# include "CommonRichTextBlock.h"
2022-09-13 07:18:28 +00:00
# include "Components/SlateWrapperTypes.h"
# include "Components/WidgetSwitcher.h"
# include "Containers/Array.h"
2022-05-23 18:41:30 +00:00
# include "GameSetting.h"
# include "GameSettingValueScalar.h"
2022-09-13 07:18:28 +00:00
# include "GameplayTagContainer.h"
# include "Input/Events.h"
# include "InputCoreTypes.h"
# include "Internationalization/Internationalization.h"
# include "Internationalization/Text.h"
# include "Math/UnrealMathUtility.h"
# include "Misc/Optional.h"
# include "Settings/LyraSettingsLocal.h"
# include "Templates/Casts.h"
# include "UObject/WeakObjectPtr.h"
# include "Widgets/Layout/SSafeZone.h"
struct FGeometry ;
2022-05-23 18:41:30 +00:00
# define LOCTEXT_NAMESPACE "Lyra"
namespace BrightnessEditor
{
const float JoystickDeadZone = 0.2f ;
const float SafeZoneChangeSpeed = 0.1f ;
}
ULyraBrightnessEditor : : ULyraBrightnessEditor ( const FObjectInitializer & Initializer )
: Super ( Initializer )
{
2022-09-13 07:18:28 +00:00
SetVisibility ( ESlateVisibility : : Visible ) ;
2022-05-23 18:41:30 +00:00
bIsFocusable = true ;
}
void ULyraBrightnessEditor : : NativeOnInitialized ( )
{
Super : : NativeOnInitialized ( ) ;
Switcher_SafeZoneMessage - > SetActiveWidget ( RichText_Default ) ;
}
void ULyraBrightnessEditor : : NativeOnActivated ( )
{
Super : : NativeOnActivated ( ) ;
SSafeZone : : SetGlobalSafeZoneScale ( ULyraSettingsLocal : : Get ( ) - > GetSafeZone ( ) ) ;
Button_Done - > OnClicked ( ) . AddUObject ( this , & ThisClass : : HandleDoneClicked ) ;
Button_Back - > SetVisibility ( ( bCanCancel ) ? ESlateVisibility : : Visible : ESlateVisibility : : Collapsed ) ;
if ( bCanCancel )
{
Button_Back - > OnClicked ( ) . AddUObject ( this , & ThisClass : : HandleBackClicked ) ;
}
}
bool ULyraBrightnessEditor : : ExecuteActionForSetting_Implementation ( FGameplayTag ActionTag , UGameSetting * InSetting )
{
TArray < UGameSetting * > ChildSettings = InSetting ? InSetting - > GetChildSettings ( ) : TArray < UGameSetting * > ( ) ;
if ( ChildSettings . Num ( ) > 0 & & ChildSettings [ 0 ] )
{
ValueSetting = Cast < UGameSettingValueScalar > ( ChildSettings [ 0 ] ) ;
}
return true ;
}
FReply ULyraBrightnessEditor : : NativeOnAnalogValueChanged ( const FGeometry & InGeometry , const FAnalogInputEvent & InAnalogEvent )
{
if ( InAnalogEvent . GetKey ( ) = = EKeys : : Gamepad_LeftY & & FMath : : Abs ( InAnalogEvent . GetAnalogValue ( ) ) > = BrightnessEditor : : JoystickDeadZone )
{
const float SafeZoneMultiplier = FMath : : Clamp ( SSafeZone : : GetGlobalSafeZoneScale ( ) . Get ( 1.0f ) + InAnalogEvent . GetAnalogValue ( ) * BrightnessEditor : : SafeZoneChangeSpeed , 0.0f , 1.0f ) ;
SSafeZone : : SetGlobalSafeZoneScale ( SafeZoneMultiplier > = 0 ? SafeZoneMultiplier : 0 ) ;
return FReply : : Handled ( ) ;
}
return Super : : NativeOnAnalogValueChanged ( InGeometry , InAnalogEvent ) ;
}
FReply ULyraBrightnessEditor : : NativeOnMouseWheel ( const FGeometry & InGeometry , const FPointerEvent & InMouseEvent )
{
const float SafeZoneMultiplier = FMath : : Clamp ( SSafeZone : : GetGlobalSafeZoneScale ( ) . Get ( 1.0f ) + InMouseEvent . GetWheelDelta ( ) * BrightnessEditor : : SafeZoneChangeSpeed , 0.0f , 1.0f ) ;
SSafeZone : : SetGlobalSafeZoneScale ( SafeZoneMultiplier > = 0 ? SafeZoneMultiplier : 0 ) ;
return FReply : : Handled ( ) ;
}
void ULyraBrightnessEditor : : HandleInputModeChanged ( ECommonInputType InInputType )
{
const FText KeyName = InInputType = = ECommonInputType : : Gamepad ? LOCTEXT ( " SafeZone_KeyToPress_Gamepad " , " Left Stick " ) : LOCTEXT ( " SafeZone_KeyToPress_Mouse " , " Mouse Wheel " ) ;
RichText_Default - > SetText ( FText : : Format ( LOCTEXT ( " BrightnessAdjustInstructions " , " Use <text color= \" FFFFFFFF \" fontface= \" black \" >{0}</> to adjust the brightness " ) , KeyName ) ) ;
}
void ULyraBrightnessEditor : : HandleBackClicked ( )
{
DeactivateWidget ( ) ;
SSafeZone : : SetGlobalSafeZoneScale ( ULyraSettingsLocal : : Get ( ) - > GetSafeZone ( ) ) ;
}
void ULyraBrightnessEditor : : HandleDoneClicked ( )
{
if ( ValueSetting . IsValid ( ) )
{
ValueSetting . Get ( ) - > SetValue ( SSafeZone : : GetGlobalSafeZoneScale ( ) . Get ( 1.0f ) ) ;
}
else
{
ULyraSettingsLocal : : Get ( ) - > SetSafeZone ( SSafeZone : : GetGlobalSafeZoneScale ( ) . Get ( 1.0f ) ) ;
}
OnSafeZoneSet . Broadcast ( ) ;
DeactivateWidget ( ) ;
}
# undef LOCTEXT_NAMESPACE