From 2b4027282dbe42837f445ad9931a662931745307 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Tue, 21 Mar 2023 16:50:20 +0100 Subject: [PATCH] allow setting custom hardware offset through the plugin settings --- .../Private/SGSettings/SGSettings.cpp | 62 ++++++++++++++++--- .../Public/SGSettings/SGSettings.h | 24 +++++++ .../SenseGloveSettings.Build.cs | 1 + 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/Source/SenseGloveSettings/Private/SGSettings/SGSettings.cpp b/Source/SenseGloveSettings/Private/SGSettings/SGSettings.cpp index 8fd96eb5..024069b3 100644 --- a/Source/SenseGloveSettings/Private/SGSettings/SGSettings.cpp +++ b/Source/SenseGloveSettings/Private/SGSettings/SGSettings.cpp @@ -38,6 +38,7 @@ #include "Engine/Engine.h" #include "SGLog/SGLog.h" +#include "SGCore/SGTracking.h" struct USGSettings::FImpl { @@ -68,6 +69,8 @@ struct USGSettings::FImpl /************************ * Methods ************************/ + + void ResetHardwareOffsetValuesToZero(); }; USGSettings* USGSettings::GetInstance() @@ -76,17 +79,12 @@ USGSettings* USGSettings::GetInstance() return Instance; } -void USGSettings::FImplDeleter::operator()(const FImpl* P) const -{ - delete P; -} - USGSettings::USGSettings() : Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) { HardwareOffset = ESGPositionalTrackingHardware::None; - HardwareLocationOffset = FVector::ZeroVector; - HardwareRotationOffset = FRotator::ZeroRotator; + + Pimpl->ResetHardwareOffsetValuesToZero(); } bool USGSettings::ShouldCreateSubsystem(UObject* Outer) const @@ -116,9 +114,57 @@ void USGSettings::Deinitialize() SGLOG("The SenseGlove settings singleton has been successfully de-initialized!"); } +#if WITH_EDITOR +bool USGSettings::CanEditChange(const FProperty* InProperty) const +{ + bool bCanEditChange = Super::CanEditChange(InProperty); + + /*const FName PropertyName{InProperty ? InProperty->GetFName() : NAME_None}; + + if (PropertyName == GET_MEMBER_NAME_CHECKED(USGSettings, HardwareOffset)) + { + return HardwareOffset == ESGPositionalTrackingHardware::Custom; + }*/ + + return bCanEditChange; +} +#endif /* WITH_EDITOR */ + +#if WITH_EDITOR +void USGSettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) +{ + Super::PostEditChangeProperty(PropertyChangedEvent); + + const FName PropertyName{ + PropertyChangedEvent.Property + ? PropertyChangedEvent.Property->GetFName() + : NAME_None + }; + + if (PropertyName == GET_MEMBER_NAME_CHECKED(USGSettings, HardwareOffset)) + { + Pimpl->ResetHardwareOffsetValuesToZero(); + return; + } +} +#endif /* WITH_EDITOR */ + USGSettings::FImpl::FImpl(USGSettings* InOwner) : Owner(InOwner) { } -USGSettings::FImpl::~FImpl() = default; \ No newline at end of file +USGSettings::FImpl::~FImpl() = default; + +void USGSettings::FImpl::ResetHardwareOffsetValuesToZero() +{ + Owner->HardwareLocationOffsetLeftHand = FVector::ZeroVector; + Owner->HardwareLocationOffsetRightHand = FVector::ZeroVector; + Owner->HardwareRotationOffsetLeftHand = FRotator::ZeroRotator; + Owner->HardwareRotationOffsetRightHand = FRotator::ZeroRotator; +} + +void USGSettings::FImplDeleter::operator()(const FImpl* P) const +{ + delete P; +} \ No newline at end of file diff --git a/Source/SenseGloveSettings/Public/SGSettings/SGSettings.h b/Source/SenseGloveSettings/Public/SGSettings/SGSettings.h index bd5e95ad..25e07f53 100644 --- a/Source/SenseGloveSettings/Public/SGSettings/SGSettings.h +++ b/Source/SenseGloveSettings/Public/SGSettings/SGSettings.h @@ -35,6 +35,8 @@ #pragma once +#include "Math/Rotator.h" +#include "Math/Vector.h" #include "Subsystems/EngineSubsystem.h" #include "Templates/UniquePtr.h" #include "UObject/ObjectMacros.h" @@ -66,6 +68,22 @@ private: UPROPERTY(Config, EditDefaultsOnly, Category = "Wrist Tracking") ESGPositionalTrackingHardware HardwareOffset; + UPROPERTY(Config, EditDefaultsOnly, Category = "Wrist Tracking", + meta=(EditCondition="HardwareOffset == ESGPositionalTrackingHardware::Custom", EditConditionHides)) + FVector HardwareLocationOffsetLeftHand; + + UPROPERTY(Config, EditDefaultsOnly, Category = "Wrist Tracking", + meta=(EditCondition="HardwareOffset == ESGPositionalTrackingHardware::Custom", EditConditionHides)) + FVector HardwareLocationOffsetRightHand; + + UPROPERTY(Config, EditDefaultsOnly, Category = "Wrist Tracking", + meta=(EditCondition="HardwareOffset == ESGPositionalTrackingHardware::Custom", EditConditionHides)) + FRotator HardwareRotationOffsetLeftHand; + + UPROPERTY(Config, EditDefaultsOnly, Category = "Wrist Tracking", + meta=(EditCondition="HardwareOffset == ESGPositionalTrackingHardware::Custom", EditConditionHides)) + FRotator HardwareRotationOffsetRightHand; + public: USGSettings(); @@ -85,4 +103,10 @@ public: virtual void Initialize(FSubsystemCollectionBase& Collection) override; virtual void Deinitialize() override; + +public: +#if WITH_EDITOR + virtual bool CanEditChange(const FProperty* InProperty) const override; + virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; +#endif /* WITH_EDITOR */ }; \ No newline at end of file diff --git a/Source/SenseGloveSettings/SenseGloveSettings.Build.cs b/Source/SenseGloveSettings/SenseGloveSettings.Build.cs index 50451ab8..de0595d5 100644 --- a/Source/SenseGloveSettings/SenseGloveSettings.Build.cs +++ b/Source/SenseGloveSettings/SenseGloveSettings.Build.cs @@ -55,6 +55,7 @@ public class SenseGloveSettings : ModuleRules "CoreUObject", "Engine", "Settings", + "SenseGloveCore", "SenseGloveLog", "SenseGloveTypes", }