From 095cf66937cf00076209e3db35b01cb4173c03b8 Mon Sep 17 00:00:00 2001 From: Jamie Greunbaum Date: Sun, 17 Sep 2023 17:35:43 -0400 Subject: [PATCH] Release actions are now supported, and fired the same frame as an Activated action if the action was buffered and then released. --- .../Components/ComboManagerComponent.cpp | 18 ++++-------------- .../Private/Events/K2Node_ComboAction.cpp | 2 +- .../InputBufferLocalPlayerSubsystem.cpp | 7 +++++++ .../Public/Components/ComboManagerComponent.h | 2 ++ 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Source/ComboInput/Private/Components/ComboManagerComponent.cpp b/Source/ComboInput/Private/Components/ComboManagerComponent.cpp index bc3a1f0..ddddca0 100644 --- a/Source/ComboInput/Private/Components/ComboManagerComponent.cpp +++ b/Source/ComboInput/Private/Components/ComboManagerComponent.cpp @@ -111,21 +111,10 @@ void UComboManagerComponent::DEBUG__UnlockAction(TObjectPtr CurrentNode = (this->ActiveNode ? this->ActiveNode : this->DefaultStartNode); - checkf(CurrentNode, TEXT("No combo sequence nodes available.")); - - const FComboSequenceAction *ActionData = CurrentNode->ComboBranch.Find(Input); - // If this node has an action we can release, then release it. - if (ActionData && ActionData->ComboAction) + if (this->LastComboAction) { - this->BroadcastDelegates(ActionData->ComboAction, EComboActionTriggerEvent::Released); - UE_LOG(LogComboManagerComponent, Verbose, TEXT("%s released"), *ActionData->ComboAction->ActionName.ToString()); - } - // Otherwise, see if we have a fallback we can use. - else if (const TObjectPtr *ComboAction = this->FallbackActions.Find(Input)) - { - this->BroadcastDelegates(*ComboAction, EComboActionTriggerEvent::Released); - UE_LOG(LogComboManagerComponent, Verbose, TEXT("Fallback action %s released"), *(*ComboAction)->ActionName.ToString()); + this->BroadcastDelegates(this->LastComboAction, EComboActionTriggerEvent::Released); + this->LastComboAction = nullptr; } } @@ -159,4 +148,5 @@ void UComboManagerComponent::BroadcastDelegates(const UComboAction *ComboAction, Binding->Execute(ComboAction, TriggerEvent); } this->OnComboAction.Broadcast(ComboAction, (TriggerEvent == EComboActionTriggerEvent::Activated) ? true : false); + this->LastComboAction = ComboAction; } diff --git a/Source/ComboInput/Private/Events/K2Node_ComboAction.cpp b/Source/ComboInput/Private/Events/K2Node_ComboAction.cpp index 427db22..6b8383d 100644 --- a/Source/ComboInput/Private/Events/K2Node_ComboAction.cpp +++ b/Source/ComboInput/Private/Events/K2Node_ComboAction.cpp @@ -74,7 +74,7 @@ FText UK2Node_ComboAction::GetTooltipText() const if (CachedTooltip.IsOutOfDate(this)) { // FText::Format() is slow, so we cache this to save on performance - CachedTooltip.SetCachedText(FText::Format(NSLOCTEXT("K2Node", "ComboAction_Tooltip", "Event for when the combo action {0} is pressed or released."), FText::FromName(this->ComboAction->GetFName())), this); + CachedTooltip.SetCachedText(FText::Format(NSLOCTEXT("K2Node", "ComboAction_Tooltip", "Event for when the combo action {0} is activated or released.\nBoth execution pins might fire on the same frame if an action\nwas buffered during a release action, but \"Activated\" will\nalways happen before \"Released\"."), FText::FromName(this->ComboAction->GetFName())), this); } return CachedTooltip; } diff --git a/Source/ComboInput/Private/InputBufferLocalPlayerSubsystem.cpp b/Source/ComboInput/Private/InputBufferLocalPlayerSubsystem.cpp index 5669957..81d0d00 100644 --- a/Source/ComboInput/Private/InputBufferLocalPlayerSubsystem.cpp +++ b/Source/ComboInput/Private/InputBufferLocalPlayerSubsystem.cpp @@ -100,6 +100,13 @@ void UInputBufferLocalPlayerSubsystem::ActivateComboInput(const UComboInputAsset } this->OnNewComboInput.Execute(ComboInput, EComboActionTriggerEvent::Activated); + + // If the incoming combo input contains an expiring action, + // we know it's been released, so send that signal too. + if (ComboInput->ContainsOneOf(this->ExpiringActions)) + { + this->OnNewComboInput.Execute(ComboInput, EComboActionTriggerEvent::Released); + } } else { diff --git a/Source/ComboInput/Public/Components/ComboManagerComponent.h b/Source/ComboInput/Public/Components/ComboManagerComponent.h index 07db8e3..47e57ab 100644 --- a/Source/ComboInput/Public/Components/ComboManagerComponent.h +++ b/Source/ComboInput/Public/Components/ComboManagerComponent.h @@ -92,6 +92,8 @@ private: const class UComboSequenceNode *ActiveNode = nullptr; const class UComboSequenceNode *PreviousNode = nullptr; + TObjectPtr LastComboAction = nullptr; + TMap ComboActionEventBindings; TObjectPtr AttachedInputBuffer;