FUICommandInfoDecl::FUICommandInfoDecl( const TSharedRef<FBindingContext>& InContext, const FName InCommandName, const FText& InLabel, const FText& InDesc ) : Context( InContext ) { Info = MakeShareable( new FUICommandInfo( InContext->GetContextName() ) ); Info->CommandName = InCommandName; Info->Label = InLabel; Info->Description = InDesc; }
void FUICommandInfo::MakeCommandInfo( const TSharedRef<class FBindingContext>& InContext, TSharedPtr< FUICommandInfo >& OutCommand, const FName InCommandName, const FText& InCommandLabel, const FText& InCommandDesc, const FSlateIcon& InIcon, const EUserInterfaceActionType::Type InUserInterfaceType, const FInputChord& InDefaultChord ) { ensureMsgf( !InCommandLabel.IsEmpty(), TEXT("Command labels cannot be empty") ); OutCommand = MakeShareable( new FUICommandInfo( InContext->GetContextName() ) ); OutCommand->CommandName = InCommandName; OutCommand->Label = InCommandLabel; OutCommand->Description = InCommandDesc; OutCommand->Icon = InIcon; OutCommand->UserInterfaceType = InUserInterfaceType; OutCommand->DefaultChord = InDefaultChord; FInputBindingManager::Get().CreateInputCommand( InContext, OutCommand.ToSharedRef() ); }
void FInputBindingManager::CreateInputCommand( const TSharedRef<FBindingContext>& InBindingContext, TSharedRef<FUICommandInfo> InCommandInfo ) { check( InCommandInfo->BindingContext == InBindingContext->GetContextName() ); // The command name should be valid check( InCommandInfo->CommandName != NAME_None ); // Should not have already created a gesture for this command check( !InCommandInfo->ActiveGesture->IsValidGesture() ); const FName ContextName = InBindingContext->GetContextName(); FContextEntry& ContextEntry = ContextMap.FindOrAdd( ContextName ); // Our parent context must exist. check( InBindingContext->GetContextParent() == NAME_None || ContextMap.Find( InBindingContext->GetContextParent() ) != NULL ); FCommandInfoMap& CommandInfoMap = ContextEntry.CommandInfoMap; if( !ContextEntry.BindingContext.IsValid() ) { ContextEntry.BindingContext = InBindingContext; } if( InBindingContext->GetContextParent() != NAME_None ) { check( InBindingContext->GetContextName() != InBindingContext->GetContextParent() ); // Set a mapping from the parent of the current context to the current context ParentToChildMap.AddUnique( InBindingContext->GetContextParent(), InBindingContext->GetContextName() ); } if( InCommandInfo->DefaultGesture.IsValidGesture() ) { CheckForDuplicateDefaultGestures( *InBindingContext, InCommandInfo ); } { TSharedPtr<FUICommandInfo> ExistingInfo = CommandInfoMap.FindRef( InCommandInfo->CommandName ); ensureMsgf( !ExistingInfo.IsValid(), TEXT("A command with name %s already exists in context %s"), *InCommandInfo->CommandName.ToString(), *InBindingContext->GetContextName().ToString() ); } // Add the command info to the list of known infos. It can only exist once. CommandInfoMap.Add( InCommandInfo->CommandName, InCommandInfo ); // See if there are user defined gestures for this command FInputGesture UserDefinedGesture; bool bFoundUserDefinedGesture = GetUserDefinedGesture( ContextName, InCommandInfo->CommandName, UserDefinedGesture ); if( !bFoundUserDefinedGesture && InCommandInfo->DefaultGesture.IsValidGesture() ) { // Find any existing command with the same gesture // This is for inconsistency between default and user defined gesture. We need to make sure that if default gestures are changed to a gesture that a user set to a different command, that the default gesture doesn't replace // the existing commands gesture. Note: Duplicate default gestures are found above in CheckForDuplicateDefaultGestures FName ExisingCommand = ContextEntry.GestureToCommandInfoMap.FindRef( InCommandInfo->DefaultGesture ); if( ExisingCommand == NAME_None ) { // No existing command has a user defined gesture and no user defined gesture is available for this command TSharedRef<FInputGesture> NewGesture = MakeShareable( new FInputGesture( InCommandInfo->DefaultGesture ) ); InCommandInfo->ActiveGesture = NewGesture; } } else if( bFoundUserDefinedGesture ) { // Find any existing command with the same gesture // This is for inconsistency between default and user defined gesture. We need to make sure that if default gestures are changed to a gesture that a user set to a different command, that the default gesture doesn't replace // the existing commands gesture. FName ExisingCommandName = ContextEntry.GestureToCommandInfoMap.FindRef( UserDefinedGesture ); if( ExisingCommandName != NAME_None ) { // Get the command with using the same gesture TSharedPtr<FUICommandInfo> ExistingInfo = CommandInfoMap.FindRef( ExisingCommandName ); if( *ExistingInfo->ActiveGesture != ExistingInfo->DefaultGesture ) { // two user defined gestures are the same within a context. If the keybinding editor was used this wont happen so this must have been directly a modified user setting file UE_LOG(LogSlate, Error, TEXT("Duplicate user defined gestures found: [%s,%s]. Gesture for %s being removed"), *InCommandInfo->GetLabel().ToString(), *ExistingInfo->GetLabel().ToString(), *ExistingInfo->GetLabel().ToString() ); } ContextEntry.GestureToCommandInfoMap.Remove( *ExistingInfo->ActiveGesture ); // Remove the existing gesture. ExistingInfo->ActiveGesture = MakeShareable( new FInputGesture() ); } TSharedRef<FInputGesture> NewGesture = MakeShareable( new FInputGesture( UserDefinedGesture ) ); // Set the active gesture on the command info InCommandInfo->ActiveGesture = NewGesture; } // If the active gesture is valid, map the gesture to the map for fast lookup when processing bindings if( InCommandInfo->ActiveGesture->IsValidGesture() ) { checkSlow( !ContextEntry.GestureToCommandInfoMap.Contains( *InCommandInfo->GetActiveGesture() ) ); ContextEntry.GestureToCommandInfoMap.Add( *InCommandInfo->GetActiveGesture(), InCommandInfo->GetCommandName() ); } }