Files
Plugin/Source/SenseGloveSettings/Private/SGSettings/SGWristTrackingDetailsCustomization.cpp
T

218 lines
6.8 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2025 SenseGlove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
*
*
*/
#include "SGSettings/SGWristTrackingDetailsCustomization.h"
#include "IMotionController.h"
#include "Widgets/Input/SComboBox.h"
#include "Widgets/Text/STextBlock.h"
#include "SGLog/SGLog.h"
struct FSGWristTrackingDetailsCustomization::FImpl
{
/************************
* Typedefs
************************/
/************************
* Static methods
************************/
FORCENOINLINE static const FString& GetLeftHandMotionSourcePropertyName()
{
static const FString Name{TEXT("LeftHandMotionSource")};
return Name;
}
FORCENOINLINE static const FString& GetRightHandMotionSourcePropertyName()
{
static const FString Name{TEXT("RightHandMotionSource")};
return Name;
}
/************************
* Member variables
************************/
TArray<TSharedPtr<FName>> MotionSources;
/************************
* Owner object
************************/
FSGWristTrackingDetailsCustomization* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(FSGWristTrackingDetailsCustomization* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = delete;
FImpl& operator=(const FImpl& Rhs) = delete;
/************************
* Methods
************************/
void PopulateComboBoxOptions();
};
TSharedRef<IPropertyTypeCustomization> FSGWristTrackingDetailsCustomization::NewWristTrackingDetailsCustomization()
{
return MakeShareable(new FSGWristTrackingDetailsCustomization{});
}
FSGWristTrackingDetailsCustomization::FSGWristTrackingDetailsCustomization()
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
void FSGWristTrackingDetailsCustomization::CustomizeHeader(
TSharedRef<IPropertyHandle> PropertyHandle,
FDetailWidgetRow& HeaderRow,
IPropertyTypeCustomizationUtils& CustomizationUtils)
{
HeaderRow.NameContent()
[
PropertyHandle->CreatePropertyNameWidget()
]
.ValueContent()
[
PropertyHandle->CreatePropertyValueWidget()
];
}
void FSGWristTrackingDetailsCustomization::CustomizeChildren(
TSharedRef<IPropertyHandle> PropertyHandle,
IDetailChildrenBuilder& ChildBuilder,
IPropertyTypeCustomizationUtils& CustomizationUtils)
{
Pimpl->PopulateComboBoxOptions();
uint32 NumChildren;
PropertyHandle->GetNumChildren(NumChildren);
for (uint32 Index = 0; Index < NumChildren; ++Index)
{
TSharedRef<IPropertyHandle> ChildHandle{PropertyHandle->GetChildHandle(Index).ToSharedRef()};
if (ChildHandle->GetProperty()->GetName() == Pimpl->GetLeftHandMotionSourcePropertyName()
|| ChildHandle->GetProperty()->GetName() == Pimpl->GetRightHandMotionSourcePropertyName())
{
ChildBuilder.AddCustomRow(ChildHandle->GetPropertyDisplayName())
.NameContent()
[
ChildHandle->CreatePropertyNameWidget()
]
.ValueContent()
[
SNew(SComboBox<TSharedPtr<FName>>)
.OptionsSource(&Pimpl->MotionSources)
.OnGenerateWidget_Lambda([](TSharedPtr<FName> InItem)
{
return SNew(STextBlock).Text(FText::FromName(*InItem));
})
.OnSelectionChanged_Lambda([ChildHandle](TSharedPtr<FName> NewValue, ESelectInfo::Type)
{
if (NewValue.IsValid())
{
ChildHandle->SetValue(*NewValue);
}
})
.Content()
[
SNew(STextBlock)
.Text_Lambda([ChildHandle]()
{
FName CurrentValue;
ChildHandle->GetValue(CurrentValue);
return FText::FromName(CurrentValue);
})
]
];
}
else
{
ChildBuilder.AddProperty(ChildHandle);
}
}
}
void FSGWristTrackingDetailsCustomization::FImpl::PopulateComboBoxOptions()
{
SGLOG("Populating the FSGWristTrackingSettings MotionSources...");
MotionSources.Reset();
const TArray<IMotionController*> MotionControllers{
IModularFeatures::Get().GetModularFeatureImplementations<
IMotionController>(IMotionController::GetModularFeatureName())
};
for (const IMotionController* MotionController: MotionControllers)
{
if (MotionController)
{
TArray<FMotionControllerSource> MotionControllerSources;
MotionController->EnumerateSources(MotionControllerSources);
MotionSources.Reserve(MotionSources.Num() + MotionControllerSources.Num());
for (const FMotionControllerSource& MotionSource: MotionControllerSources)
{
SGLOG("Discovered a new motion source", MotionSource.SourceName);
MotionSources.AddUnique(MakeShareable(new FName{MotionSource.SourceName}));
}
}
}
}
FSGWristTrackingDetailsCustomization::FImpl::FImpl(FSGWristTrackingDetailsCustomization* InOwner)
: Owner(InOwner)
{
}
FSGWristTrackingDetailsCustomization::FImpl::~FImpl() = default;
void FSGWristTrackingDetailsCustomization::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}