Skip to content

Commit

Permalink
5.3 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlicekdominik committed Jul 8, 2024
1 parent 19023ef commit 3b3bf7f
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include "Helpers/ActorInteractionPluginLog.h"

#if WITH_EDITOR

#include "EditorHelper.h"
#include "Misc/DataValidation.h"

#endif

#include "CommonInputSubsystem.h"
Expand All @@ -21,6 +24,7 @@
#include "Interfaces/ActorInteractionWidget.h"
#include "Interfaces/ActorInteractorInterface.h"


#include "Net/UnrealNetwork.h"

#define LOCTEXT_NAMESPACE "InteractableComponentBase"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2353,12 +2366,12 @@ void UActorInteractableComponentBase::PostEditChangeChainProperty(FPropertyChang
}
}

EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray<FText>& 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();
{
Expand All @@ -2383,12 +2396,10 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray<FText>
{
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;
}

Expand All @@ -2398,10 +2409,8 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray<FText>
(
interactableName.Append(TEXT(": DefaultInteractableState cannot be lesser than -1!"))
);

InteractionPeriod = -1.f;

ValidationErrors.Add(ErrorMessage);
Context.AddError(ErrorMessage);
bAnyError = true;
}

Expand All @@ -2411,11 +2420,8 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray<FText>
(
interactableName.Append(TEXT(":")).Append(TEXT(" LifecycleCount cannot be %d!"), LifecycleCount)
);

LifecycleCount = 2.f;
RemainingLifecycleCount = LifecycleCount;

ValidationErrors.Add(ErrorMessage);
Context.AddError(ErrorMessage);
bAnyError = true;
}

Expand All @@ -2426,7 +2432,7 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray<FText>
interactableName.Append(TEXT(": Widget Class is NULL!"))
);

ValidationErrors.Add(ErrorMessage);
Context.AddError(ErrorMessage);
bAnyError = true;
}
else
Expand All @@ -2437,13 +2443,22 @@ EDataValidationResult UActorInteractableComponentBase::IsDataValid(TArray<FText>
(
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include "Components/Interactable/ActorInteractableComponentPress.h"

#if WITH_EDITOR

#include "EditorHelper.h"
#include "Misc/DataValidation.h"

#endif

#define LOCTEXT_NAMESPACE "InteractableComponentPress"
Expand Down Expand Up @@ -87,9 +90,9 @@ void UActorInteractableComponentPress::PostEditChangeChainProperty(FPropertyChan
}
}

EDataValidationResult UActorInteractableComponentPress::IsDataValid(TArray<FText>& ValidationErrors)
EDataValidationResult UActorInteractableComponentPress::IsDataValid(FDataValidationContext& Context) const
{
const EDataValidationResult SuperResult = Super::IsDataValid(ValidationErrors);
const EDataValidationResult SuperResult = Super::IsDataValid(Context);

bool bAnyError = SuperResult == EDataValidationResult::Invalid;

Expand All @@ -110,18 +113,21 @@ EDataValidationResult UActorInteractableComponentPress::IsDataValid(TArray<FText

if (!FMath::IsNearlyEqual(InteractionPeriod, -1.f))
{
InteractionPeriod = -1.f;

const FText ErrorMessage = FText::FromString
(
interactableName.Append(TEXT(": Widget Class is NULL!"))
interactableName.Append(TEXT(": InteractionPeriod must be -1.f!"))
);

ValidationErrors.Add(ErrorMessage);
Context.AddError(ErrorMessage);
bAnyError = true;
}

return bAnyError ? EDataValidationResult::Invalid : EDataValidationResult::Valid;
if (bAnyError && RequestEditorDefaults.IsBound())
{
RequestEditorDefaults.Broadcast();
}

return bAnyError ? EDataValidationResult::Invalid : SuperResult;
}

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@

#include "Components/Interactor/ActorInteractorComponentBase.h"

#include "Helpers/ActorInteractionPluginLog.h"


#if WITH_EDITOR

#include "EditorHelper.h"
#include "Misc/DataValidation.h"

#endif

#include "Helpers/ActorInteractionFunctionLibrary.h"
#include "Helpers/InteractionHelpers.h"
#include "Helpers/MounteaInteractionSystemBFL.h"
#include "Helpers/ActorInteractionPluginLog.h"

#include "Interfaces/ActorInteractableInterface.h"

#include "Net/UnrealNetwork.h"
#include "Net/Core/PushModel/PushModel.h"

Expand All @@ -32,7 +35,14 @@ UActorInteractorComponentBase::UActorInteractorComponentBase() :
PrimaryComponentTick.bStartWithTickEnabled = false;

ComponentTags.Add(FName("Mountea"));
ComponentTags.Add(FName("Interaction"));
ComponentTags.Add(FName("Interaction"));

#if WITH_EDITOR || WITH_EDITORONLY_DATA
if (GIsEditor && !GIsPlayInEditorWorld)
{
RequestEditorDefaults.AddUObject(this, &UActorInteractorComponentBase::ResetDefaults);
}
#endif
}

void UActorInteractorComponentBase::BeginPlay()
Expand All @@ -55,7 +65,7 @@ void UActorInteractorComponentBase::BeginPlay()
Execute_AddIgnoredActor(this, GetOwner());

Execute_SetState(this, DefaultInteractorState);
}
}
}

FString UActorInteractorComponentBase::ToString_Implementation() const
Expand Down Expand Up @@ -1030,6 +1040,11 @@ void UActorInteractorComponentBase::SetState_Server_Implementation(const EIntera

#if WITH_EDITOR

void UActorInteractorComponentBase::ResetDefaults()
{
Execute_SetDefaults(this);
}

void UActorInteractorComponentBase::PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent)
{
const FName PropertyName = (PropertyChangedEvent.MemberProperty != nullptr) ? PropertyChangedEvent.GetPropertyName() : NAME_None;
Expand Down Expand Up @@ -1068,9 +1083,9 @@ void UActorInteractorComponentBase::PostEditChangeChainProperty(FPropertyChanged
}
}

EDataValidationResult UActorInteractorComponentBase::IsDataValid(TArray<FText>& 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();
Expand All @@ -1096,14 +1111,22 @@ EDataValidationResult UActorInteractorComponentBase::IsDataValid(TArray<FText>&
{
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FText>& ValidationErrors) override;
virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override;

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ACTORINTERACTIONPLUGIN_API UActorInteractableComponentPress : public UActo

#if WITH_EDITOR
virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override;
virtual EDataValidationResult IsDataValid(TArray<FText>& ValidationErrors) override;
virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override;
#endif

};
Original file line number Diff line number Diff line change
Expand Up @@ -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<FText>& ValidationErrors) override;
virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override;

#endif

Expand Down

0 comments on commit 3b3bf7f

Please sign in to comment.