You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rnx #rb none #ROBOMERGE-SOURCE: CL 10869241 via CL 10869527 via CL 10869904 #ROBOMERGE-BOT: (v613-10869866) [CL 10870586 by ryan durand in Main branch]
96 lines
2.8 KiB
C++
96 lines
2.8 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "MotionControllerSourceCustomization.h"
|
|
#include "PropertyHandle.h"
|
|
#include "Framework/Application/SlateApplication.h"
|
|
#include "Framework/MultiBox/MultiBoxBuilder.h"
|
|
#include "Features/IModularFeatures.h"
|
|
#include "IMotionController.h"
|
|
#include "Widgets/Input/SComboBox.h"
|
|
#include "Widgets/Input/SEditableTextBox.h"
|
|
|
|
void SMotionSourceWidget::Construct(const FArguments& InArgs)
|
|
{
|
|
check(InArgs._OnMotionSourceChanged.IsBound());
|
|
check(InArgs._OnGetMotionSourceText.IsBound());
|
|
|
|
OnMotionSourceChanged = InArgs._OnMotionSourceChanged;
|
|
OnGetMotionSourceText = InArgs._OnGetMotionSourceText;
|
|
|
|
this->ChildSlot
|
|
[
|
|
SNew(SComboButton)
|
|
.ContentPadding(1)
|
|
.OnGetMenuContent(this, &SMotionSourceWidget::BuildMotionSourceMenu)
|
|
.ButtonContent()
|
|
[
|
|
SNew(SEditableTextBox)
|
|
.RevertTextOnEscape(true)
|
|
.SelectAllTextWhenFocused(true)
|
|
.Text(this, &SMotionSourceWidget::GetMotionSourceText)
|
|
.OnTextCommitted(this, &SMotionSourceWidget::OnMotionSourceValueTextComitted)
|
|
]
|
|
];
|
|
}
|
|
|
|
TSharedRef<SWidget> SMotionSourceWidget::BuildMotionSourceMenu()
|
|
{
|
|
TMap<FName, TArray<FName>> CategorizedMotionSources;
|
|
|
|
TArray<IMotionController*> MotionControllers = IModularFeatures::Get().GetModularFeatureImplementations<IMotionController>(IMotionController::GetModularFeatureName());
|
|
for (IMotionController* MotionController : MotionControllers)
|
|
{
|
|
if (MotionController)
|
|
{
|
|
TArray<FMotionControllerSource> MotionSources;
|
|
MotionController->EnumerateSources(MotionSources);
|
|
|
|
for (FMotionControllerSource& Source : MotionSources)
|
|
{
|
|
CategorizedMotionSources.FindOrAdd(Source.EditorCategory).AddUnique(Source.SourceName);
|
|
}
|
|
}
|
|
}
|
|
|
|
FMenuBuilder MenuBuilder(true, NULL);
|
|
|
|
for (TPair<FName, TArray<FName>> Pair : CategorizedMotionSources)
|
|
{
|
|
const bool bWrapInSection = !Pair.Key.IsNone();
|
|
if (bWrapInSection)
|
|
{
|
|
MenuBuilder.BeginSection(Pair.Key, FText::FromName(Pair.Key));
|
|
}
|
|
|
|
for (FName SourceName : Pair.Value)
|
|
{
|
|
FUIAction MenuAction(FExecuteAction::CreateSP(this, &SMotionSourceWidget::OnMotionSourceComboValueCommited, SourceName));
|
|
MenuBuilder.AddMenuEntry(FText::FromName(SourceName), FText(), FSlateIcon(), MenuAction);
|
|
}
|
|
|
|
if (bWrapInSection)
|
|
{
|
|
MenuBuilder.EndSection();
|
|
}
|
|
}
|
|
|
|
return MenuBuilder.MakeWidget();
|
|
}
|
|
|
|
FText SMotionSourceWidget::GetMotionSourceText() const
|
|
{
|
|
return OnGetMotionSourceText.Execute();
|
|
}
|
|
|
|
void SMotionSourceWidget::OnMotionSourceValueTextComitted(const FText& InNewText, ETextCommit::Type InTextCommit)
|
|
{
|
|
FName NewMotionSource = *InNewText.ToString();
|
|
OnMotionSourceChanged.Execute(NewMotionSource);
|
|
}
|
|
|
|
void SMotionSourceWidget::OnMotionSourceComboValueCommited(FName InMotionSource)
|
|
{
|
|
FSlateApplication::Get().ClearKeyboardFocus(EFocusCause::Cleared);
|
|
OnMotionSourceChanged.Execute(InMotionSource);
|
|
}
|