From bd195c7ee86cff5a45d19a5b570e2badc5d049b5 Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Thu, 10 Aug 2023 22:27:40 -0400 Subject: [PATCH] Add callback for when movement mode on character is changed --- .../UnrealFightingFramework/State/FFState.cpp | 13 +++++++++++++ .../UnrealFightingFramework/State/FFState.h | 16 ++++++++++++++++ .../State/FFStateMachineComponent.cpp | 19 +++++++++++++++++++ .../State/FFStateMachineComponent.h | 3 +++ 4 files changed, 51 insertions(+) diff --git a/Source/UnrealFightingFramework/State/FFState.cpp b/Source/UnrealFightingFramework/State/FFState.cpp index d4129d1..95cd2bd 100644 --- a/Source/UnrealFightingFramework/State/FFState.cpp +++ b/Source/UnrealFightingFramework/State/FFState.cpp @@ -126,6 +126,19 @@ void UFFState::Landed(const FHitResult& Hit, const FFFStateContext& InStateConte } +void UFFState::MovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode, + EMovementMode NewMovementMode, uint8 NewCustomMode, const FFFStateContext& InStateContext) +{ + OnMovementModeChanged(PrevMovementMode, PreviousCustomMode, + NewMovementMode, NewCustomMode, InStateContext); + + if(NewMovementMode != ReqMovementMode || ((ReqMovementMode == MOVE_Custom) && NewCustomMode != RequiredCustomMode)) + { + Finish(InStateContext); + } +} + + void UFFState::Hit(const FFFStateContext& InStateContext) { OnHit(InStateContext); diff --git a/Source/UnrealFightingFramework/State/FFState.h b/Source/UnrealFightingFramework/State/FFState.h index 13e9c9f..6fe99ce 100644 --- a/Source/UnrealFightingFramework/State/FFState.h +++ b/Source/UnrealFightingFramework/State/FFState.h @@ -108,6 +108,12 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="UFF State Properties") bool bCanTransitionToSelf = false; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="UFF State Properties") + TEnumAsByte ReqMovementMode; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="UFF State Properties") + uint8 RequiredCustomMode; + /** * Animation to begin playing when this state is entered */ @@ -159,6 +165,10 @@ public: // TODO: document virtual void Landed(const FHitResult& Hit, const FFFStateContext& InStateContext); + // TODO: document + virtual void MovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode, + EMovementMode NewMovementMode, uint8 NewCustomMode, const FFFStateContext& InStateContext); + // TODO: document // TODO: pass in hitdata struct as well virtual void Hit(const FFFStateContext& InStateContext); @@ -188,6 +198,7 @@ public: virtual void RegisterInputHandler( const FFFInputSequence& InRequiredSequence, FFFInputEventDelegate InDelegate); + // TODO: document UFUNCTION(BlueprintNativeEvent, Category="UFF|State|Events") void OnInit(const FFFStateContext& InStateContext); @@ -221,6 +232,11 @@ public: UFUNCTION(BlueprintImplementableEvent, Category="UFF|State|Events") void OnLanded(const FHitResult& Hit, const FFFStateContext& InStateContext); + // TODO: document + UFUNCTION(BlueprintImplementableEvent, Category="UFF|State|Events") + void OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode, + EMovementMode NewMovementMode, uint8 NewCustomMode, const FFFStateContext& InStateContext); + // TODO: document // TODO: pass in hitdata struct as well UFUNCTION(BlueprintImplementableEvent, Category="UFF|State|Events") diff --git a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp index 0b7c716..54bf8cd 100644 --- a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp +++ b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp @@ -160,6 +160,25 @@ void UFFStateMachineComponent::Landed(const FHitResult& Hit) } +void UFFStateMachineComponent::MovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode, + EMovementMode NewMovementMode, uint8 NewCustomMode) +{ + // TODO: this check should be valid but isn't right now. + // Movement mode changed seems to be called whenever the character is first created but before + // any states are created and entered. + // For now just check if CurrentState is null and don't call the MovementModeChanged callback if + // so + //check(CurrentState) + if(!CurrentState) + { + return; + } + + CurrentState->MovementModeChanged(PrevMovementMode, PreviousCustomMode, + NewMovementMode, NewCustomMode, GetCurrentStateContext()); +} + + void UFFStateMachineComponent::FixedTick(float OneFrame) { // CurrentState should never be null diff --git a/Source/UnrealFightingFramework/State/FFStateMachineComponent.h b/Source/UnrealFightingFramework/State/FFStateMachineComponent.h index 4030cfc..11aed2d 100644 --- a/Source/UnrealFightingFramework/State/FFStateMachineComponent.h +++ b/Source/UnrealFightingFramework/State/FFStateMachineComponent.h @@ -104,6 +104,9 @@ public: // Events virtual void Landed(const FHitResult& Hit); + virtual void MovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode, + EMovementMode NewMovementMode, uint8 NewCustomMode); + // IFFSystemInterface interface virtual void FixedTick(float OneFrame) override; // End of IFFSystemInterface interface