2019-12-26 15:33:43 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "InputSettingsDetails.h"
2022-08-30 23:03:03 -04:00
# include "Containers/UnrealString.h"
# include "CoreTypes.h"
# include "DetailCategoryBuilder.h"
2016-11-23 15:48:37 -05:00
# include "DetailLayoutBuilder.h"
2022-08-30 23:03:03 -04:00
# include "DetailWidgetRow.h"
# include "Fonts/SlateFontInfo.h"
# include "Framework/SlateDelegates.h"
# include "GameFramework/InputSettings.h"
# include "GameFramework/PlayerInput.h"
# include "HAL/PlatformCrt.h"
# include "IDetailChildrenBuilder.h"
2016-11-23 15:48:37 -05:00
# include "IDetailGroup.h"
# include "IDetailPropertyRow.h"
2014-10-17 15:39:39 -04:00
# include "IDocumentation.h"
2022-08-30 23:03:03 -04:00
# include "Internationalization/Internationalization.h"
# include "Internationalization/Text.h"
# include "Misc/AssertionMacros.h"
# include "Misc/Attribute.h"
# include "PropertyCustomizationHelpers.h"
# include "PropertyEditorModule.h"
# include "PropertyHandle.h"
# include "ScopedTransaction.h"
# include "SlotBase.h"
# include "Templates/Casts.h"
# include "Templates/Tuple.h"
# include "Types/SlateStructs.h"
# include "UObject/Class.h"
# include "UObject/UnrealType.h"
# include "Widgets/DeclarativeSyntaxSupport.h"
2022-10-26 12:57:32 -04:00
# include "Widgets/Images/SImage.h"
2022-08-30 23:03:03 -04:00
# include "Widgets/Input/SEditableTextBox.h"
# include "Widgets/Layout/SBox.h"
# include "Widgets/SBoxPanel.h"
# include "Widgets/Text/STextBlock.h"
class SWidget ;
class UObject ;
2014-03-14 14:13:41 -04:00
# define LOCTEXT_NAMESPACE "InputSettingsDetails"
////////////////////////////////
// FActionMappingsNodeBuilder //
////////////////////////////////
FActionMappingsNodeBuilder : : FActionMappingsNodeBuilder ( IDetailLayoutBuilder * InDetailLayoutBuilder , const TSharedPtr < IPropertyHandle > & InPropertyHandle )
: DetailLayoutBuilder ( InDetailLayoutBuilder )
, ActionMappingsPropertyHandle ( InPropertyHandle )
{
// Delegate for when the children in the array change
FSimpleDelegate RebuildChildrenDelegate = FSimpleDelegate : : CreateRaw ( this , & FActionMappingsNodeBuilder : : RebuildChildren ) ;
ActionMappingsPropertyHandle - > SetOnPropertyValueChanged ( RebuildChildrenDelegate ) ;
ActionMappingsPropertyHandle - > AsArray ( ) - > SetOnNumElementsChanged ( RebuildChildrenDelegate ) ;
}
void FActionMappingsNodeBuilder : : Tick ( float DeltaTime )
{
if ( GroupsRequireRebuild ( ) )
{
RebuildChildren ( ) ;
}
2014-10-17 06:12:03 -04:00
HandleDelayedGroupExpansion ( ) ;
2014-03-14 14:13:41 -04:00
}
void FActionMappingsNodeBuilder : : GenerateHeaderRowContent ( FDetailWidgetRow & NodeRow )
{
TSharedRef < SWidget > AddButton = PropertyCustomizationHelpers : : MakeAddButton ( FSimpleDelegate : : CreateSP ( this , & FActionMappingsNodeBuilder : : AddActionMappingButton_OnClick ) ,
LOCTEXT ( " AddActionMappingToolTip " , " Adds Action Mapping " ) ) ;
TSharedRef < SWidget > ClearButton = PropertyCustomizationHelpers : : MakeEmptyButton ( FSimpleDelegate : : CreateSP ( this , & FActionMappingsNodeBuilder : : ClearActionMappingButton_OnClick ) ,
LOCTEXT ( " ClearActionMappingToolTip " , " Removes all Action Mappings " ) ) ;
NodeRow
2019-09-03 10:33:32 -04:00
. FilterString ( ActionMappingsPropertyHandle - > GetPropertyDisplayName ( ) )
2014-03-14 14:13:41 -04:00
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
ActionMappingsPropertyHandle - > CreatePropertyNameWidget ( )
]
+ SHorizontalBox : : Slot ( )
. Padding ( 2.0f )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
. AutoWidth ( )
[
AddButton
]
+ SHorizontalBox : : Slot ( )
. Padding ( 2.0f )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
. AutoWidth ( )
[
ClearButton
]
] ;
}
void FActionMappingsNodeBuilder : : GenerateChildContent ( IDetailChildrenBuilder & ChildrenBuilder )
{
RebuildGroupedMappings ( ) ;
for ( int32 Index = 0 ; Index < GroupedMappings . Num ( ) ; + + Index )
{
2022-07-20 21:52:06 -04:00
InputSettingsDetails : : FMappingSet & MappingSet = GroupedMappings [ Index ] ;
2014-03-14 14:13:41 -04:00
FString GroupNameString ( TEXT ( " ActionMappings. " ) ) ;
MappingSet . SharedName . AppendString ( GroupNameString ) ;
FName GroupName ( * GroupNameString ) ;
2017-06-19 20:27:30 -04:00
IDetailGroup & ActionMappingGroup = ChildrenBuilder . AddGroup ( GroupName , FText : : FromName ( MappingSet . SharedName ) ) ;
2014-06-27 05:00:12 -04:00
MappingSet . DetailGroup = & ActionMappingGroup ;
2014-10-17 06:12:03 -04:00
TSharedRef < SWidget > AddButton = PropertyCustomizationHelpers : : MakeAddButton ( FSimpleDelegate : : CreateSP ( this , & FActionMappingsNodeBuilder : : AddActionMappingToGroupButton_OnClick , MappingSet ) ,
LOCTEXT ( " AddActionMappingToGroupToolTip " , " Adds Action Mapping to Group " ) ) ;
TSharedRef < SWidget > RemoveButton = PropertyCustomizationHelpers : : MakeDeleteButton ( FSimpleDelegate : : CreateSP ( this , & FActionMappingsNodeBuilder : : RemoveActionMappingGroupButton_OnClick , MappingSet ) ,
LOCTEXT ( " RemoveActionMappingGroupToolTip " , " Removes Action Mapping Group " ) ) ;
2014-03-14 14:13:41 -04:00
ActionMappingGroup . HeaderRow ( )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
SNew ( SBox )
2022-07-20 21:52:06 -04:00
. WidthOverride ( InputSettingsDetails : : InputConstants : : TextBoxWidth )
2014-03-14 14:13:41 -04:00
[
SNew ( SEditableTextBox )
. Padding ( 2.0f )
. Text ( FText : : FromName ( MappingSet . SharedName ) )
. OnTextCommitted ( FOnTextCommitted : : CreateSP ( this , & FActionMappingsNodeBuilder : : OnActionMappingNameCommitted , MappingSet ) )
. Font ( IDetailLayoutBuilder : : GetDetailFont ( ) )
]
]
+ SHorizontalBox : : Slot ( )
2022-07-20 21:52:06 -04:00
. Padding ( InputSettingsDetails : : InputConstants : : PropertyPadding )
2014-03-14 14:13:41 -04:00
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
. AutoWidth ( )
[
AddButton
]
+ SHorizontalBox : : Slot ( )
2022-07-20 21:52:06 -04:00
. Padding ( InputSettingsDetails : : InputConstants : : PropertyPadding )
2014-03-14 14:13:41 -04:00
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
. AutoWidth ( )
[
RemoveButton
]
] ;
for ( int32 MappingIndex = 0 ; MappingIndex < MappingSet . Mappings . Num ( ) ; + + MappingIndex )
{
ActionMappingGroup . AddPropertyRow ( MappingSet . Mappings [ MappingIndex ] ) . ShowPropertyButtons ( false ) ;
}
}
}
void FActionMappingsNodeBuilder : : AddActionMappingButton_OnClick ( )
{
2014-05-16 04:31:18 -04:00
static const FName BaseActionMappingName ( * LOCTEXT ( " NewActionMappingName " , " NewActionMapping " ) . ToString ( ) ) ;
const FScopedTransaction Transaction ( LOCTEXT ( " AddActionMapping_Transaction " , " Add Action Mapping " ) ) ;
TArray < UObject * > OuterObjects ;
ActionMappingsPropertyHandle - > GetOuterObjects ( OuterObjects ) ;
if ( OuterObjects . Num ( ) = = 1 )
{
UInputSettings * InputSettings = CastChecked < UInputSettings > ( OuterObjects [ 0 ] ) ;
InputSettings - > Modify ( ) ;
ActionMappingsPropertyHandle - > NotifyPreChange ( ) ;
2019-07-10 13:47:03 -04:00
FName NewActionMappingName = InputSettings - > GetUniqueActionName ( BaseActionMappingName ) ;
2014-05-16 04:31:18 -04:00
2017-02-21 15:51:42 -05:00
DelayedGroupExpansionStates . Emplace ( NewActionMappingName , true ) ;
2014-05-16 04:31:18 -04:00
FInputActionKeyMapping NewMapping ( NewActionMappingName ) ;
2019-07-10 13:47:03 -04:00
InputSettings - > AddActionMapping ( NewMapping ) ;
2014-05-16 04:31:18 -04:00
2020-07-17 11:52:33 -04:00
ActionMappingsPropertyHandle - > NotifyPostChange ( EPropertyChangeType : : ArrayAdd ) ;
2014-05-16 04:31:18 -04:00
}
2014-03-14 14:13:41 -04:00
}
void FActionMappingsNodeBuilder : : ClearActionMappingButton_OnClick ( )
{
ActionMappingsPropertyHandle - > AsArray ( ) - > EmptyArray ( ) ;
}
2022-07-20 21:52:06 -04:00
void FActionMappingsNodeBuilder : : OnActionMappingNameCommitted ( const FText & InName , ETextCommit : : Type CommitInfo , const InputSettingsDetails : : FMappingSet MappingSet )
2014-03-14 14:13:41 -04:00
{
const FScopedTransaction Transaction ( LOCTEXT ( " RenameActionMapping_Transaction " , " Rename Action Mapping " ) ) ;
FName NewName = FName ( * InName . ToString ( ) ) ;
2014-06-27 05:00:12 -04:00
FName CurrentName = NewName ;
2014-03-14 14:13:41 -04:00
2014-06-27 05:00:12 -04:00
if ( MappingSet . Mappings . Num ( ) > 0 )
2014-03-14 14:13:41 -04:00
{
2014-06-27 05:00:12 -04:00
MappingSet . Mappings [ 0 ] - > GetChildHandle ( GET_MEMBER_NAME_CHECKED ( FInputActionKeyMapping , ActionName ) ) - > GetValue ( CurrentName ) ;
}
if ( NewName ! = CurrentName )
{
for ( int32 Index = 0 ; Index < MappingSet . Mappings . Num ( ) ; + + Index )
{
MappingSet . Mappings [ Index ] - > GetChildHandle ( GET_MEMBER_NAME_CHECKED ( FInputActionKeyMapping , ActionName ) ) - > SetValue ( NewName ) ;
}
if ( MappingSet . DetailGroup )
{
2017-02-21 15:51:42 -05:00
DelayedGroupExpansionStates . Emplace ( NewName , MappingSet . DetailGroup - > GetExpansionState ( ) ) ;
2014-06-27 05:00:12 -04:00
// Don't want to save expansion state of old name
MappingSet . DetailGroup - > ToggleExpansion ( false ) ;
}
2014-03-14 14:13:41 -04:00
}
}
2022-07-20 21:52:06 -04:00
void FActionMappingsNodeBuilder : : AddActionMappingToGroupButton_OnClick ( const InputSettingsDetails : : FMappingSet MappingSet )
2014-03-14 14:13:41 -04:00
{
const FScopedTransaction Transaction ( LOCTEXT ( " AddActionMappingToGroup_Transaction " , " Add Action Mapping To Group " ) ) ;
TArray < UObject * > OuterObjects ;
ActionMappingsPropertyHandle - > GetOuterObjects ( OuterObjects ) ;
if ( OuterObjects . Num ( ) = = 1 )
{
UInputSettings * InputSettings = CastChecked < UInputSettings > ( OuterObjects [ 0 ] ) ;
InputSettings - > Modify ( ) ;
ActionMappingsPropertyHandle - > NotifyPreChange ( ) ;
2017-02-21 15:51:42 -05:00
DelayedGroupExpansionStates . Emplace ( MappingSet . SharedName , true ) ;
2014-03-14 14:13:41 -04:00
FInputActionKeyMapping NewMapping ( MappingSet . SharedName ) ;
2019-07-10 13:47:03 -04:00
InputSettings - > AddActionMapping ( NewMapping ) ;
2014-03-14 14:13:41 -04:00
2020-07-17 11:52:33 -04:00
ActionMappingsPropertyHandle - > NotifyPostChange ( EPropertyChangeType : : ArrayAdd ) ;
2014-03-14 14:13:41 -04:00
}
}
2022-07-20 21:52:06 -04:00
void FActionMappingsNodeBuilder : : RemoveActionMappingGroupButton_OnClick ( const InputSettingsDetails : : FMappingSet MappingSet )
2014-03-14 14:13:41 -04:00
{
const FScopedTransaction Transaction ( LOCTEXT ( " RemoveActionMappingGroup_Transaction " , " Remove Action Mapping Group " ) ) ;
TSharedPtr < IPropertyHandleArray > ActionMappingsArrayHandle = ActionMappingsPropertyHandle - > AsArray ( ) ;
TArray < int32 > SortedIndices ;
for ( int32 Index = 0 ; Index < MappingSet . Mappings . Num ( ) ; + + Index )
{
SortedIndices . AddUnique ( MappingSet . Mappings [ Index ] - > GetIndexInArray ( ) ) ;
}
SortedIndices . Sort ( ) ;
for ( int32 Index = SortedIndices . Num ( ) - 1 ; Index > = 0 ; - - Index )
{
ActionMappingsArrayHandle - > DeleteItem ( SortedIndices [ Index ] ) ;
}
}
bool FActionMappingsNodeBuilder : : GroupsRequireRebuild ( ) const
{
for ( int32 GroupIndex = 0 ; GroupIndex < GroupedMappings . Num ( ) ; + + GroupIndex )
{
2022-07-20 21:52:06 -04:00
const InputSettingsDetails : : FMappingSet & MappingSet = GroupedMappings [ GroupIndex ] ;
2014-03-14 14:13:41 -04:00
for ( int32 MappingIndex = 0 ; MappingIndex < MappingSet . Mappings . Num ( ) ; + + MappingIndex )
{
FName ActionName ;
MappingSet . Mappings [ MappingIndex ] - > GetChildHandle ( GET_MEMBER_NAME_CHECKED ( FInputActionKeyMapping , ActionName ) ) - > GetValue ( ActionName ) ;
if ( MappingSet . SharedName ! = ActionName )
{
return true ;
}
}
}
return false ;
}
void FActionMappingsNodeBuilder : : RebuildGroupedMappings ( )
{
GroupedMappings . Empty ( ) ;
TSharedPtr < IPropertyHandleArray > ActionMappingsArrayHandle = ActionMappingsPropertyHandle - > AsArray ( ) ;
uint32 NumMappings ;
ActionMappingsArrayHandle - > GetNumElements ( NumMappings ) ;
for ( uint32 Index = 0 ; Index < NumMappings ; + + Index )
{
TSharedRef < IPropertyHandle > ActionMapping = ActionMappingsArrayHandle - > GetElement ( Index ) ;
FName ActionName ;
2014-04-02 18:09:23 -04:00
FPropertyAccess : : Result Result = ActionMapping - > GetChildHandle ( GET_MEMBER_NAME_CHECKED ( FInputActionKeyMapping , ActionName ) ) - > GetValue ( ActionName ) ;
if ( Result = = FPropertyAccess : : Success )
2014-03-14 14:13:41 -04:00
{
2014-04-02 18:09:23 -04:00
int32 FoundIndex = INDEX_NONE ;
for ( int32 GroupIndex = 0 ; GroupIndex < GroupedMappings . Num ( ) ; + + GroupIndex )
2014-03-14 14:13:41 -04:00
{
2014-04-02 18:09:23 -04:00
if ( GroupedMappings [ GroupIndex ] . SharedName = = ActionName )
{
FoundIndex = GroupIndex ;
break ;
}
2014-03-14 14:13:41 -04:00
}
2014-04-02 18:09:23 -04:00
if ( FoundIndex = = INDEX_NONE )
{
FoundIndex = GroupedMappings . Num ( ) ;
GroupedMappings . AddZeroed ( ) ;
GroupedMappings [ FoundIndex ] . SharedName = ActionName ;
}
GroupedMappings [ FoundIndex ] . Mappings . Add ( ActionMapping ) ;
2014-03-14 14:13:41 -04:00
}
}
}
2014-10-17 06:12:03 -04:00
void FActionMappingsNodeBuilder : : HandleDelayedGroupExpansion ( )
2014-06-27 05:00:12 -04:00
{
2014-10-17 06:12:03 -04:00
if ( DelayedGroupExpansionStates . Num ( ) > 0 )
2014-06-27 05:00:12 -04:00
{
2014-10-17 06:12:03 -04:00
for ( auto GroupState : DelayedGroupExpansionStates )
2014-06-27 05:00:12 -04:00
{
2014-10-17 06:12:03 -04:00
for ( auto & MappingSet : GroupedMappings )
2014-06-27 05:00:12 -04:00
{
2014-10-17 06:12:03 -04:00
if ( MappingSet . SharedName = = GroupState . Key )
{
MappingSet . DetailGroup - > ToggleExpansion ( GroupState . Value ) ;
break ;
}
2014-06-27 05:00:12 -04:00
}
}
2014-10-17 06:12:03 -04:00
DelayedGroupExpansionStates . Empty ( ) ;
2014-06-27 05:00:12 -04:00
}
}
2014-03-14 14:13:41 -04:00
//////////////////////////////
// FAxisMappingsNodeBuilder //
//////////////////////////////
FAxisMappingsNodeBuilder : : FAxisMappingsNodeBuilder ( IDetailLayoutBuilder * InDetailLayoutBuilder , const TSharedPtr < IPropertyHandle > & InPropertyHandle )
: DetailLayoutBuilder ( InDetailLayoutBuilder )
, AxisMappingsPropertyHandle ( InPropertyHandle )
{
// Delegate for when the children in the array change
FSimpleDelegate RebuildChildrenDelegate = FSimpleDelegate : : CreateRaw ( this , & FAxisMappingsNodeBuilder : : RebuildChildren ) ;
AxisMappingsPropertyHandle - > SetOnPropertyValueChanged ( RebuildChildrenDelegate ) ;
AxisMappingsPropertyHandle - > AsArray ( ) - > SetOnNumElementsChanged ( RebuildChildrenDelegate ) ;
}
void FAxisMappingsNodeBuilder : : Tick ( float DeltaTime )
{
if ( GroupsRequireRebuild ( ) )
{
RebuildChildren ( ) ;
}
2014-10-17 06:12:03 -04:00
HandleDelayedGroupExpansion ( ) ;
2014-03-14 14:13:41 -04:00
}
void FAxisMappingsNodeBuilder : : GenerateHeaderRowContent ( FDetailWidgetRow & NodeRow )
{
TSharedRef < SWidget > AddButton = PropertyCustomizationHelpers : : MakeAddButton ( FSimpleDelegate : : CreateSP ( this , & FAxisMappingsNodeBuilder : : AddAxisMappingButton_OnClick ) ,
LOCTEXT ( " AddAxisMappingToolTip " , " Adds Axis Mapping " ) ) ;
TSharedRef < SWidget > ClearButton = PropertyCustomizationHelpers : : MakeEmptyButton ( FSimpleDelegate : : CreateSP ( this , & FAxisMappingsNodeBuilder : : ClearAxisMappingButton_OnClick ) ,
LOCTEXT ( " ClearAxisMappingToolTip " , " Removes all Axis Mappings " ) ) ;
NodeRow
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
AxisMappingsPropertyHandle - > CreatePropertyNameWidget ( )
]
+ SHorizontalBox : : Slot ( )
. Padding ( 2.0f )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
. AutoWidth ( )
[
AddButton
]
+ SHorizontalBox : : Slot ( )
. Padding ( 2.0f )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
. AutoWidth ( )
[
ClearButton
]
] ;
}
void FAxisMappingsNodeBuilder : : GenerateChildContent ( IDetailChildrenBuilder & ChildrenBuilder )
{
RebuildGroupedMappings ( ) ;
for ( int32 Index = 0 ; Index < GroupedMappings . Num ( ) ; + + Index )
{
2022-07-20 21:52:06 -04:00
InputSettingsDetails : : FMappingSet & MappingSet = GroupedMappings [ Index ] ;
2014-03-14 14:13:41 -04:00
FString GroupNameString ( TEXT ( " AxisMappings. " ) ) ;
MappingSet . SharedName . AppendString ( GroupNameString ) ;
FName GroupName ( * GroupNameString ) ;
2017-06-19 20:27:30 -04:00
IDetailGroup & AxisMappingGroup = ChildrenBuilder . AddGroup ( GroupName , FText : : FromName ( MappingSet . SharedName ) ) ;
2014-06-27 05:00:12 -04:00
MappingSet . DetailGroup = & AxisMappingGroup ;
2014-10-17 06:12:03 -04:00
TSharedRef < SWidget > AddButton = PropertyCustomizationHelpers : : MakeAddButton ( FSimpleDelegate : : CreateSP ( this , & FAxisMappingsNodeBuilder : : AddAxisMappingToGroupButton_OnClick , MappingSet ) ,
LOCTEXT ( " AddAxisMappingToGroupToolTip " , " Adds Axis Mapping to Group " ) ) ;
TSharedRef < SWidget > RemoveButton = PropertyCustomizationHelpers : : MakeDeleteButton ( FSimpleDelegate : : CreateSP ( this , & FAxisMappingsNodeBuilder : : RemoveAxisMappingGroupButton_OnClick , MappingSet ) ,
LOCTEXT ( " RemoveAxisMappingGroupToolTip " , " Removes Axis Mapping Group " ) ) ;
2014-03-14 14:13:41 -04:00
AxisMappingGroup . HeaderRow ( )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
SNew ( SBox )
2022-07-20 21:52:06 -04:00
. WidthOverride ( InputSettingsDetails : : InputConstants : : TextBoxWidth )
2014-03-14 14:13:41 -04:00
[
SNew ( SEditableTextBox )
. Padding ( 2.0f )
. Text ( FText : : FromName ( MappingSet . SharedName ) )
. OnTextCommitted ( FOnTextCommitted : : CreateSP ( this , & FAxisMappingsNodeBuilder : : OnAxisMappingNameCommitted , MappingSet ) )
. Font ( IDetailLayoutBuilder : : GetDetailFont ( ) )
]
]
+ SHorizontalBox : : Slot ( )
2022-07-20 21:52:06 -04:00
. Padding ( InputSettingsDetails : : InputConstants : : PropertyPadding )
2014-03-14 14:13:41 -04:00
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
. AutoWidth ( )
[
AddButton
]
+ SHorizontalBox : : Slot ( )
2022-07-20 21:52:06 -04:00
. Padding ( InputSettingsDetails : : InputConstants : : PropertyPadding )
2014-03-14 14:13:41 -04:00
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
. AutoWidth ( )
[
RemoveButton
]
] ;
for ( int32 MappingIndex = 0 ; MappingIndex < MappingSet . Mappings . Num ( ) ; + + MappingIndex )
{
AxisMappingGroup . AddPropertyRow ( MappingSet . Mappings [ MappingIndex ] ) . ShowPropertyButtons ( false ) ;
}
}
}
void FAxisMappingsNodeBuilder : : AddAxisMappingButton_OnClick ( )
{
2014-05-16 04:31:18 -04:00
static const FName BaseAxisMappingName ( * LOCTEXT ( " NewAxisMappingName " , " NewAxisMapping " ) . ToString ( ) ) ;
static int32 NewMappingCount = 0 ;
const FScopedTransaction Transaction ( LOCTEXT ( " AddAxisMapping_Transaction " , " Add Axis Mapping " ) ) ;
TArray < UObject * > OuterObjects ;
AxisMappingsPropertyHandle - > GetOuterObjects ( OuterObjects ) ;
if ( OuterObjects . Num ( ) = = 1 )
{
UInputSettings * InputSettings = CastChecked < UInputSettings > ( OuterObjects [ 0 ] ) ;
InputSettings - > Modify ( ) ;
AxisMappingsPropertyHandle - > NotifyPreChange ( ) ;
2019-07-10 13:47:03 -04:00
FName NewAxisMappingName = InputSettings - > GetUniqueAxisName ( BaseAxisMappingName ) ;
2014-05-16 04:31:18 -04:00
2017-02-21 15:51:42 -05:00
DelayedGroupExpansionStates . Emplace ( NewAxisMappingName , true ) ;
2014-05-16 04:31:18 -04:00
FInputAxisKeyMapping NewMapping ( NewAxisMappingName ) ;
2019-07-10 13:47:03 -04:00
InputSettings - > AddAxisMapping ( NewMapping ) ;
2014-05-16 04:31:18 -04:00
2020-07-17 11:52:33 -04:00
AxisMappingsPropertyHandle - > NotifyPostChange ( EPropertyChangeType : : ArrayAdd ) ;
2014-05-16 04:31:18 -04:00
}
2014-03-14 14:13:41 -04:00
}
void FAxisMappingsNodeBuilder : : ClearAxisMappingButton_OnClick ( )
{
AxisMappingsPropertyHandle - > AsArray ( ) - > EmptyArray ( ) ;
}
2022-07-20 21:52:06 -04:00
void FAxisMappingsNodeBuilder : : OnAxisMappingNameCommitted ( const FText & InName , ETextCommit : : Type CommitInfo , const InputSettingsDetails : : FMappingSet MappingSet )
2014-03-14 14:13:41 -04:00
{
const FScopedTransaction Transaction ( LOCTEXT ( " RenameAxisMapping_Transaction " , " Rename Axis Mapping " ) ) ;
FName NewName = FName ( * InName . ToString ( ) ) ;
2014-06-27 05:00:12 -04:00
FName CurrentName = NewName ;
2014-03-14 14:13:41 -04:00
2014-06-27 05:00:12 -04:00
if ( MappingSet . Mappings . Num ( ) > 0 )
2014-03-14 14:13:41 -04:00
{
2014-06-27 05:00:12 -04:00
MappingSet . Mappings [ 0 ] - > GetChildHandle ( GET_MEMBER_NAME_CHECKED ( FInputAxisKeyMapping , AxisName ) ) - > GetValue ( CurrentName ) ;
}
if ( NewName ! = CurrentName )
{
for ( int32 Index = 0 ; Index < MappingSet . Mappings . Num ( ) ; + + Index )
{
MappingSet . Mappings [ Index ] - > GetChildHandle ( GET_MEMBER_NAME_CHECKED ( FInputAxisKeyMapping , AxisName ) ) - > SetValue ( NewName ) ;
}
if ( MappingSet . DetailGroup )
{
2017-02-21 15:51:42 -05:00
DelayedGroupExpansionStates . Emplace ( NewName , MappingSet . DetailGroup - > GetExpansionState ( ) ) ;
2014-06-27 05:00:12 -04:00
// Don't want to save expansion state of old name
MappingSet . DetailGroup - > ToggleExpansion ( false ) ;
}
2014-03-14 14:13:41 -04:00
}
}
2022-07-20 21:52:06 -04:00
void FAxisMappingsNodeBuilder : : AddAxisMappingToGroupButton_OnClick ( const InputSettingsDetails : : FMappingSet MappingSet )
2014-03-14 14:13:41 -04:00
{
const FScopedTransaction Transaction ( LOCTEXT ( " AddAxisMappingToGroup_Transaction " , " Add Axis Mapping To Group " ) ) ;
TArray < UObject * > OuterObjects ;
AxisMappingsPropertyHandle - > GetOuterObjects ( OuterObjects ) ;
if ( OuterObjects . Num ( ) = = 1 )
{
UInputSettings * InputSettings = CastChecked < UInputSettings > ( OuterObjects [ 0 ] ) ;
InputSettings - > Modify ( ) ;
AxisMappingsPropertyHandle - > NotifyPreChange ( ) ;
2017-02-21 15:51:42 -05:00
DelayedGroupExpansionStates . Emplace ( MappingSet . SharedName , true ) ;
2014-03-14 14:13:41 -04:00
FInputAxisKeyMapping NewMapping ( MappingSet . SharedName ) ;
2019-07-10 13:47:03 -04:00
InputSettings - > AddAxisMapping ( NewMapping ) ;
2014-03-14 14:13:41 -04:00
2020-07-17 11:52:33 -04:00
AxisMappingsPropertyHandle - > NotifyPostChange ( EPropertyChangeType : : ArrayAdd ) ;
2014-03-14 14:13:41 -04:00
}
}
2022-07-20 21:52:06 -04:00
void FAxisMappingsNodeBuilder : : RemoveAxisMappingGroupButton_OnClick ( const InputSettingsDetails : : FMappingSet MappingSet )
2014-03-14 14:13:41 -04:00
{
const FScopedTransaction Transaction ( LOCTEXT ( " RemoveAxisMappingGroup_Transaction " , " Remove Axis Mapping Group " ) ) ;
TSharedPtr < IPropertyHandleArray > AxisMappingsArrayHandle = AxisMappingsPropertyHandle - > AsArray ( ) ;
TArray < int32 > SortedIndices ;
for ( int32 Index = 0 ; Index < MappingSet . Mappings . Num ( ) ; + + Index )
{
SortedIndices . AddUnique ( MappingSet . Mappings [ Index ] - > GetIndexInArray ( ) ) ;
}
SortedIndices . Sort ( ) ;
for ( int32 Index = SortedIndices . Num ( ) - 1 ; Index > = 0 ; - - Index )
{
AxisMappingsArrayHandle - > DeleteItem ( SortedIndices [ Index ] ) ;
}
}
bool FAxisMappingsNodeBuilder : : GroupsRequireRebuild ( ) const
{
for ( int32 GroupIndex = 0 ; GroupIndex < GroupedMappings . Num ( ) ; + + GroupIndex )
{
2022-07-20 21:52:06 -04:00
const InputSettingsDetails : : FMappingSet & MappingSet = GroupedMappings [ GroupIndex ] ;
2014-03-14 14:13:41 -04:00
for ( int32 MappingIndex = 0 ; MappingIndex < MappingSet . Mappings . Num ( ) ; + + MappingIndex )
{
FName AxisName ;
MappingSet . Mappings [ MappingIndex ] - > GetChildHandle ( GET_MEMBER_NAME_CHECKED ( FInputAxisKeyMapping , AxisName ) ) - > GetValue ( AxisName ) ;
if ( MappingSet . SharedName ! = AxisName )
{
return true ;
}
}
}
return false ;
}
void FAxisMappingsNodeBuilder : : RebuildGroupedMappings ( )
{
GroupedMappings . Empty ( ) ;
TSharedPtr < IPropertyHandleArray > AxisMappingsArrayHandle = AxisMappingsPropertyHandle - > AsArray ( ) ;
uint32 NumMappings ;
AxisMappingsArrayHandle - > GetNumElements ( NumMappings ) ;
for ( uint32 Index = 0 ; Index < NumMappings ; + + Index )
{
TSharedRef < IPropertyHandle > AxisMapping = AxisMappingsArrayHandle - > GetElement ( Index ) ;
FName AxisName ;
2014-04-02 18:09:23 -04:00
FPropertyAccess : : Result Result = AxisMapping - > GetChildHandle ( GET_MEMBER_NAME_CHECKED ( FInputAxisKeyMapping , AxisName ) ) - > GetValue ( AxisName ) ;
if ( Result = = FPropertyAccess : : Success )
2014-03-14 14:13:41 -04:00
{
2014-04-02 18:09:23 -04:00
int32 FoundIndex = INDEX_NONE ;
for ( int32 GroupIndex = 0 ; GroupIndex < GroupedMappings . Num ( ) ; + + GroupIndex )
2014-03-14 14:13:41 -04:00
{
2014-04-02 18:09:23 -04:00
if ( GroupedMappings [ GroupIndex ] . SharedName = = AxisName )
{
FoundIndex = GroupIndex ;
break ;
}
2014-03-14 14:13:41 -04:00
}
2014-04-02 18:09:23 -04:00
if ( FoundIndex = = INDEX_NONE )
{
FoundIndex = GroupedMappings . Num ( ) ;
GroupedMappings . AddZeroed ( ) ;
GroupedMappings [ FoundIndex ] . SharedName = AxisName ;
}
GroupedMappings [ FoundIndex ] . Mappings . Add ( AxisMapping ) ;
2014-03-14 14:13:41 -04:00
}
}
}
2014-10-17 06:12:03 -04:00
void FAxisMappingsNodeBuilder : : HandleDelayedGroupExpansion ( )
2014-06-27 05:00:12 -04:00
{
2014-10-17 06:12:03 -04:00
if ( DelayedGroupExpansionStates . Num ( ) > 0 )
2014-06-27 05:00:12 -04:00
{
2014-10-17 06:12:03 -04:00
for ( auto GroupState : DelayedGroupExpansionStates )
2014-06-27 05:00:12 -04:00
{
2014-10-17 06:12:03 -04:00
for ( auto & MappingSet : GroupedMappings )
2014-06-27 05:00:12 -04:00
{
2014-10-17 06:12:03 -04:00
if ( MappingSet . SharedName = = GroupState . Key )
{
MappingSet . DetailGroup - > ToggleExpansion ( GroupState . Value ) ;
break ;
}
2014-06-27 05:00:12 -04:00
}
}
2014-10-17 06:12:03 -04:00
DelayedGroupExpansionStates . Empty ( ) ;
2014-06-27 05:00:12 -04:00
}
}
2014-03-14 14:13:41 -04:00
/////////////////////////
// FInputSettingsDetails //
/////////////////////////
TSharedRef < IDetailCustomization > FInputSettingsDetails : : MakeInstance ( )
{
return MakeShareable ( new FInputSettingsDetails ) ;
}
void FInputSettingsDetails : : CustomizeDetails ( class IDetailLayoutBuilder & DetailBuilder )
{
static const FName BindingsCategory = TEXT ( " Bindings " ) ;
2019-07-10 13:47:03 -04:00
static const FName ActionMappings = UInputSettings : : GetActionMappingsPropertyName ( ) ;
static const FName AxisMappings = UInputSettings : : GetAxisMappingsPropertyName ( ) ;
2014-03-14 14:13:41 -04:00
IDetailCategoryBuilder & MappingsDetailCategoryBuilder = DetailBuilder . EditCategory ( BindingsCategory ) ;
2022-07-01 14:04:21 -04:00
// If the new Enhanced Input module is loaded, then add a warning telling people to use
// that instead of these legacy Action/Axis bindings
static const FName ForegroundColorStyle ( " Colors.Foreground " ) ;
static const FName WarningColorStyle ( " Colors.AccentYellow " ) ;
static const FSlateBrush * WarningBrush = FAppStyle : : Get ( ) . GetBrush ( " Icons.AlertCircle " ) ;
2014-12-01 11:19:41 -05:00
MappingsDetailCategoryBuilder . AddCustomRow ( LOCTEXT ( " Mappings_Title " , " Action Axis Mappings " ) )
2014-10-17 15:39:39 -04:00
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
2022-07-01 14:04:21 -04:00
. FillWidth ( 1.0f )
2014-10-17 15:39:39 -04:00
[
2022-07-01 14:04:21 -04:00
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. HAlign ( HAlign_Center )
. Padding ( 0.0f , 10.0f )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. Padding ( 10.0f , 10.0f )
[
SNew ( SImage )
. Image ( WarningBrush )
. Visibility ( this , & FInputSettingsDetails : : GetLegacyWarningVisibility )
. ColorAndOpacity ( FAppStyle : : Get ( ) . GetSlateColor ( ForegroundColorStyle ) )
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Bottom )
[
SNew ( STextBlock )
. Font ( IDetailLayoutBuilder : : GetDetailFont ( ) )
. AutoWrapText ( true )
. Visibility ( this , & FInputSettingsDetails : : GetLegacyWarningVisibility )
. Text ( LOCTEXT ( " Mappings_DeprecationWarning " , " Axis and Action mappings are now deprecated, please use Enhanced Input Actions and Input Mapping Contexts instead. " ) )
. ColorAndOpacity ( FAppStyle : : Get ( ) . GetSlateColor ( WarningColorStyle ) )
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. HAlign ( HAlign_Left )
[
SNew ( STextBlock )
. Font ( IDetailLayoutBuilder : : GetDetailFont ( ) )
. AutoWrapText ( true )
. Text ( LOCTEXT ( " Mappings_Description " , " Action and Axis Mappings provide a mechanism to conveniently map keys and axes to input behaviors by inserting a layer of indirection between the input behavior and the keys that invoke it. Action Mappings are for key presses and releases, while Axis Mappings allow for inputs that have a continuous range. " ) )
]
2014-10-17 15:39:39 -04:00
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
IDocumentation : : Get ( ) - > CreateAnchor ( FString ( " Gameplay/Input " ) )
]
] ;
2014-03-14 14:13:41 -04:00
// Custom Action Mappings
const TSharedPtr < IPropertyHandle > ActionMappingsPropertyHandle = DetailBuilder . GetProperty ( ActionMappings , UInputSettings : : StaticClass ( ) ) ;
ActionMappingsPropertyHandle - > MarkHiddenByCustomization ( ) ;
const TSharedRef < FActionMappingsNodeBuilder > ActionMappingsBuilder = MakeShareable ( new FActionMappingsNodeBuilder ( & DetailBuilder , ActionMappingsPropertyHandle ) ) ;
MappingsDetailCategoryBuilder . AddCustomBuilder ( ActionMappingsBuilder ) ;
// Custom Axis Mappings
const TSharedPtr < IPropertyHandle > AxisMappingsPropertyHandle = DetailBuilder . GetProperty ( AxisMappings , UInputSettings : : StaticClass ( ) ) ;
AxisMappingsPropertyHandle - > MarkHiddenByCustomization ( ) ;
const TSharedRef < FAxisMappingsNodeBuilder > AxisMappingsBuilder = MakeShareable ( new FAxisMappingsNodeBuilder ( & DetailBuilder , AxisMappingsPropertyHandle ) ) ;
MappingsDetailCategoryBuilder . AddCustomBuilder ( AxisMappingsBuilder ) ;
}
2022-07-01 14:04:21 -04:00
EVisibility FInputSettingsDetails : : GetLegacyWarningVisibility ( ) const
{
return FModuleManager : : Get ( ) . IsModuleLoaded ( " EnhancedInput " ) ? EVisibility : : Visible : EVisibility : : Hidden ;
}
2014-03-14 14:13:41 -04:00
# undef LOCTEXT_NAMESPACE