From 3b3bf7f9619b57d4ef4b7a7ead11d87f160065f6 Mon Sep 17 00:00:00 2001 From: Dominik Morse Date: Mon, 8 Jul 2024 19:17:54 +0200 Subject: [PATCH] 5.3 Update --- .../ActorInteractableComponentBase.cpp | 51 ++++++++++++------- .../ActorInteractableComponentPress.cpp | 20 +++++--- .../ActorInteractorComponentBase.cpp | 45 ++++++++++++---- .../ActorInteractableComponentBase.h | 6 ++- .../ActorInteractableComponentPress.h | 2 +- .../Interactor/ActorInteractorComponentBase.h | 6 ++- 6 files changed, 91 insertions(+), 39 deletions(-) diff --git a/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentBase.cpp b/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentBase.cpp index b34a4c6..601cc51 100644 --- a/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentBase.cpp +++ b/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentBase.cpp @@ -5,7 +5,10 @@ #include "Helpers/ActorInteractionPluginLog.h" #if WITH_EDITOR + #include "EditorHelper.h" +#include "Misc/DataValidation.h" + #endif #include "CommonInputSubsystem.h" @@ -21,6 +24,7 @@ #include "Interfaces/ActorInteractionWidget.h" #include "Interfaces/ActorInteractorInterface.h" + #include "Net/UnrealNetwork.h" #define LOCTEXT_NAMESPACE "InteractableComponentBase" @@ -68,6 +72,10 @@ UActorInteractableComponentBase::UActorInteractableComponentBase() : #endif #if WITH_EDITOR || WITH_EDITORONLY_DATA + if (GIsEditor && !GIsPlayInEditorWorld) + { + RequestEditorDefaults.AddUObject(this, &UActorInteractableComponentBase::ResetDefaults); + } if (GIsEditor && !GIsPlayInEditorWorld && !bInteractableInitialized) { SetDefaultValues(); @@ -2222,6 +2230,11 @@ void UActorInteractableComponentBase::SetState_Server_Implementation(const EInte #if (!UE_BUILD_SHIPPING || WITH_EDITOR) #if WITH_EDITOR +void UActorInteractableComponentBase::ResetDefaults() +{ + Execute_SetDefaults(this); +} + void UActorInteractableComponentBase::PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) { const FName PropertyName = (PropertyChangedEvent.MemberProperty != nullptr) ? PropertyChangedEvent.GetPropertyName() : NAME_None; @@ -2353,12 +2366,12 @@ void UActorInteractableComponentBase::PostEditChangeChainProperty(FPropertyChang } } -EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray& ValidationErrors) +EDataValidationResult UActorInteractableComponentBase::IsDataValid(FDataValidationContext& Context) const { - const auto DefaultValue = Super::IsDataValid(ValidationErrors); + const auto DefaultValue = Super::IsDataValid(Context); bool bAnyError = false; - if (DefaultInteractableState == EInteractableStateV2::EIS_Disabled) + // Validation { FString interactableName = GetName(); { @@ -2383,12 +2396,10 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray { const FText ErrorMessage = FText::FromString ( - interactableName.Append(TEXT(": DefaultInteractableState cannot be")).Append(GetEnumValueAsString("EInteractableStateV2", DefaultInteractableState)).Append(TEXT("!")) + interactableName.Append(TEXT(": DefaultInteractableState cannot be ")).Append(GetEnumValueAsString("EInteractableStateV2", DefaultInteractableState)).Append(TEXT("!")) ); - - DefaultInteractableState = EInteractableStateV2::EIS_Awake; - ValidationErrors.Add(ErrorMessage); + Context.AddError(ErrorMessage); bAnyError = true; } @@ -2398,10 +2409,8 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray ( interactableName.Append(TEXT(": DefaultInteractableState cannot be lesser than -1!")) ); - - InteractionPeriod = -1.f; - ValidationErrors.Add(ErrorMessage); + Context.AddError(ErrorMessage); bAnyError = true; } @@ -2411,11 +2420,8 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray ( interactableName.Append(TEXT(":")).Append(TEXT(" LifecycleCount cannot be %d!"), LifecycleCount) ); - - LifecycleCount = 2.f; - RemainingLifecycleCount = LifecycleCount; - ValidationErrors.Add(ErrorMessage); + Context.AddError(ErrorMessage); bAnyError = true; } @@ -2426,7 +2432,7 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray interactableName.Append(TEXT(": Widget Class is NULL!")) ); - ValidationErrors.Add(ErrorMessage); + Context.AddError(ErrorMessage); bAnyError = true; } else @@ -2437,13 +2443,22 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray ( interactableName.Append(TEXT(" : Widget Class must either implement 'ActorInteractionWidget Interface'!")) ); - - SetWidgetClass(nullptr); - ValidationErrors.Add(ErrorMessage); + + Context.AddError(ErrorMessage); bAnyError = true; } } } + + if (bAnyError && RequestEditorDefaults.IsBound()) + { + RequestEditorDefaults.Broadcast(); + } + + if (bAnyError) + { + Context.AddWarning(FText::FromString("Interactable failed to Validate. `SetDefaults` has been called. Some settings might have been overriden by default values!")); + } return bAnyError ? EDataValidationResult::Invalid : DefaultValue; } diff --git a/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentPress.cpp b/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentPress.cpp index 3613a43..eb0aa0c 100644 --- a/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentPress.cpp +++ b/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentPress.cpp @@ -4,7 +4,10 @@ #include "Components/Interactable/ActorInteractableComponentPress.h" #if WITH_EDITOR + #include "EditorHelper.h" +#include "Misc/DataValidation.h" + #endif #define LOCTEXT_NAMESPACE "InteractableComponentPress" @@ -87,9 +90,9 @@ void UActorInteractableComponentPress::PostEditChangeChainProperty(FPropertyChan } } -EDataValidationResult UActorInteractableComponentPress::IsDataValid(TArray& ValidationErrors) +EDataValidationResult UActorInteractableComponentPress::IsDataValid(FDataValidationContext& Context) const { - const EDataValidationResult SuperResult = Super::IsDataValid(ValidationErrors); + const EDataValidationResult SuperResult = Super::IsDataValid(Context); bool bAnyError = SuperResult == EDataValidationResult::Invalid; @@ -110,18 +113,21 @@ EDataValidationResult UActorInteractableComponentPress::IsDataValid(TArray& ValidationErrors) +EDataValidationResult UActorInteractorComponentBase::IsDataValid(FDataValidationContext& Context) const { - const auto DefaultValue = Super::IsDataValid(ValidationErrors); + const auto DefaultValue = Super::IsDataValid(Context); bool bAnyError = false; FString InteractorName = GetName(); @@ -1096,14 +1111,22 @@ EDataValidationResult UActorInteractorComponentBase::IsDataValid(TArray& { const FText ErrorMessage = FText::FromString ( - InteractorName.Append(TEXT(": DefaultInteractorState cannot be")).Append(GetEnumValueAsString("EInteractorStateV2", DefaultInteractorState)).Append(TEXT("!")) + InteractorName.Append(TEXT(": DefaultInteractorState cannot be ")).Append(GetEnumValueAsString("EInteractorStateV2", DefaultInteractorState)).Append(TEXT("!")) ); - - DefaultInteractorState = EInteractorStateV2::EIS_Awake; - ValidationErrors.Add(ErrorMessage); + Context.AddError(ErrorMessage); bAnyError = true; } + + if (bAnyError && RequestEditorDefaults.IsBound()) + { + RequestEditorDefaults.Broadcast(); + } + + if (bAnyError) + { + Context.AddWarning(FText::FromString("Interactable failed to Validate. `SetDefaults` has been called. Some settings might have been overriden by default values!")); + } return bAnyError ? EDataValidationResult::Invalid : DefaultValue; } diff --git a/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentBase.h b/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentBase.h index e7bc620..b2580c4 100644 --- a/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentBase.h +++ b/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentBase.h @@ -1130,9 +1130,13 @@ class ACTORINTERACTIONPLUGIN_API UActorInteractableComponentBase : public UWidge #if (!UE_BUILD_SHIPPING || WITH_EDITOR) #if WITH_EDITOR protected: + + DECLARE_EVENT(UActorInteractableComponentBase, FRequestEditorDefaults); + FRequestEditorDefaults RequestEditorDefaults; + virtual void ResetDefaults(); virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override; - virtual EDataValidationResult IsDataValid(TArray& ValidationErrors) override; + virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override; #endif diff --git a/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentPress.h b/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentPress.h index fcc472a..1b28466 100644 --- a/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentPress.h +++ b/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentPress.h @@ -35,7 +35,7 @@ class ACTORINTERACTIONPLUGIN_API UActorInteractableComponentPress : public UActo #if WITH_EDITOR virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override; - virtual EDataValidationResult IsDataValid(TArray& ValidationErrors) override; + virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override; #endif }; diff --git a/Source/ActorInteractionPlugin/Public/Components/Interactor/ActorInteractorComponentBase.h b/Source/ActorInteractionPlugin/Public/Components/Interactor/ActorInteractorComponentBase.h index e707777..855d533 100644 --- a/Source/ActorInteractionPlugin/Public/Components/Interactor/ActorInteractorComponentBase.h +++ b/Source/ActorInteractionPlugin/Public/Components/Interactor/ActorInteractorComponentBase.h @@ -329,8 +329,12 @@ class ACTORINTERACTIONPLUGIN_API UActorInteractorComponentBase : public UActorCo protected: + DECLARE_EVENT(UActorInteractorComponentBase, FRequestInteractorEditorDefaults); + FRequestInteractorEditorDefaults RequestEditorDefaults; + virtual void ResetDefaults(); + virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override; - virtual EDataValidationResult IsDataValid(TArray& ValidationErrors) override; + virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override; #endif