Release actions are now supported, and fired the same frame as an Activated action if the action was buffered and then released.

This commit is contained in:
Jamie Greunbaum 2023-09-17 17:35:43 -04:00
parent 6af0b1c23a
commit 095cf66937
4 changed files with 14 additions and 15 deletions

View File

@ -111,21 +111,10 @@ void UComboManagerComponent::DEBUG__UnlockAction(TObjectPtr<const UComboInputAss
void UComboManagerComponent::ReleaseComboAction(const class UComboInputAsset *Input) void UComboManagerComponent::ReleaseComboAction(const class UComboInputAsset *Input)
{ {
const TObjectPtr<const UComboSequenceNode> CurrentNode = (this->ActiveNode ? this->ActiveNode : this->DefaultStartNode); if (this->LastComboAction)
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)
{ {
this->BroadcastDelegates(ActionData->ComboAction, EComboActionTriggerEvent::Released); this->BroadcastDelegates(this->LastComboAction, EComboActionTriggerEvent::Released);
UE_LOG(LogComboManagerComponent, Verbose, TEXT("%s released"), *ActionData->ComboAction->ActionName.ToString()); this->LastComboAction = nullptr;
}
// Otherwise, see if we have a fallback we can use.
else if (const TObjectPtr<const UComboAction> *ComboAction = this->FallbackActions.Find(Input))
{
this->BroadcastDelegates(*ComboAction, EComboActionTriggerEvent::Released);
UE_LOG(LogComboManagerComponent, Verbose, TEXT("Fallback action %s released"), *(*ComboAction)->ActionName.ToString());
} }
} }
@ -159,4 +148,5 @@ void UComboManagerComponent::BroadcastDelegates(const UComboAction *ComboAction,
Binding->Execute(ComboAction, TriggerEvent); Binding->Execute(ComboAction, TriggerEvent);
} }
this->OnComboAction.Broadcast(ComboAction, (TriggerEvent == EComboActionTriggerEvent::Activated) ? true : false); this->OnComboAction.Broadcast(ComboAction, (TriggerEvent == EComboActionTriggerEvent::Activated) ? true : false);
this->LastComboAction = ComboAction;
} }

View File

@ -74,7 +74,7 @@ FText UK2Node_ComboAction::GetTooltipText() const
if (CachedTooltip.IsOutOfDate(this)) if (CachedTooltip.IsOutOfDate(this))
{ {
// FText::Format() is slow, so we cache this to save on performance // 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; return CachedTooltip;
} }

View File

@ -100,6 +100,13 @@ void UInputBufferLocalPlayerSubsystem::ActivateComboInput(const UComboInputAsset
} }
this->OnNewComboInput.Execute(ComboInput, EComboActionTriggerEvent::Activated); 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 else
{ {

View File

@ -92,6 +92,8 @@ private:
const class UComboSequenceNode *ActiveNode = nullptr; const class UComboSequenceNode *ActiveNode = nullptr;
const class UComboSequenceNode *PreviousNode = nullptr; const class UComboSequenceNode *PreviousNode = nullptr;
TObjectPtr<const class UComboAction> LastComboAction = nullptr;
TMap<FName, FComboActionHandlerDynamicSignature> ComboActionEventBindings; TMap<FName, FComboActionHandlerDynamicSignature> ComboActionEventBindings;
TObjectPtr<class UInputBufferComponent> AttachedInputBuffer; TObjectPtr<class UInputBufferComponent> AttachedInputBuffer;